我看了一下ElasticSearch: search inside the array of objects,虽然它有帮助,但我实际上是在尝试确定是否至少有一个对象具有字段,以及是否所有嵌套对象都具有字段。
假装我们有一个所有冰箱的索引,上面有一个多余的文档,比如:
{
"_id": "whatever",
"location": "North Building 1",
"floor": 2,
"tag": "refrigerator-1",
"contents" : [
{
"item": "milk-carton",
"expires": 1-1-2023
},
{
"item": "pyrex-container",
}
]
}
如何创建ElasticSearch查询:
1.查找至少有1件物品可能过期的冰箱( "exists" : { "field" : "expires" } }
1.查找没有过期物品的冰箱
1.查找所有物品都有过期字段的冰箱
1条答案
按热度按时间odopli941#
如果要在单个查询中执行此操作,请使用named_queries
查询
结果
查询是自解释性的。如果要对三个条件使用单独的查询,请断开上面的查询。每个should子句将成为单独的查询