Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is not possible to convert Dociment that have Embedded document #931

Open
rtyshyk opened this issue Apr 7, 2020 · 2 comments
Open

It is not possible to convert Dociment that have Embedded document #931

rtyshyk opened this issue Apr 7, 2020 · 2 comments

Comments

@rtyshyk
Copy link

rtyshyk commented Apr 7, 2020

Looks like it is not possible to have Embedded object as a single item and bundle forces to use always array.

Is it right or I am missing something?

The raw object looks like

{
    "bar": {
       "acme": "delta"
   }
}

php class mapping

/**
* @ES\Index()
*/
class A {
    
    /**
     * @ES\Embedded(class="Bar")
     */   
    public $bar;
}

/**
* @ES\ObjectType()
*/
class Bar {

    /**
     * @ES\Property(type="keyword")
     */
   public $acme;
}

As result, \ONGR\ElasticsearchBundle\Result\ObjectIterator::doInitialize iterates object keys and passes primitive to convertDocument that expect array as well as other methods that will be called afterwards.

At the same time \ONGR\ElasticsearchBundle\Mapping\Converter::normalize has verification if embeded value is iterable.

            if ($fieldMeta['embeded']) {
                if (is_iterable($value)) {
                    foreach ($value as $item) {
                        $result[$field][] = $this->normalize($item, $fieldMeta['sub_properties']);
                    }
                } else {
                    $result[$field] = $this->normalize($value, $fieldMeta['sub_properties']);
                }
            }

Did I miss something? How to deal with it, when I have already defined schema and it returns single object instead of array, change type is not an option.

Thanks in advance.

@xxxdannybyrdxxx
Copy link

I have the same problem((

@jeanphilippeds
Copy link

Same here :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants