这是http://localhost:9200/fb_events/_search
[...]
"hits": {
"total": 18,
"max_score": 1,
"hits": [
{
"_index": "fb_events",
"_type": "event",
"_id": "AVw1MpQDmr08c_VMq0b_",
"_score": 1,
"_source": {
"description": "desc",
"start_time": "2017-11-17T20:00:00+0100",
"place": {
"id": "496893413669851",
"name": "Dwa Światy",
"location": {
"city": "Torun",
"zip": "87-100",
"country": "Poland",
"longitude": 18.603430234931,
"street": "ul. Ducha św. 10/12",
"latitude": 53.009319027091,
"geo_cord": "18.6034302349,53.0093190271"
}
},
"end_time": "2017-11-17T23:00:00+0100",
"id": "622266071285763",
"name": "Podwórkowi Chuligani (XX-lecie) + TBA - Toruń / Dwa Światy"
}
}
}
[...]
我喜欢根据位置搜索记录。这是我的问题:
query = {
"size": 100,
"query": {
"bool" : {
"must" : {
"match_all" : {}
},
"filter": {"geo_distance": {"distance": distance, "geo_cord": {"lat": lat, "lon": lon}}}
}
}
}
但是当我执行此操作时,我收到错误RequestError: TransportError(400, u'search_phase_execution_exception', u'failed to find geo_point field [geo_cord]')
我的问题是,我该怎么办?添加映射到此字段?
编辑:
GET /fb_events/_mapping/event
{
"fb_events": {
"mappings": {
"event": {
"properties": {
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"end_time": {
"type": "date"
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"place": {
"properties": {
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"location": {
"properties": {
"city": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"country": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"geo_cord": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"latitude": {
"type": "float"
},
"longitude": {
"type": "float"
},
"street": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"zip": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"start_time": {
"type": "date"
}
}
}
}
}
}
答案 0 :(得分:2)
根据您的映射,geo_cord
字段的类型为text
,如果您想在geo_point
查询中使用它,则该字段应为geo_distance
。< / p>
在索引第一个文档之前,您需要删除索引并使用正确的映射重新创建索引。
并确保在查询中使用place.location.geo_cord
代替location.geo_cord
。