我正在尝试解决在查询 ElasticSearch 数千个结果时遇到的性能问题。基本思想是,我们进行一些查询后处理,并仅显示前 X 个结果(查询可能有 ~100000 个结果,而根据我们的评分机制,我们只需要前 100 个结果)。
基本机制如下:ElasticSearch 分数在 0..1 (score/max(score)) 之间标准化,我们添加排名分数(也在 0..1 之间标准化)并除以 2。
我想做的是使用自定义评分(或者任何有效的方法)将此逻辑移至 ElasticSearch 中:https ://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function -score-query.html#function-script-score
我面临的问题是,使用分数脚本/分数函数我似乎找不到一种方法来执行 max(_score) 之类的操作来将分数标准化在 0 和 1 之间。
"script_score" : {
"script" : "(_score / max(_score) + doc['some_normalized_field'].value)/2"
}
Run Code Online (Sandbox Code Playgroud)
欢迎任何想法。
我不确定我是否理解你的问题。您想限制结果数量吗?
你试过了吗?
{
"from" : 0, "size" : 10,
"query" : {
"term" : { "name" : "dennis" }
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用 sort 来定义排序顺序,默认情况下它将按主查询排序。
您还可以使用聚合(带或不带 function_score )
{
"query": {
"function_score": {
"functions": [
{
"gauss": {
"date": {
"scale": "3d",
"offset": "7d",
"decay": 0.1
}
}
},
{
"gauss": {
"priority": {
"origin": "0",
"scale": "100"
}
}
}
],
"query": {
"match" : { "body" : "dennis" }
}
}
},
"aggs": {
"hits": {
"top_hits": {
"size": 10
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16781 次 |
| 最近记录: |