Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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]
- }
- }
- }
- }
- }
- }
- }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement