【发布时间】:2021-01-15 02:45:44
【问题描述】:
所以我得到了这份文件 我想用这个查询过滤的嵌套数组。
我希望 ES 返回所有项目都具有更改 = 0 的所有文档,并且仅此而已。 如果文档在列表中甚至有一个更改为 1 的项目,则将其丢弃。
有什么方法可以从我已经编写的查询开始实现这一点?还是应该改用脚本?
文件:
{
"id": "abc",
"_source" : {
"trips" : [
{
"type" : "home",
"changes" : 0
},
{
"type" : "home",
"changes" : 1
}
]
}
},
{
"id": "def",
"_source" : {
"trips" : [
{
"type" : "home",
"changes" : 0
},
{
"type" : "home",
"changes" : 0
}
]
}
}
查询:
GET trips_solutions/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"id": {
"value": "abc"
}
}
},
{
"nested": {
"path": "trips",
"query": {
"range": {
"trips.changes": {
"gt": -1,
"lt": 1
}
}
}
}
}
]
}
}
}
预期结果:
{
"id": "def",
"_source" : {
"trips" : [
{
"type" : "home",
"changes" : 0
},
{
"type" : "home",
"changes" : 0
}
]
}
}
Elasticsearch 版本:7.6.2
已经阅读了这个答案,但他们没有帮助我: https://discuss.elastic.co/t/how-to-match-all-item-in-nested-array/163873 ElasticSearch: How to query exact nested array
【问题讨论】:
标签: elasticsearch kibana elastic-stack kibana-7