Вопрос

I am just after a bit of clarification, I have just upgraded from ElasticSearch 0.90 to 1.1.1.

One difference I am noticing is that I have a field that returns json data. On 0.90 a call to :

$jsondata = $hits['fields']['jsondata']

would return the data as is and I would use

json_decode($jsondata)

to convert it into a PHP array.

Under ElasticSearch 1.1 with the same code, I am seeing a different result

$jsondata = $hits['fields']['jsondata']

This instead of returning data, returns it as an array, so to access it, I need to call something like

json_decode($jsondata[0]);

Is this a change in Elastic Search, in the way it handles json data that is stored?

The actual json data I am storing looks like:

[{"data1":"43456435435345","data2":"tyetytbety"}]

Any help with this would be appreciated.

Это было полезно?

Решение

This is in fact normal and expected behavior for the return of fields data in Elasticsearch 1.x, and is explained in Breaking Changes in 1.0 > Return Values

Field values, in response to the fields parameter, are now always returned as arrays. A field could have single or multiple values, which meant that sometimes they were returned as scalars and sometimes as arrays. By always returning arrays, this simplifies user code. The only exception to this rule is when fields is used to retrieve metadata like the routing value, which are always singular. Metadata fields are always returned as scalars.

The fields parameter is intended to be used for retrieving stored fields, rather than for fields extracted from the _source. That means that it can no longer be used to return whole objects and it no longer accepts the _source.fieldname format. For these you should use the _source _source_include and _source_exclude parameters instead.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top