如何在Elasticsearch中的多个字段上创建bool过滤器?

时间:2017-10-19 14:52:16

标签: elasticsearch

我在Elasticsearch中有以下查询:

{
  "script_fields": {
    "travel_time": {
      "script": {
        "inline": "doc['DateTo'].value - doc['DateFrom'].value"
      }
    }
  }, 
  "stored_fields": [
    "_source"
    ], 
  "query": {
    "bool": { 
      "filter": {
        "exists": {
          "field": "DateTo"
        }
      }
    }
  }
}

如何将DateFrom添加到exists过滤器中?

1 个答案:

答案 0 :(得分:1)

您可以添加多个exists条件:

  "query": {
    "bool": { 
      "filter": [
       {
         "exists": {
           "field": "DateFrom"
         }
       },
       {
         "exists": {
           "field": "DateTo"
         }
       },
       {
         "script": {
           "script": {
             "inline": "doc['DateTo'].value - doc['DateFrom'].value > 0"
           }
         }
       }
      ]
    }
  }