Typ*_*war 5 boost filter elasticsearch
我对 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
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
现在,在这个特定的搜索中,重点是 ,tags
我想知道如何增强并将其乘以下面_score
的整数。votes
tags
如果这是不可能的(或者很难实现),我只是想知道如何_score
通过votes
(不在tags
)来提高
_score
例如,为中的每个整数添加 0.1votes
这是我当前使用的搜索查询(仅用于搜索标签):
{
"query": {
"nested": {
"path": "tags",
"query": {
"bool":{
"should":{
"match":{
"tags.name":"example,testing,something else"
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在网上找不到太多信息,希望有人能帮助我。
如何使用_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"
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
将tags.likes
/更改tags.dislikes
为tags.votes
,并向nested
tags
这花了很长时间才弄清楚。在去那里的路上我学到了很多东西。
这是最终结果:
{
"query": {
"nested": {
"path": "tags",
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"match": {
"tags.name": "example"
}
},
{
"match": {
"tags.name": "testing"
}
},
{
"match": {
"tags.name": "test"
}
}
]
}
},
"functions": [
{
"field_value_factor": {
"field": "tags.votes"
}
}
],
"boost_mode": "multiply"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
中的数组should
有很大帮助,很高兴我可以将它与function_score
归档时间: |
|
查看次数: |
2859 次 |
最近记录: |