总结
Elasticsearch 计算并返回距离一共有两种方法:sort 和 script_fields
环境概述
- CentOS 7.6
- Elasticsearch 7.10
创建索引
PUT /scenic_spot
{
"mappings": {
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "text"
},
"pin": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
},
"settings": {
"number_of_replicas": 3,
"number_of_shards": 3
}
}
索引数据
PUT /scenic_spot/_doc/1
{
"id": 1,
"name": "恭王府景区",
"pin": {
"location": {
"lat": 31.007925,
"lon": 103.607572
}
}
}
PUT /scenic_spot/_doc/2
{
"id": 2,
"name": "故宫博物院",
"pin": {
"location": {
&