【发布时间】:2015-08-31 17:24:21
【问题描述】:
数据库的映射是这样的:
{
"users": {
"mappings": {
"user": {
"properties": {
credentials": {
"type": "nested",
"properties": {
"achievement_id": {
"type": "string"
},
"percentage_completion": {
"type": "integer"
}
}
},
"current_location": {
"type": "geo_point"
},
"locations": {
"type": "geo_point"
}
}
}
}
}
现在在映射中,您可以看到有两个地理距离字段,一个是 current_location,另一个是位置。现在我想根据 credentials.percentage_completion 对用户进行排序,这是一个嵌套字段。这很好,例如这个查询, 示例查询:
GET /users/user/_search?size=23
{
"sort": [
{
"credentials.percentage_completion": {
"order": "desc",
"missing": "_last"
}
},
"_score"
],
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "100000000km",
"user.locations": {
"lat": 19.77,
"lon": 73
}
}
}
}
}
}
我想更改桶中的排序顺序,希望的顺序是首先显示所有在 user.current_location 半径 100KM 范围内的人,并根据 credentials.percentage_completion 对他们进行排序,然后再按 credentials.percentage_completion 对其余用户进行排序.
我尝试在排序中放置条件并使其成为多级,但这不起作用,因为只有嵌套可以有过滤器,而嵌套字段只能有子字段。
我认为我可以使用 _score 进行排序并为 1000 公里以下的人提供更多相关性,但地理距离是一个过滤器,我似乎没有找到任何方法在过滤器中提供相关性。
这里有什么我遗漏的吗,任何帮助都会很棒。
谢谢
【问题讨论】:
标签: elasticsearch