Elastic Search - 按文档类型排序
Elastic Search - Sort By Doc Type
我有一个具有 2 种不同文档类型的弹性搜索索引:'a'
和 'b'
。我想按类型对我的结果进行排序,并优先考虑 type='b'
(即使它的分数很低)。我一直在客户端使用下面的搜索结果并对它们进行排序,但我意识到这种方法效果不佳,因为我只检查通常不包含任何 b 的前 10 个结果。增加 return 结果并不理想。我想让弹性搜索来完成这项工作。
http://<server>:9200/my_index/_search?q=london
您需要为每种类型玩 function_score
and, depending on how you already score your documents, test some weight
values, boost_mode
s and score_mode
s。例如:
GET /some_index/a,b/_search
{
"query": {
"function_score": {
"query": {
# your query here
},
"functions": [
{
"filter": {
"type": {
"value": "b"
}
},
"weight": 3
},
{
"filter": {
"type": {
"value": "a"
}
},
"weight": 1
}
],
"score_mode": "first",
"boost_mode": "multiply"
}
}
}
它为 me.you 工作将在命令提示符下执行以下命令。
curl -XGET localhost:9200/index_v1,index_v2/_search?pretty -d @boost.json
boost.json
{
"indices_boost" : {
"index_v2" : 1.4,
"index_v1" : 1.3
}
}
我有一个具有 2 种不同文档类型的弹性搜索索引:'a'
和 'b'
。我想按类型对我的结果进行排序,并优先考虑 type='b'
(即使它的分数很低)。我一直在客户端使用下面的搜索结果并对它们进行排序,但我意识到这种方法效果不佳,因为我只检查通常不包含任何 b 的前 10 个结果。增加 return 结果并不理想。我想让弹性搜索来完成这项工作。
http://<server>:9200/my_index/_search?q=london
您需要为每种类型玩 function_score
and, depending on how you already score your documents, test some weight
values, boost_mode
s and score_mode
s。例如:
GET /some_index/a,b/_search
{
"query": {
"function_score": {
"query": {
# your query here
},
"functions": [
{
"filter": {
"type": {
"value": "b"
}
},
"weight": 3
},
{
"filter": {
"type": {
"value": "a"
}
},
"weight": 1
}
],
"score_mode": "first",
"boost_mode": "multiply"
}
}
}
它为 me.you 工作将在命令提示符下执行以下命令。
curl -XGET localhost:9200/index_v1,index_v2/_search?pretty -d @boost.json
boost.json {
"indices_boost" : {
"index_v2" : 1.4,
"index_v1" : 1.3
}
}