简体   繁体   English

Python-将地理数据插入弹性搜索后,如何搜索数据?

[英]Python - After i insert geo data into elastic search, how do I search the data?

I'm am using python-elasticsearch to insert geo data into the engine as below, but what function or method can I use to search for my data? 我正在使用python-elasticsearch将地理数据插入到引擎中,如下所示,但是我可以使用什么函数或方法来搜索我的数据? Can you give an example please? 你能举个例子吗?

mappings = { 
            "doc": {
                   "properties": {
                                  "geo": {
                                         "properties": {
                                            "location": {"type": "geo_point"}
                                          }
                                  }
                   }
            }
          }
es.indices.create(index='geodata', body=mappings)

# ...
es_entries['geo'] =  {'location':str(data['_longitude_'])+","+str(data['_latitude_'])}
# ...
es.index(index="geodata", doc_type="doc", body=es_entries)

You can use the Geo Distance Query: 您可以使用地理距离查询:

{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "10km",
                    "geo.location" : {
                        "lat" : 10,
                        "lon" : -10
                    }
                }
            }
        }
    }
}

You can use both es.search and elasticsearch.helpers.scan , for example: 您可以同时使用es.searchelasticsearch.helpers.scan ,例如:

res = es.search(index='geodata', body= { ... }) # put the above dictionary in the `body`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM