如何在弹性搜索中形成搜索查询在python中查询地理点的DSL?

时间:2015-12-29 18:16:21

标签: python elasticsearch

{
  "geo_bounding_box": {
    "location": {
      "top_right": {
        "lat": 4.482137,
        "lon": 51.0355306
      },
      "bottom_left": {
        "lat": 4.482137,
        "lon": 51.0146768
      }
    }
  }
} . 

将上述搜索过滤器转换为弹性搜索查询DSL。(Python)

2 个答案:

答案 0 :(得分:3)

如果查看source code,您会发现geo_bounding_box filter,您的脚本应该是这样的

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search

client = Elasticsearch()

s = Search(using=client, index="my_index") \
    .filter("geo_bounding_box", location={
            "top_right": {
              "lat": 4.482137,
              "lon": 51.0355306
            },
            "bottom_left": {
              "lat": 4.482137,
              "lon": 51.0146768
            }
          })

希望这有帮助!

答案 1 :(得分:0)

.filter(“geo_bounding_box”,location = {“top_right”:{“lat”:4.482137,“lon”:51.0355306},“bottom_left”:{“lat”:4.482137,“lon”:51.0146768}})

这会有效!