build
mvn clean package -DskipTests
run
cd ./target/bin export ES_CLASSPATH="../classes:../lib/*"; ./elasticsearch
create index
curl -XPUT http://localhost:9200/test_local_index/ -d ' {}'
mapping
curl -XPUT http://localhost:9200/test_local_index/test/_mapping -d ' { "test" : { "properties" : { "pin" : { "properties" : { "location" : { "type" : "geo_point" } } } } } }'
add document
curl -XPOST http://localhost:9200/test_local_index/test/2 -d '{ "pin" : { "location" : { "lat" : 40.12, "lon" : -71.34 },
"tag" : ["food", "family"], "text" : "my favorite family restaurant" }
}'
search
curl -XPOST http://localhost:9200/test_local_index/_search -d ' { "query" : { "filtered" : { "query" : { "match" : { "text" : "restaurant" } }, "filter" : { "geo_distance" : { "distance" : "150km", "pin.location" : { "lat" : 40, "lon" : -70
} } } } } }'
Elasticsearch地理距离搜索
本文详细介绍如何使用Elasticsearch创建本地索引,定义地理坐标映射,并通过curl命令进行地理距离过滤查询,演示了从构建环境到实现精确地理位置搜索的全过程。
3470

被折叠的 条评论
为什么被折叠?



