Created
September 3, 2014 09:41
-
-
Save clement-tourriere/a05723be373d75dddf72 to your computer and use it in GitHub Desktop.
Testing ElasticSearch geo_polygon filter
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
curl -XDELETE "http://localhost:9200/geo_polygon" | |
curl -XPOST "http://localhost:9200/geo_polygon" | |
# We index points with geo_point and geo_shape types for testing purpose | |
curl -XPOST "http://localhost:9200/geo_polygon/loc/_mapping" -d' | |
{ | |
"loc": { | |
"properties": { | |
"location": { | |
"type": "geo_point" | |
}, | |
"location-shape": { | |
"type": "geo_shape" | |
} | |
} | |
} | |
}' | |
curl -XPOST "http://localhost:9200/geo_polygon/loc/1" -d' | |
{ | |
"location": [ | |
2.31884888759, | |
48.8651610589 | |
], | |
"location-shape": { | |
"type": "point", | |
"coordinates": [ | |
2.31884888759, | |
48.8651610589 | |
] | |
} | |
}' | |
curl -XPOST "http://localhost:9200/geo_polygon/loc/2" -d' | |
{ | |
"location": [ | |
2.31897149993, | |
48.8653294812 | |
], | |
"location-shape": { | |
"type": "point", | |
"coordinates": [ | |
2.31897149993, | |
48.8653294812 | |
] | |
} | |
}' | |
# geo_polygon query. Returns only one document | |
curl -XPOST "http://localhost:9200/geo_polygon/_search" -d' | |
{ | |
"post_filter": { | |
"geo_polygon": { | |
"location": { | |
"points": [ | |
[ | |
2.31884888759, | |
48.8651610589 | |
], | |
[ | |
2.31884888759, | |
48.8653294812 | |
], | |
[ | |
2.31897149993, | |
48.8653294812 | |
], | |
[ | |
2.31897149993, | |
48.8651610589 | |
], | |
[ | |
2.31884888759, | |
48.8651610589 | |
] | |
] | |
} | |
} | |
} | |
}' | |
# geo_shape query (with exact same polygon) returns the two docs | |
curl -XPOST "http://localhost:9200/geo_polygon/_search" -d' | |
{ | |
"post_filter": { | |
"geo_shape": { | |
"location-shape": { | |
"shape": { | |
"type": "polygon", | |
"coordinates": [ | |
[ | |
[ | |
2.31884888759, | |
48.8651610589 | |
], | |
[ | |
2.31884888759, | |
48.8653294812 | |
], | |
[ | |
2.31897149993, | |
48.8653294812 | |
], | |
[ | |
2.31897149993, | |
48.8651610589 | |
], | |
[ | |
2.31884888759, | |
48.8651610589 | |
] | |
] | |
] | |
} | |
} | |
} | |
} | |
}' | |
# geo_bounding_box query with same bounds than geo_polygon query. Returns two docs | |
curl -XPOST "http://localhost:9200/geo_polygon/_search" -d' | |
{ | |
"post_filter": { | |
"geo_bounding_box": { | |
"location": { | |
"top_left": [ | |
2.31884888759, | |
48.8653294812 | |
], | |
"bottom_right": [ | |
2.31897149993, | |
48.8651610589 | |
] | |
}, | |
"type": "memory" | |
} | |
} | |
}' | |
# geo_polygon query with larger bounds. Returns two docs | |
curl -XPOST "http://localhost:9200/geo_polygon/_search" -d' | |
{ | |
"filter": { | |
"geo_polygon": { | |
"location": { | |
"points": [ | |
[ | |
2.06130981445, | |
48.9098646109 | |
], | |
[ | |
2.59689331055, | |
48.9098646109 | |
], | |
[ | |
2.59689331055, | |
48.8077679015 | |
], | |
[ | |
2.06130981445, | |
48.8077679015 | |
], | |
[ | |
2.06130981445, | |
48.9098646109 | |
] | |
] | |
} | |
} | |
} | |
}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment