【问题标题】:Elasticsearch post_filterElasticsearch post_filter
【发布时间】:2016-09-24 07:09:43
【问题描述】:

有没有办法在elasticsearch中对post_filter应用多个条件?

GET /job/_search
{
  "post_filter":
      {
        "terms": {
          "expertise_level": [
            "medium",
            "high"
          ]
        }
      },
    "aggs": {
      "expertise_level": {
        "terms": {
          "field": "expertise_level",
          "size": 10
        }
      }
    }
}

这会奏效。但我想在查询中添加多个过滤器。我怎样才能做到这一点??

【问题讨论】:

    标签: php elasticsearch lucene


    【解决方案1】:

    使用bool 子句:

    {
    "post_filter": {
      "bool": {
         "must": [
            {
              //Add  Filter 1
            },
            {
              //Add  Filter 2
            },
            {
               //Add  Filter 3
            }
         ]
         }
       }
    }  
    

    【讨论】:

      【解决方案2】:

      试试

      {
        "post_filter": {
          "and": {
            "filters": [
              {
                "terms": {
                "FIELD": [
                  "VALUE1",
                  "VALUE2"
                ]
              }},
              {
                "terms": {
                  "FIELD": [
                    "VALUE1",
                    "VALUE2"
                  ]
                }
              }
            ]
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-20
        • 1970-01-01
        • 1970-01-01
        • 2019-05-22
        • 1970-01-01
        • 2020-07-28
        • 2016-09-02
        • 1970-01-01
        相关资源
        最近更新 更多