elastic / elasticsearch

Free and Open, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.51k stars 24.6k forks source link

GeoBoundsAggregation does not reject sub aggregations #91072

Closed mushao999 closed 1 year ago

mushao999 commented 1 year ago

Elasticsearch Version

8.6.0

Installed Plugins

No response

Java Version

java version "17.0.1" 2021-10-19 LTS

OS Version

Darwin xxx.local 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64

Problem Description

GeoBoundsAggregation is a metric aggregation that doesn't support sub aggregations. However, it does not reject sub aggregations or do anything when sub aggregations are added into it during search.

Steps to Reproduce

refer to :https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-metrics-geobounds-aggregation.html

create index

PUT /museums
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_point"
      }
    }
  }
}

index docs

POST /museums/_bulk?refresh
{"index":{"_id":1}}
{"location": "POINT (4.912350 52.374081)", "name": "NEMO Science Museum"}
{"index":{"_id":2}}
{"location": "POINT (4.901618 52.369219)", "name": "Museum Het Rembrandthuis"}
{"index":{"_id":3}}
{"location": "POINT (4.914722 52.371667)", "name": "Nederlands Scheepvaartmuseum"}
{"index":{"_id":4}}
{"location": "POINT (4.405200 51.222900)", "name": "Letterenhuis"}
{"index":{"_id":5}}
{"location": "POINT (2.336389 48.861111)", "name": "Musée du Louvre"}
{"index":{"_id":6}}
{"location": "POINT (2.327000 48.860000)", "name": "Musée d'Orsay"}

search with sub agg

POST /museums/_search?size=0
{
    "query" : {
        "match" : { "name" : "musée" }
    },
    "aggs" : {
        "viewport" : {
            "geo_bounds" : {
                "field" : "location", 
                "wrap_longitude" : true 
            },
            "aggs": {
              "names": {
                "terms": {
                  "field": "name.keyword",
                  "size": 10
                }
              }
            }
        }
    }
}

current response

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  },
  "aggregations" : {
    "viewport" : {
      "bounds" : {
        "top_left" : {
          "lat" : 48.86111099738628,
          "lon" : 2.3269999679178
        },
        "bottom_right" : {
          "lat" : 48.85999997612089,
          "lon" : 2.3363889567553997
        }
      }
    }
  }
}

we want reponse be like that of GeoCentroid's

{
  "error" : {
    "root_cause" : [
      {
        "type" : "aggregation_initialization_exception",
        "reason" : "Aggregator [centroid] of type [geo_centroid] cannot accept sub-aggregations"
      }
    ],
    "type" : "aggregation_initialization_exception",
    "reason" : "Aggregator [centroid] of type [geo_centroid] cannot accept sub-aggregations"
  },
  "status" : 500
}

Logs (if relevant)

No response

elasticsearchmachine commented 1 year ago

Pinging @elastic/es-analytics-geo (Team:Analytics)

iverase commented 1 year ago

Fixed in https://github.com/elastic/elasticsearch/pull/91073