我是一名对ElasticSearch不是很有经验的人,希望了解如何根据特定整数值提高搜索结果的优先级。
以下是一个文档示例:
{
"_index": "links",
"_type": "db1",
"_id": "mV32vWcBZsblNn1WqTcN",
"_score": 8.115617,
"_source": {
"url": "example.com",
"title": "Example website",
"description": "This is an example website, used for various of examples around the world",
"likes": 9,
"popularity": 543,
"tags": [
{
"name": "example",
"votes": 5
},
{
"name": "test",
"votes": 2
},
{
"name": "testing",
"votes": 1
}
]
}
}
现在这个特定的搜索,重点在于标签
,我想知道如何提高_score
并将其乘以标签
下投票
中的整数。
如果这不可能(或者很难实现),我只想知道如何通过投票
(而不是标签
下的投票)来提高_score
例如,为投票
中的每个整数添加0.1到_score
中
这是我目前正在使用的搜索查询(仅用于搜索标签):
{
"query": {
"nested": {
"path": "tags",
"query": {
"bool":{
"should":{
"match":{
"tags.name":"example,testing,something else"
}
}
}
}
}
}
}
我在网上找不到太多信息,希望有人能帮助我。
如何使用整数值提高 _score
?
更新
以下是映射的更多信息:
{
"links": {
"mappings": {
"db1": {
"properties": {
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"likes": {
"type": "long"
},
"popularity": {
"type": "long"
},
"tags": {
"type": "nested",
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"votes": {
"type": "long"
}
}
}
}
}
}
}
}
更新 2
将tags.likes
/tags.dislikes
更改为tags.votes
,并在tags
中添加了一个nested
属性。
tags
是nested
类型吗? - Valtags
应该是嵌套的,否则你无法查询特定嵌套标签以获取它们的赞/踩值来提高分数。 - Val