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.

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

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错