欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

es7.8附近的人附近的门店查询

程序员文章站 2024-03-16 22:04:22
...

坐标 附近的门店

geo_point经纬度坐标类型

DELETE index2
PUT index2
PUT index2/_mapping
{
  "properties":{
    "shop":{
      "properties":{
        "id":{
          "type":"integer"
        },
        "shopName":{
          "type":"text"
        },
        "location":{
            "type":"geo_point"
        }
     }
    },
    
    "goods":{
      "properties":{
        "id":{
          "type":"integer"
        },
        "goodsName":{
          "type":"text"
        },
        "parentId":{
          "type":"integer"
        }
      }
    },
    
    "relation":{
        "type": "join",
        "relations":{
          "shop":["goods"]
        }
      }
  }
}

添加数据

POST index2/_doc/1
{
  "shop.id":"1",
  "shop.shopName":"店铺1(宝安中心店)",
  "shop.location":{
    "lat":"22.566822",
    "lon":"113.890394"
  }
}

POST index2/_doc/2
{
  "shop.id":2,
  "shop.shopName":"店铺2(西乡店)",
  "shop.location":{
    "lat":"22.581735",
    "lon":"113.869117"
  }
}

POST index2/_doc/3
{
  "shop.id":3,
  "shop.shopName":"店铺3(南山深大店)",
  "shop.location":{
    "lat":"22.54387",
    "lon":"113.950339"
  }
}
#查询10公里内按照距离排序
GET index2/_search
{
  "query": {
    "geo_distance": {
      "distance": "10km",
      "shop.location": {
        "lat": "22.567086",
        "lon": "113.868281"
      }
    }
  },
  "sort": [
    {
      "_geo_distance": {
        "unit": "km", 
        "shop.location": {
          "lat": 23.131304,
          "lon": 113.262402
        },
        "order": "asc"
      }
    }
  ]
}

es7.8附近的人附近的门店查询

相关标签: es