Created
January 21, 2015 15:53
-
-
Save spalladino/a898f75b4c02aa75e8a1 to your computer and use it in GitHub Desktop.
Hit test in elasticsearch
This file contains hidden or 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 | |
| curl -XPUT localhost:9200/locations/ | |
| # Create mapping with field 'shape' as geo shape | |
| curl -XPUT localhost:9200/locations/_mapping/location -d ' | |
| { | |
| "location": { | |
| "properties": { | |
| "name": { | |
| "type": "string" | |
| }, | |
| "shape": { | |
| "type": "geo_shape" | |
| } | |
| } | |
| } | |
| } | |
| ' | |
| # Index 3 elements | |
| curl -XPOST localhost:9200/locations/location -d ' | |
| { | |
| "name": "foo", | |
| "shape": { | |
| "type": "polygon", | |
| "coordinates": [ [ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ] ] | |
| } | |
| } | |
| ' | |
| curl -XPOST localhost:9200/locations/location -d ' | |
| { | |
| "name": "bar", | |
| "shape": { | |
| "type": "polygon", | |
| "coordinates": [ [ [ 200.0, 0.0 ], [ 201.0, 0.0 ], [ 201.0, 1.0 ], [ 200.0, 1.0 ], [ 200.0, 0.0 ] ] ] | |
| } | |
| } | |
| ' | |
| curl -XPOST localhost:9200/locations/location -d ' | |
| { | |
| "name": "foobar", | |
| "shape": { | |
| "type": "polygon", | |
| "coordinates": [ [ [ 100.0, 0.0 ], [ 201.0, 0.0 ], [ 201.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ] ] | |
| } | |
| } | |
| ' | |
| # Search for a geo_shape point | |
| curl localhost:9200/locations/location/_search -d ' | |
| { | |
| "query":{ | |
| "filtered": { | |
| "query": { | |
| "match_all": {} | |
| }, | |
| "filter": { | |
| "geo_shape": { | |
| "shape": { | |
| "shape": { | |
| "type": "point", | |
| "coordinates" : [100.5, 0.5] | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment