ElasticSearch搜索、查询、过滤与分面操作指南
1. 搜索、查询与过滤
在地理定位中,常见的操作之一是搜索特定区域。ElasticSearch提供了多种过滤方式,以满足不同的搜索需求。
1.1 布尔过滤器性能
从性能角度考虑,布尔过滤器比大量的与(and)、或(or)、非(not)过滤器更快。
1.2 使用geo_bounding_box过滤器
在地理定位中,搜索一个矩形区域是非常常见的操作。
-准备工作:需要一个正常运行的ElasticSearch集群,并使用geo populate脚本填充数据。
-操作步骤:若要搜索与维度为(40.03, 72.0)和(40.717, 70.99)的边界框相关的文档,可以使用以下查询:
curl -XGET http://127.0.0.1:9200/test-mindex/_search -d '{ "query": { "filtered": { "filter": { "geo_bounding_box": { "pin.location": { "bottom_right": { "lat": 40.03,