我需要做的是按位置提升文档(越近越好)。locations
是嵌套类型。
工作正常除了如果文档中缺少locations
,Elasticsearch不会返回文档。如果缺少字段,Elasticsearch应该将文档视为完美命中。如何实现这一点?
我的查询:
{
"sort": [
{
"_score": "desc"
}
],
"query": {
"function_score": {
"query": {
"bool": {
"must_not": [],
"should": [
{
"nested": {
"path": "locations",
"query": {
"function_score": {
"score_mode": "sum",
"functions": [
{
"gauss": {
"locations.coordinates": {
"origin": {
"lat": "50.1078852",
"lon": "15.0385376"
},
"scale": "100km",
"offset": "20km",
"decay": "0.5"
}
}
}
]
}
}
}
}
]
}
}
}
}
}
字符串
顺便说一句:我正在使用Elasticsearch 5.0
2条答案
按热度按时间krugob8w1#
在functions部分中添加一个
function
,并使用高提升(如1000)来弥补缺失的locations
,类似于以下内容:字符串
因此,缺少
locations
的记录将首先出现,因为权重很高。这可能略有不同。有关查询的更多信息,请单击此处:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html的
icnyk63a2#
使用过滤器内部函数
字符串