问题背景:目前有个查询需要根据标题+内容全文检索,同时要在加上terms 精确匹配一些id串再去查询,查询的结果无法保证id匹配的数据_score为最高,让其排在最前面
期望实现效果: terms条件id精确匹配到的条目,优先排在最前面
查询脚本如下:
{
"highlight": {... },
"size": 20,
"query": {
"bool": {
"must": [
{
"terms": {
"categoryId": [
"1",
"2"
]
}
},
{
"bool": {
"should": [
{
"multi_match": {
"query": "测试",
"fields": [
"title",
"contentTxt"
],
"slop": 2
}
},
{
"terms": {
"id": [
"77B018A91A3B4B4BB131F270A58CB99B",
"BAABA77BECF841CA912955C1E44BF5EF",
"A9243C98DCA144719EF50411D04AE8C9",
"8953858B445A4CC9B889CDCFF59AF705",
"F558B769D1C44E6080F4635491110B1C",
"2C07E65419FA4D15B662A5217F3D4F13"
]
}
}
]
}
}
]
}
},
"from": 0
}
期望实现效果: terms条件id精确匹配到的条目,优先排在最前面
查询脚本如下:
{
"highlight": {... },
"size": 20,
"query": {
"bool": {
"must": [
{
"terms": {
"categoryId": [
"1",
"2"
]
}
},
{
"bool": {
"should": [
{
"multi_match": {
"query": "测试",
"fields": [
"title",
"contentTxt"
],
"slop": 2
}
},
{
"terms": {
"id": [
"77B018A91A3B4B4BB131F270A58CB99B",
"BAABA77BECF841CA912955C1E44BF5EF",
"A9243C98DCA144719EF50411D04AE8C9",
"8953858B445A4CC9B889CDCFF59AF705",
"F558B769D1C44E6080F4635491110B1C",
"2C07E65419FA4D15B662A5217F3D4F13"
]
}
}
]
}
}
]
}
},
"from": 0
}
2 个回复
w_b
赞同来自: wuzx
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自: