elasticsearch范围查询被范围聚合忽略

时间:2019-01-11 09:29:55

标签: elasticsearch

我在range aggregation上方有一个maxPrice,以获取每个价格的文件数量。

我使用range query来设置maxPrice的最大值。查询结果正常。当我设定范围f.e.直到20,显示正确的文档。

问题:

对于价格大于范围查询范围内设置的价格,range aggregation显示doc_count> 0

我的问题:

如何获取与范围查询相关的范围汇总?

GET test-faceted-search/_search
{
  "query": {
    "function_score": {
      "field_value_factor": {
        "field": "ranking",
        "factor": 0.0001,
        "modifier": "ln1p",
        "missing": 1
      },
      "score_mode": "avg",
      "query": {
        "bool": {
          "must": [
            {
              "multi_match": {
                "query": "find me",
                "fields": [
                  "name^100",
                  "altname^80",
                  "cat^20"
                ],
                "fuzziness": 1,
                "operator": "and",
                "type": "best_fields"
              }
            },
            {
              "range": {
                "maxPrice": {
                  "lte": 20
                }
              }
            }
          ]
        }
      }
    }
  },
  "aggs": {
    "pricefilter": {
      "range": {
        "field": "maxPrice",
          "ranges": [
            {
              "to": 10
            },
            {
              "to": 25
            }
          ]
        }
      }
  }
}

我希望有人能帮助我。

1 个答案:

答案 0 :(得分:0)

我找到了解决方法。

我错过了,我必须向范围聚合添加from参数。

"aggs": {
    "pricefilter": {
      "range": {
        "field": "maxPrice",
          "ranges": [
            {
              "from": 0.1
              "to": 10
            },
            {
              "from": 10.01
              "to": 25
            }
          ]
        }
      }
  }
相关问题