ElasticsearchDSL icon indicating copy to clipboard operation
ElasticsearchDSL copied to clipboard

Getting Null for array fields

Open dijadev opened this issue 8 years ago • 3 comments

Hi! I am trying to map a hash object from a mongdb collection, using object type , but I am geting null value.

<?
    /**
     * @ES\Property(type="object")
     * @MongoDB\hash
     */
    protected $data;

Is my mapping wrong? I am using bundle version 1.2 with elasticsearch 2.4.

Thanks in advance,

dijadev avatar Mar 07 '17 17:03 dijadev

Hey @dijadev

This issue should be in ElasticsearchBundle.

There is no hash support until 5.x version in ElasticsearchBundle. If you want to use an object, you need to create a separate class and embed it.

saimaz avatar Mar 07 '17 20:03 saimaz

Thank you @saimaz for replying.

Unfortunately i can't use another version since my elasticsearch version is 2.4 .

Edit: Actully I figured out that the problem was not in the field type but in the name. My field name is "pageData" and since I did not specify the name in the mapping, the getter getPageData() resolves the name with Snakcase so it returns Null for page_data field.. The solution is to specify the name explicitly in the annotation in this way:

<?
    /**
     * @ES\Property(name="pageData")
     * @MongoDB\hash
     */
    protected $pageData;

dijadev avatar Mar 08 '17 09:03 dijadev

I'll take a look later this week if I can backport hashmap support to 1.x bundle version.

saimaz avatar Mar 08 '17 12:03 saimaz