gpt4 book ai didi

php - ElasticSearch 从 0.90 更改为 1.1

转载 作者:行者123 更新时间:2023-12-03 02:07:35 24 4
gpt4 key购买 nike

我只是稍微澄清一下,我刚刚从 ElasticSearch 0.90 升级到 1.1.1。

我注意到的一个区别是我有一个返回 json 数据的字段。在 0.90 调用:

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

会按原样返回数据,我会使用
json_decode($jsondata)

将其转换为 PHP 数组。

在具有相同代码的 ElasticSearch 1.1 下,我看到了不同的结果

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

这不是返回数据,而是将其作为数组返回,因此要访问它,我需要调用类似
json_decode($jsondata[0]);

这是 Elastic Search 在处理存储的 json 数据的方式上的变化吗?

我存储的实际 json 数据如下所示:
[{"data1":"43456435435345","data2":"tyetytbety"}]

对此的任何帮助将不胜感激。

最佳答案

这实际上是 Elasticsearch 1.x 中返回字段数据的正常和预期行为,并在 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.

关于php - ElasticSearch 从 0.90 更改为 1.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23645411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com