gpt4 book ai didi

elasticsearch - 嵌套文档的弹性存在查询

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

我有一个嵌套文档:

"someField": "hello",
"users": [
{
"name": "John",
"surname": "Doe",
"age": 2
}
]

根据这个https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html ,上面应该匹配:

GET /_search
{
"query": {
"exists" : { "field" : "users" }
}

而以下不应该,

"someField": "hello",
"users": []

但不幸的是两者都不匹配。有什么想法吗?

最佳答案

Elasticsearch博客中提到的例子是指string和string类型的array,不是嵌套类型。

以下查询应该适合您:

{
"query": {
"nested": {
"path": "users",
"query": {
"bool": {
"must": [
{
"exists": {
"field": "users"
}
}
]
}
}
}
}
}

另外可以引用this issue了解更多信息,其中讨论了这种使用模式。

关于elasticsearch - 嵌套文档的弹性存在查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41491982/

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