【发布时间】: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