使用internal_hits,elasticsearch查询的偏移量

时间:2019-07-10 13:18:18

标签: elasticsearch

我试图编写一个与嵌套对象字段匹配的搜索查询,但只匹配数组中第一项(嵌套类型)的那些查询。

数据示例:

"_source": {
  ...
  "status": [
    {
      "@timestamp": "2019-07-09T16:08:45.779Z",
      "ad_user": "jgross",
      "message": "ergregergergegegregregregrege",
      "status": "ACKNOWLEDGE"
    },
    {
      "@timestamp": "2019-07-09T01:09:40.719305Z",
      "ad_user": "__elastic",
      "message": "Initial status",
      "status": "ACTIVE"
    }
  ]
},

因此该文档不匹配,因为数组中的第一项的状态为 ACKNOWLEDGE ,而不是 ACTIVE

查询:

"query": {
  "nested": {
  "path": "status",
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "status.status": "ACTIVE"
          }
        }
      ]
    }
  },
  "inner_hits": {}
 }
}

结果:

"hits": [
  {
    "_index": "watches-logs",
    "_type": "_doc",
    "_id": "o4BH1GsBaUeb2kAfclb-",
    "_nested": {
      "field": "status",
      "offset": 1
    },
    "_score": 0.4088956,
    "_source": {
      "@timestamp": "2019-07-09T01:09:40.719305Z",
      "ad_user": "__elastic",
      "message": "Initial status",
      "status": "ACTIVE"
    }
  },
  ...
]

是否可以添加另一条匹配offest: 0或其他方式的match语句?

我确定我可以使用一个轻松的脚本,但这似乎很昂贵,所以我想先尝试其他方法。

0 个答案:

没有答案