Skip to content

Instantly share code, notes, and snippets.

@owainb
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owainb/fb58a7703a73b456b887 to your computer and use it in GitHub Desktop.
Save owainb/fb58a7703a73b456b887 to your computer and use it in GitHub Desktop.
Filtering points across indexes
# 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