简体   繁体   English

弹性搜索-对批量导入的JSON执行地理位置查询

[英]Elastic Search - Performing Geo Location Query on Bulk imported JSON

I have a file modified.json containing JSON documents which contain the following: 我有一个包含其中包含以下JSON文件文件modified.json:

{"index":{"_index": "trial", "_type": "trial", "_id":"1"}}
{"clinics" : [{"price": 1048, "city": "Bangalore", "Location": {"lon": 77.38381692924742, "lat": 12.952155989068519}}, {"price": 1048, "city": "Bangalore", "Location": {"lon": 77.38381692924742, "lat": 12.952155989068519}}]

.... And more similar documents. ....和更多类似文件。 I am running a bulk insert through this command: 我正在通过此命令运行批量插入:

curl -s -XPOST 'http://localhost:9200/_bulk' --data-binary @modified.json

Next, through the Sense (Google Chrome) plugin, I am issuing the following request 接下来,通过Sense(Google Chrome)插件,我发出以下请求

Server: localhost:9200/trial/trial 伺服器:localhost:9200 / trial / trial

PUT _search
{
    "mappings": {
        "clinics": {
            "properties": {
                "Location": {"type": "geo_point"}
            }
        }
    }
}

I don't know whether or not this is creating a mapping for the Location fields. 我不知道这是否正在为“位置”字段创建映射。 After issuing a search request, like this: 发出搜索请求后,如下所示:

Server: localhost:9200/trial/trial 伺服器:localhost:9200 / trial / trial

GET _search
{
    "query": {
        "filtered" : {
            "query" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "20km",
                    "Location" : {
                        "lat" : 12.958487287824958,
                        "lon" : 77.69648881178146
                    }
                }
            }
        }
    }
}

I am getting an error saying: failed to find geo_point field [Location]]; 我收到一条错误消息: 找不到geo_point字段[Location]]; }]", }]“,

Please help me regarding this. 请帮助我。 Also, if possible also guide me on how to do faceted search on this data, to show clinics within a range of distance: like between 20 and 30 kilometers 另外,如果可能的话,还指导我如何对该数据进行多面搜索,以显示距离范围内的诊所:例如20至30公里

You need to reverse your ordering. 您需要取消订购。 PUT your mapping mapping first and then do the bulk insert. 首先放置您的映射映射,然后进行批量插入。

By putting the map before the insert you are letting ES know what the datatype are so that it can index them correctly. 通过将映射放在插入之前,您可以让ES知道数据类型是什么,以便它可以正确地为它们建立索引。 ES allows you to add mappings to an existing index but the data that's already there isn't going to get re-indexed automatically. ES允许您将映射添加到现有索引,但是已经存在的数据不会自动重新索引。 (This is a known issue). (这是一个已知的问题)。

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

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