Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] - Geo Tile Grid Aggregation on Geo Shape Field #195

Closed
navneet1v opened this issue Dec 5, 2022 · 1 comment
Closed

[RFC] - Geo Tile Grid Aggregation on Geo Shape Field #195

navneet1v opened this issue Dec 5, 2022 · 1 comment
Assignees
Labels
aggregations label for all the aggregations that are getting created in this repo feature geospatial v2.9.0 v2.9.0

Comments

@navneet1v
Copy link
Collaborator

navneet1v commented Dec 5, 2022

The purpose of this RFC (request for comments) is to gather community feedback on a proposal to allow OpenSearch users to facilitate Geo Tile Grid Aggregations over the GeoShape data type. This RFC is in continuation with #84.

Geo Tile Grid Aggregation

GeoTile Grid is a multi-bucket aggregation which will grouping the GeoShapes into different buckets where each bucket represent the cells in a grid. Each cell corresponds to a map tile (https://en.wikipedia.org/wiki/Tiled_web_map) as used by many online map sites. Each cell is labeled using a "{zoom}/{x}/{y}" format, where zoom is equal to the user-specified precision.
The working of the aggregation is very similar to GeoTile Grid Aggregation on GeoPoint but there is key difference. A geo_point(if it is not multi geo_point) is only present in one bucket, but the a geo_shape will be counted in all the grid cells with which the shape is intersecting.

Aggregation Schema

{
  "aggs/aggregations": {
    "<user-provided-aggregation-name>": {
      "geotile_grid": {
        "field": "<field-name-on-which-aggregation-will-be-performed>",
        "precision" : 10, // default value is 7
        "bounds": {  // optional object
          "top_left": <Point representing the top left corner>,
          "bottom_right": <Point representing the bottom right corner>
        }
      }
    }
  }
}

Input Parmeters:

  • precision: The integer zoom of the key used to define cells/buckets in the results. The default value is 7 and the max value is 29.
  • bounds: It is an optional object, which bounds the region over which the aggregation is happening. Shapes which are intersecting with this bound or completely present in this bounds will only be included in the aggregation output.

Example

Index Creation

PUT /example
{
    "mappings": {
        "properties": {
            "location": {
                "type": "geo_shape"
            }
        }
        
    }
}

Index Data

POST /example/_bulk?refresh
{"index":{"_id":191}}
{"name": "NEMO Science Museum","location": {"type": "envelope","coordinates": [ [100.0, 1.0], [101.0, 0.0] ]}}
{"index":{"_id":219}}
{"name": "NEMO Science Museum","location": {"type": "envelope","coordinates": [ [100.0, 1.0], [106.0, 0.0] ]}}

Run Aggregation

POST /myexample/_search?size=0
{
  "aggregations": {
    "myaggregation": {
      "geotile_grid": {
        "field": "location",
        "precision": 4
      }
    }
  }
}

Output of Aggregation

{
....
  "aggregations": {
        "myaggregation": {
            "buckets": [
                {
                    "key": "4/12/8",
                    "doc_count": 2
                },
                {
                    "key": "4/12/7",
                    "doc_count": 2
                }
            ]
        }
    }

References

  1. RFC for Aggregations: [RFC] - Implement Aggregations on Geo Shape Field #84
  2. [Feature] : Geo Tile Grid Aggregation on Geo Shape field #194
@navneet1v
Copy link
Collaborator Author

Closing this RFC as the code is merged to 2.9 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aggregations label for all the aggregations that are getting created in this repo feature geospatial v2.9.0 v2.9.0
Projects
None yet
Development

No branches or pull requests

1 participant