文档计数大于'x',geo_point聚合elasticsearch

时间:2018-04-18 13:10:46

标签: elasticsearch geometry elasticsearch-aggregation

我目前正在执行以下查询以在弹性搜索中聚合特定精度内的所有点。

{
  "aggs": {
    "coordinates": {
      "geohash_grid": {
        "field": "properties.Geometry.geo_point",
        "precision": 12
      },
      "aggs": {
        "centroid": {
          "geo_centroid": {
            "field": "properties.Geometry.geo_point"
          }
        }
      }
    }
  }
}

,回复是

      "aggregations": {
            "coordinates": {
              "buckets": [
                {
                  "key": "s00000000000",
                  "doc_count": 82571,
                  "centroid": {
                    "location": {
                      "lat": 0,
                      "lon": 0
                    },
                    "count": 82571
                  }
                },
                {
                  "key": "6gyf4bf8m0uh",
                  "doc_count": 58587,
                  "centroid": {
                    "location": {
                      "lat": -23.55052001774311,
                      "lon": -46.633309721946716
                    },
                    "count": 58587
                  }
                },
                {
                  "key": "7h2y8hz76g8m",
                  "doc_count": 14551,
                  "centroid": {
                    "location": {
                      "lat": -19.924501832574606,
                      "lon": -43.93523778766394
                    },
                    "count": 14551
                  }
                }
}

我需要获得计数大于一定数量的所有桶。我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

您可以添加字段

GET _search
{
    "query": {
        "range" : {
            "age" : {
                "gte" : 5000,
            }
        }
    }
}

如文档中的描述: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

答案 1 :(得分:0)

解决了,我使用了以下过滤器:

{
    "aggs": {
    "coordinates": {
      "geohash_grid": {
        "field": "properties.Geometry.geo_point",
        "precision": 12
      },
      "aggs": {
        "sales_bucket_filter": {
          "bucket_selector": {
            "buckets_path": {
              "doc_count": "centroid.count"
            },
            "script": "params.doc_count > 500"
          }
        },
        "centroid": {
          "geo_centroid": {
            "field": "properties.Geometry.geo_point"
          }
        }
      }
    }
  }
}