0

I'm currently doing the following Query to aggregate all points within a certain precision in elastic search.

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

and the response is

      "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
                  }
                }
}

I need to get all buckets that have a count greater than a certain number. How can I do that?

Juliano Grams
  • 525
  • 1
  • 5
  • 17

2 Answers2

1

You can add the field

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

as descripe here in the documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html

lu1her
  • 105
  • 12
  • But won't this just filter the aggregation? What I need is to filter the buckets after the aggregation. The field count only exist in the aggregation query, which means how many hits were grouped. – Juliano Grams Apr 18 '18 at 13:34
  • Then you might have a look to https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_minimum_document_count_3 and https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html to manage to filter your result, which version of elasticjsearch are you using ? – lu1her Apr 18 '18 at 13:41
  • I'm using version 6.2 – Juliano Grams Apr 18 '18 at 13:46
  • did my advices helped you ? – lu1her Apr 18 '18 at 14:00
0

Solved, I used the following filter:

{
    "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"
          }
        }
      }
    }
  }
}
Juliano Grams
  • 525
  • 1
  • 5
  • 17