Advertisement
Guest User

Untitled

a guest
May 29th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. # Add mapping
  2. curl -XPUT localhost:9200/restaurants -d '{
  3. "mappings": {
  4. "areas": {
  5. "properties": {
  6. "name": {
  7. "type": "string"
  8. },
  9. "area": {
  10. "type": "string"
  11. },
  12. "location": {
  13. "type": "geo_shape"
  14. }
  15. }
  16. }
  17. }
  18. }'
  19.  
  20. # Add restaurant in area A1
  21. curl -XPOST localhost:9200/restaurants/areas/r1 -d '{
  22. "name" : "Restaurant 1",
  23. "area" : "A1",
  24. "location" : {
  25. "type" : "polygon",
  26. "coordinates" : [[
  27. [ 4.89, 52.37 ],
  28. [ 4.89, 52.27 ],
  29. [ 4.99, 52.27 ],
  30. [ 4.99, 52.37 ],
  31. [ 4.89, 52.37 ]
  32. ]]
  33. }
  34. }'
  35.  
  36. # Add restaurant in area A2, which overlaps area A1
  37. curl -XPOST localhost:9200/restaurants/areas/r2 -d '{
  38. "name" : "Restaurant 2",
  39. "area" : "A2",
  40. "location" : {
  41. "type" : "polygon",
  42. "coordinates" : [[
  43. [ 4.92, 52.40 ],
  44. [ 4.92, 52.30 ],
  45. [ 5.02, 52.30 ],
  46. [ 5.02, 52.40 ],
  47. [ 4.92, 52.40 ]
  48. ]]
  49. }
  50. }'
  51.  
  52. # Verify both restaurants are there
  53. curl -XGET localhost:9200/restaurants/areas/_search?pretty=true -d '{
  54. "query": {"match_all": {}}
  55. }'
  56.  
  57. # Search to get one of the restaurants
  58. curl -XGET localhost:9200/restaurants/areas/_search?pretty=true -d '{
  59. "query": {
  60. "filtered": {
  61. "query": {"match_all": {}},
  62. "filter": {
  63. "geo_shape": {
  64. "location": {
  65. "relation": "intersects",
  66. "shape": {
  67. "type": "Point",
  68. "coordinates": [4.89994,52.36815]
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }'
  76.  
  77. # Search to get both of the restaurants
  78. curl -XGET localhost:9200/restaurants/areas/_search?pretty=true -d '{
  79. "query": {
  80. "filtered": {
  81. "query": {"match_all": {}},
  82. "filter": {
  83. "geo_shape": {
  84. "location": {
  85. "relation": "intersects",
  86. "shape": {
  87. "type": "Point",
  88. "coordinates": [4.94494,52.31545]
  89. }
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement