Skip to content

Instantly share code, notes, and snippets.

@cdahlqvist
Last active August 29, 2015 14:19
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 cdahlqvist/96d0d132c5586229345e to your computer and use it in GitHub Desktop.
Save cdahlqvist/96d0d132c5586229345e to your computer and use it in GitHub Desktop.
GeoShape example
# Add mapping
curl -XPUT localhost:9200/restaurants -d '{
"mappings": {
"areas": {
"properties": {
"name": {
"type": "string"
},
"area": {
"type": "string"
},
"location": {
"type": "geo_shape"
}
}
}
}
}'
# Add restaurant in area A1
curl -XPOST localhost:9200/restaurants/areas/r1 -d '{
"name" : "Restaurant 1",
"area" : "A1",
"location" : {
"type" : "polygon",
"coordinates" : [[
[ 4.89, 52.37 ],
[ 4.89, 52.27 ],
[ 4.99, 52.27 ],
[ 4.99, 52.37 ],
[ 4.89, 52.37 ]
]]
}
}'
# Add restaurant in area A2, which overlaps area A1
curl -XPOST localhost:9200/restaurants/areas/r2 -d '{
"name" : "Restaurant 2",
"area" : "A2",
"location" : {
"type" : "polygon",
"coordinates" : [[
[ 4.92, 52.40 ],
[ 4.92, 52.30 ],
[ 5.02, 52.30 ],
[ 5.02, 52.40 ],
[ 4.92, 52.40 ]
]]
}
}'
# Verify both restaurants are there
curl -XGET localhost:9200/restaurants/areas/_search?pretty=true -d '{
"query": {"match_all": {}}
}'
# Search to get one of the restaurants
curl -XGET localhost:9200/restaurants/areas/_search?pretty=true -d '{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"geo_shape": {
"location": {
"relation": "intersects",
"shape": {
"type": "Point",
"coordinates": [4.89994,52.36815]
}
}
}
}
}
}
}'
# Search to get both of the restaurants
curl -XGET localhost:9200/restaurants/areas/_search?pretty=true -d '{
"query": {
"filtered": {
"query": {"match_all": {}},
"filter": {
"geo_shape": {
"location": {
"relation": "intersects",
"shape": {
"type": "Point",
"coordinates": [4.94494,52.31545]
}
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment