gpt4 book ai didi

arrays - Elasticsearch 的 script_field 为 array.values 返回了错误的值

转载 作者:行者123 更新时间:2023-11-29 02:56:25 27 4
gpt4 key购买 nike

我尝试使用 script_fields 从我的数据中检索数组值,但我收到了不一致的结果。

我的映射:

curl -XPUT localhost:9200/test/user/_mapping -d '
{
"user": {
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"other_ids": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
'

部分测试数据:

curl -XPUT localhost:9200/test/user/id1 -d '
{
"id": "id1",
"other_ids": [
"id2",
"id3"
]
}
'

curl -XPUT localhost:9200/test/user/id2 -d '
{
"id": "id2",
"other_ids": [
"id1"
]
}
'

curl -XPUT localhost:9200/test/user/id3 -d '
{
"id": "id3",
"other_ids": [
"id1",
"id2"
]
}
'

“简化”查询:

curl -XGET 'localhost:9200/test/user/_search?pretty=1'  -d '
{
"fields": [
"_source"
],
"query": {
"match_all": {}
},
"script_fields": {
"other_id_script": {
"lang": "groovy",
"script": "doc[\"other_ids\"].values"
}
}
}
'

答案中的相关部分:

  "hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_source":{"id":"id1","other_ids":["id2","id3"]},
"fields" : {
"other_id_script" : [ [ "id1", "id2" ] ]
}
}, {
"_source":{"id":"id2","other_ids":["id1"]},
"fields" : {
"other_id_script" : [ [ "id1", "id2" ] ]
}
}, {
"_source":{"id":"id3","other_ids":["id1","id2"]},
"fields" : {
"other_id_script" : [ [ "id1", "id2" ] ]
}
} ]
}

正如我们所见,在前两种情况下,other_id_script 的值与当前文档的 other_ids 值不同。

这是一个错误,还是我遗漏了什么?

(整个脚本可以在这里找到:https://gist.github.com/baloghz/c27e39ad419a6f4684ab)

最佳答案

看起来这个问题在 Elasticsearch 中得到了解决 issue #8576 , 由 commit d22645c 修复,并在 1.3.6、1.4.1 和 1.5.0 版本中上线。

issue的作者也给出了workaround:

"script": "doc[\"other_ids\"].values.take(100)"

关于arrays - Elasticsearch 的 script_field 为 array.values 返回了错误的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26780284/

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