创建索引

  1. PUT /company-locations
  2. {
  3. "mappings": {
  4. "properties": {
  5. "id":{
  6. "type": "keyword"
  7. },
  8. "name": {
  9. "type": "text"
  10. },
  11. "addressPoint": {
  12. "type": "geo_point"
  13. }
  14. }
  15. }
  16. }

新增数据

  • 支持数组和经纬度格式 ```java PUT /company-locations/_doc/1 { “name”: “NetEast”, “addressPoint”: { “lat”: 40.7222, “lon”: 73.989 } }

PUT /company-locations/_doc/3 { “name”: “BaiDu”, “addressPoint”: { “lat”: 40.719, “lon”: 73.983 } } PUT /company-locations/_doc/2 { “name”: “Sina”, “addressPoint”: “40.323,63.784” } PUT /company-locations/_doc/4 { “name”: “Ora”, “addressPoint”: [40.323,87.784] }

  1. <a name="YzQOw"></a>
  2. #### 搜索
  3. ```java
  4. # 查询距离内的
  5. GET /company-locations/_search
  6. {
  7. "query": {
  8. "bool": {
  9. "must": [
  10. {
  11. "match_all": {}
  12. }
  13. ],
  14. "filter": {
  15. "geo_distance": {
  16. "distance": "100km",
  17. "addressPoint": {
  18. "lat": 40.73,
  19. "lon": 74.1
  20. }
  21. }
  22. }
  23. }
  24. }
  25. }
  26. # 查询某个矩形内的
  27. GET /company-locations/_search
  28. {
  29. "query": {
  30. "bool": {
  31. "must": {
  32. "match_all":{}
  33. },
  34. "filter": {
  35. "geo_bounding_box": {
  36. "addressPoint": {
  37. "top_left": {
  38. "lat": 40.73,
  39. "lon": 71.12
  40. },
  41. "bottom_right": {
  42. "lat": 40.717,
  43. "lon": -73.99
  44. }
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }