gpt4 book ai didi

elasticsearch - 排序顺序Elasticsearch相等相关性

转载 作者:行者123 更新时间:2023-12-03 00:56:22 24 4
gpt4 key购买 nike

我有以下文件:GET /books

[{
"title": "a book",
"certified": true,
"publisherId": 1
},
{
"title": "book a",
"certified": false
"publisherId": 2
}]

当我对 title执行简单的查询字符串查询时,我希望结果在_score上排序。
如果_score相等,则应首先显示经过 认证的的图书。
如果_score相等且书籍经过认证,则应首先显示具有 PublisherId 1 的书籍。

如何在ES中实现这些类型的平局规则/排序规则?

我想做这样的事情,但是显然这是行不通的:
{
"query": {},
"sort": [
{"_score": {"order": "desc"},
{"term": {"certified": true}},
{"term": {"publisherId": "1"}}
]
}

最佳答案

您可以简单地使用bool/should查询根据certifiedpublisherId约束来增强文档。

如果您在以下查询中删除bool/should,则所有文档的评分方式均相同。添加bool/should将增强certified和带有publisherId: 1的文档

{
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "book",
"boost": 3
}
}
}
],
"should": [
{
"term": {
"certified": true
}
},
{
"term": {
"publisherId": 1
}
}
]
}
},
"sort": [
{
"_score": {
"order": "desc"
}
}
]
}

关于elasticsearch - 排序顺序Elasticsearch相等相关性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43536687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com