Elasticsearch 范围聚合忽略负值

Elasticsearch range aggregation ignores negative values

我正在尝试对范围聚合进行分桶并实现以下分桶:

<=0 - 0 including negative numbers
>=1 - 1 and above

字段类型=整数

查询:

GET _search
{
 "aggs": {
    "stock_ranges": {
      "range": {
        "field": "Facets_Integer_Stock",
        "ranges": [
          {
            "to": 0
          },
          {
            "from": 1
          }
        ]
      }
    }
  }
}

字段 Facets_Integer_Stock 的映射:

"Facets_Integer_Stock" : {
   "type" : "integer"
},

我预计第一个桶中的 2 个计数 <0。它应该包括 -10.

的命中

回应

{
  "took" : 26,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 8,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "stock_ranges" : {
      "buckets" : [
        {
          "key" : "*-0.0",
          "to" : 0.0,
          "doc_count" : 1
        },
        {
          "key" : "1.0-*",
          "from" : 1.0,
          "doc_count" : 2
        }
      ]
    }
  }
}

解决

POST /_bulk/
{"index":{"_index":"72376077"}}
{"data": -1}
{"index":{"_index":"72376077"}}
{"data":-2}
{"index":{"_index":"72376077"}}
{"data":0}
{"index":{"_index":"72376077"}}
{"data":1}
{"index":{"_index":"72376077"}}
{"data":2}

GET /72376077/_search
{
  "size": 0, 
  "aggs": {
    "stock_ranges": {
      "range": {
        "field": "data",
        "ranges": [
          {
            "to": 0.1
          },
          {
            "from": 1
          }
        ]
      }
    }
  }
}

它给那些桶:

{
  "buckets": [
    {
      "key": "*-0.1",
      "to": 0.0,
      "doc_count": 3
    },
    {
      "key": "1.0-*",
      "from": 1.0,
      "doc_count": 2
    }
  ]
}

哪个看起来绝对没问题?

range聚合中,to总是互斥的,你应该使用ltegte代替:

GET _search
{
 "aggs": {
    "stock_ranges": {
      "range": {
        "field": "Facets_Integer_Stock",
        "ranges": [
          {
            "lte": 0
          },
          {
            "gte": 1
          }
        ]
      }
    }
  }
}