繁体   English   中英

过滤文档,其中数组的所有值都满足elasticsearch中的某些条件

[英]Filter documents where all values of an array meet some criteria in elasticsearch

我的文档看起来像这样:

{
  times: [{start: "1461116454242"},{start:"1461116454242"}]
}

我希望获得每个开始时间都在过去的所有文档。 此查询在所有时间都在将来或所有时间都在过去时有效,但如果将来只有一次(仍然匹配)则失败。

 query: { filtered: { filter: { bool: { must: [ { nested: { path: "times", filter: { script : { script: "doc['start'].value < now", params: { now: Date.now() } } } } } ] } }, query: { match_all: {} } } } 

我刚刚意识到的一个解决方案:

 query: { filtered: { filter: { bool: { must: [ { nested: { path: "times", filter: { "bool": { "must": [ { "range": { "times.start": { lt: new Date() } } } ] } } } } ], must_not: [ { nested: { path: "times", filter: { "bool": { "must": [ { "range": { "times.start": { gte: new Date() } } } ] } } } } ] } }, query: { match_all: {} } } } 

这个怎么样:

  • include_in_parent: true映射中为include_in_parent: true
    "times": {
      "type": "nested",
      "include_in_parent": true,
      "properties": {
        "start": {
          "type": "date"
        }
      }
    }
  • 并使用query_string语法,而不是nested
{
  "query": {
    "query": {
      "query_string": {
        "query": "times.start:<=now AND NOT times.start:>now"
      }
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM