-
-
Save owainb/fb58a7703a73b456b887 to your computer and use it in GitHub Desktop.
Filtering points across indexes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create index with type with one geo_point field | |
curl -XPOST "http://localhost:9200/geoindex1" -d ' | |
{ | |
"mappings" : { | |
"geotest" : { | |
"dynamic" : "false", | |
"properties" : { | |
"location": { | |
"type" : "geo_point" | |
} | |
} | |
} | |
} | |
} | |
' | |
# Create a second similar index with different geo_point field name | |
curl -XPOST "http://localhost:9200/geoindex2" -d ' | |
{ | |
"mappings" : { | |
"geotest" : { | |
"dynamic" : "false", | |
"properties" : { | |
"place": { | |
"type" : "geo_point" | |
} | |
} | |
} | |
} | |
} | |
' | |
# Index a record in teh first index | |
curl -XPOST "http://localhost:9200/geoindex1/geotest/1" -d ' | |
{ | |
"location": { | |
"lon": -1.09, | |
"lat": 51.34 | |
} | |
} | |
' | |
# Index a record in teh second index | |
curl -XPOST "http://localhost:9200/geoindex2/geotest/1" -d ' | |
{ | |
"location": { | |
"lon": -1.09, | |
"lat": 51.34 | |
} | |
} | |
' | |
# Search across the indexes. Aggregate by geohash cell and filter by bounding box. | |
curl -XPOST "http://localhost:9200/geoindex1,geoindex2/geotest/_search?pretty=true" -d ' | |
{ | |
"query": {"match_all": {}}, | |
"size": 0, | |
"aggs": { | |
"view1": { | |
"filter": { | |
"geo_bounding_box": { | |
"location": { | |
"top_left": { | |
"lat": -11.25, | |
"lon": 56.25 | |
}, | |
"bottom_right": { | |
"lat": 0.0, | |
"lon": 50.625 | |
} | |
} | |
} | |
}, | |
"aggs": { | |
"cells": { | |
"geohash_grid": { | |
"field": "location", | |
"precision": 2 | |
} | |
} | |
} | |
}, | |
"view2": { | |
"filter": { | |
"geo_bounding_box": { | |
"place": { | |
"top_left": { | |
"lat": -11.25, | |
"lon": 56.25 | |
}, | |
"bottom_right": { | |
"lat": 0.0, | |
"lon": 50.625 | |
} | |
} | |
} | |
}, | |
"aggs": { | |
"cells": { | |
"geohash_grid": { | |
"field": "place", | |
"precision": 2 | |
} | |
} | |
} | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment