我有一个嵌套的文档:
"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": []
但不幸的是两者并不匹配。有什么想法吗?
5条答案
按热度按时间vaqhlq811#
Elasticsearch博客上提到的例子指的是字符串和字符串类型的数组,而不是嵌套类型。
以下查询应该对您有用:
另外,您可以参考this issue以获取更多信息,其中讨论了这种使用模式。
pkbketx92#
这对我很有效
r7knjye23#
使用以下索引Map:
我需要使用这个查询:
Elasticsearch版本5.4.3
d6kp6zgx4#
user3775217的答案对我来说很有效,但我需要调整它,使其像
must_not
预期的那样工作。本质上,bool
/must
需要 Package 在查询的nested
部分:qoefvg9y5#
更短版本(无bool查询),(在ElasticSearch 7.x上测试)