首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python -在弹性搜索中插入geo数据后,如何搜索数据?

Python -在弹性搜索中插入geo数据后,如何搜索数据?
EN

Stack Overflow用户
提问于 2016-12-04 00:28:19
回答 1查看 389关注 0票数 0

我正在使用将geo数据插入到下面的引擎中,但是我可以使用什么函数或方法来搜索数据呢?你能举个例子吗?

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-04 00:33:41

您可以使用Geo距离查询:

代码语言:javascript
复制
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "10km",
                    "geo.location" : {
                        "lat" : 10,
                        "lon" : -10
                    }
                }
            }
        }
    }
}

例如,您可以同时使用es.searchelasticsearch.helpers.scan

代码语言:javascript
复制
res = es.search(index='geodata', body= { ... }) # put the above dictionary in the `body`
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40954086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档