douxiaqin2062 2014-05-14 04:02
浏览 31
已采纳

ElasticSearch从0.90变为1.1

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.

  • 写回答

1条回答 默认 最新

  • duanluangua8850 2014-05-14 11:36
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan