gpt4 book ai didi

elasticsearch - 无痛 : check if an individual document contains a key

转载 作者:行者123 更新时间:2023-12-02 22:35:50 25 4
gpt4 key购买 nike

我正在使用 painless使用 Elastic 5.5 过滤文档

问题

使用“painless”,查找带有 strings 的文档 field 。

预期成绩

仅带有 strings 的文档字段被返回

实际结果

所有文件都被退回。

观察

只要有 strings 的文档,就会返回所有文档。 field 。这可能是某种缓存问题。

测试用例

灯具

PUT /test_idx

POST /test_idx/t/1
{
"strings": ["hello", "world"]
}

POST /test_idx/t/2
{
"numbers": [1, 2, 3]
}

询问
GET /test_idx/_search
{
"query": {
"bool": {
"filter": [
{
"script": {
"script": {
"lang": "painless",
"inline": "return doc.containsKey(params.keypath)",
"params": {"keypath": "strings"}
}
}
}
]
}
}
}

实际 react
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": [
{
"_index": "test_idx",
"_type": "t",
"_id": "2",
"_score": 0,
"_source": {
"numbers": [
1,
2,
3
]
}
},
{
"_index": "test_idx",
"_type": "t",
"_id": "1",
"_score": 0,
"_source": {
"strings": [
"hello",
"world"
]
}
}
]
}
}

预期响应
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": [
{
"_index": "test_idx",
"_type": "t",
"_id": "1",
"_score": 0,
"_source": {
"strings": [
"hello",
"world"
]
}
}
]
}
}

最佳答案

您可能想尝试这个,即使出于性能原因,强烈不鼓励过度使用无痛

GET /test_idx/_search
{
"query": {
"bool": {
"filter": [
{
"script": {
"script": {
"lang": "painless",
"inline": "return doc[params.keypath].value != null",
"params": {
"keypath": "strings.keyword"
}
}
}
}
]
}
}
}

关于elasticsearch - 无痛 : check if an individual document contains a key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53453792/

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