如何在elasticsearch中使用范围post_filter

qwa*_*waz 0 elasticsearch

我在任何地方都找不到语法示例,并且以下内容不起作用:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            { "term": { "category": "catname"   }}
          ]
        }
      }
    }
  },
  "post_filter": {
    "terms": {"type": ["foo1", "foo2"] },
    "range": { "price": { "gte": 300, "lte": 600 } }
  }
}
Run Code Online (Sandbox Code Playgroud)

Val*_*Val 5

您只需将所有terms过滤器包装在一个附加bool/must过滤器中:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "category": "catname"
              }
            }
          ]
        }
      }
    }
  },
  "post_filter": {
    "bool": {
      "must": [
        {
          "terms": {  "type": [ "foo1", "foo2" ] }
        },
        {
          "range": {  "price": { "gte": 300, "lte": 600  } }
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)