Elastic Search Kibana 如何匹配同一对象内的两个属性?

问题描述 投票:0回答:1

大家好,假设我在弹性搜索中有以下格式的数据结构:

"dataset1" :
{
"listoftasks": [ 
 {
   "task" : {
      "id": 1351
   },
   "statusOfTask": "completed"
 },
 {
   "task" : {
      "id": 1355
   },
   "statusOfTask": "completed"
 },
 {
   "task" : {
      "id": 1350
   },
   "statusOfTask": "incomplete"
 }
]
},
"dataset2" :
{
"listoftasks": [ 
 {
   "task" : {
      "id": 1351
   },
   "statusOfTask": "incomplete"
 },
 {
   "task" : {
      "id": 1355
   },
   "statusOfTask": "completed"
 },
 {
   "task" : {
      "id": 1350
   },
   "statusOfTask": "incomplete"
 }
]
}

像dataset1和dataset2一样,还有许多其他数据集。我想编写一个 ES 查询来检索所有数据集,其中有一个 taskid 为 1351 和相应的 statusOfTask 为已完成。我目前有以下查询。

"query":{
          "nested": {
            "path": "xxx",
            "query": {
              "bool":{
                "must":[
                  { "match": {"listoftasks.statusOfTask": "completed"}},
                  { "match": {"listoftasks.task.id": "1351"}}
                ]
              }
            }
          }
  }

然而,这个查询在它应该只返回数据集 1 时返回了数据集 1 和数据集 2。我的猜测是因为在 dataset2 中存在一个 taskid 1351 和一个 completed 的 statusOfTask,它返回 dataset2。那么我将如何更改查询以使其检查 1351 taskid 的同一对象内的相应 statusOfTask??

elasticsearch kibana
1个回答
0
投票

没有映射,很难看出会发生什么,但我假设你有嵌套类型的任务列表。问题很可能是您的 id 字段是更深的子属性。如果您有以下字段 “任务”:1351, “statusOfTask”:“未完成”

然后它可能会工作。

© www.soinside.com 2019 - 2024. All rights reserved.