0

我正在尝试使用在 MySQL 表上编制索引的 Elasticsearch 来查找距离特定数据点 x 公里范围内的所有地址。我已使用以下内容为该表编制索引:

{
  "type": "jdbc",
  "jdbc": {
       "strategy": "simple",
       "url": "jdbc:mysql://hostname/databasename",
       "user": "username",
       "password": "password",
       "sql": "SELECT name,address1,city,state,zip,lat as `location.lat`,lng as `location.lon` FROM addresses",
       "poll": "24h",
       "max_retries": 3,
       "max_retries_wait": "10s",
       "index" : "teststores",
       "type" : "providers"
   },
   "index": {
       "index": "addressindex",
       "autocommit": "true",
       "type": "mysql",
       "bulk_size": 100,
       "type_mapping": {
           "location_mapping" : { 
                "properties" : {
                    "pin" : {
                        "type" : "geo_point"
                    }
                }       
            }
        }
   }
}

索引数据的示例如下:

"_index": "teststores",
"_type": "providers",
"_id": "Rue2Yxo7SSa_mi5-AzRycA",
"_score": 1,
"_source": {
    "zip": "10003",
    "name": "I Salon",
    "state": "NY",
    "address1": "150 East 14th Street",
    "location":{
                "lat": 40.7337,
                "lon": -73.9881
               },
    "city": "New York"
}

我想调整以下查询以使用 lat 和 lng 来计算距离。

{ 
  "query": {
       "filtered": {
       "query": {
          "match_all": {
           }
        },
        "filter": {
           "geo_distance" : {
               "distance" : "2km",
               "pin.location" : {
                    "lat" : 40.686511,
                    "lon" : -73.986574
                }
            }
        }
     }
  },
}

如何调整它以使距离有效并获得 x 公里内的所有地址?

4

0 回答 0