Skip to content

Instantly share code, notes, and snippets.

@spalladino
Created January 21, 2015 15:53
Show Gist options
  • Select an option

  • Save spalladino/a898f75b4c02aa75e8a1 to your computer and use it in GitHub Desktop.

Select an option

Save spalladino/a898f75b4c02aa75e8a1 to your computer and use it in GitHub Desktop.
Hit test in elasticsearch
# 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