【问题标题】:how can i fix 'failed to find geo_point field [pin.location]'我该如何解决“找不到geo_point字段[pin.location]”
【发布时间】:2020-01-02 11:27:47
【问题描述】:

所以我有一个地图点索引,我需要在其中放入一些数据。但它似乎没有将我的数据注册为 pin.location 的有效输入。

我已经尽我所能从https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html 获得 但这仍然不起作用

这是我设置索引的地方:

mappings = {
    "mappings": {
        "properties": {
            "pin": {
                "properties": {
                    "location": {
                        "type": "geo_point"
                    }
                }
            },
            "index.mapping.single_type": False
        }
    }
}
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
if not es.indices.exists(index="groups_map"):
    es.indices.create(index='groups_map', body=mappings)
es.index(index='groups_map', id=data["id"], doc_type='groups_map', body=data, request_timeout=30)

这是数据:

data = {
        "pin": {
               "properties": {"location": {
                              "type": "geo_point",
                              'lat': request.POST['source_lat'],
                              'lon': request.POST['source_lon']}
                    }

                },
         "id": instance.id,

        }

这是我的查询数据,这里只是一个带有 lat 和 lon 值的字典

 query = {
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_distance": {
                    "distance": "12km",
                    "pin.location": {
                        "lat": data["lat"],
                        "lon": data["lon"]
                    }
                }
            }
        }
    }
return es.search(index="groups_map", body={"query": query}, size=20)

这是我得到的完整错误: elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', '未能找到geo_point字段[pin.location]')

【问题讨论】:

  • @LinPy 我收到此错误:elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', '根映射定义具有不受支持的参数:[pin : {properties={location={type=geo_point) }}}]')
  • ``` mappings = { "mappings": { "pin": { "properties": { "location": { "type": "geo_point" } } } } ``

标签: python elasticsearch


【解决方案1】:

问题是您的数据不正确,因为您需要删除properties 键。您的数据应如下所示。

data = {
    "pin": {
         "location": {
               'lat': request.POST['source_lat'],
               'lon': request.POST['source_lon']
         }
    },
    "id": instance.id,
}

注意:在索引新数据之前,您需要删除并重新创建索引。

【讨论】:

  • 我将数据更改为您所说的,但我仍然收到消息:elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'failed to find geo_point field [pin.location]' )
  • 需要先删除索引再重新创建。
  • 我也这样做了 curl -X DELETE "localhost:9200/groups_map"
  • 好的,那么在你运行你的代码之后,你能展示一下你在运行curl -XGET "localhost:9200/groups_map"时得到了什么吗?
  • 删除前:{"groups_map":{"aliases":{},"mappings":{"properties":{"id":{"type":"long"},"pin ":{"properties":{"location":{"properties":{"lat":{"type":"text","fields":{"keyword":{"type":"keyword"," ignore_above":256}}},"lon":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"type ":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}}}}},"settings":{" index":{"creation_date":"1567069163611","number_of_shards":"1","number_of_replicas":"1","uuid":"Gp4hdzxGTpmINEbxGBDCUQ","version":{"created":"7030199"}, "provided_name":"groups_map"}}}}%
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-09
  • 2020-04-24
  • 1970-01-01
  • 1970-01-01
  • 2018-08-08
  • 1970-01-01
  • 2020-05-05
相关资源
最近更新 更多