elasticsearch - 基于整数值的提升分数 - 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
}
]
}
}
现在在这个特定的搜索中,重点是tags
,我想知道如何提升_score
并将其乘以votes
under中的整数tags
。
如果这是不可能的(或很难实现),我只想知道如何_score
通过votes
(而不是下tags
)来提升
示例,将 0.1 添加到中的_score
每个整数votes
这是我正在使用的当前搜索查询(仅用于搜索标签):
{
"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
,nested
并向tags
解决方案
您正在查看function score query
: https ://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
和field value factor
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor。
来自文档的片段:
GET /_search
{
"query": {
"function_score": {
"field_value_factor": {
"field": "tags.dislikes",
"factor": 1.2,
"modifier": "sqrt",
"missing": 1
}
}
}
}
或者script score
因为你的嵌套tags
字段(不确定field value score
嵌套结构是否可以正常工作)。
推荐阅读
- python - 浏览器(或代理)发送了此服务器无法理解的请求。KeyError:'PostTitle'
- android - Android ViewModel LiveData 观察
- javascript - 从同步循环中调用异步函数并保持结果有序
- c# - 将 C# 8.0 转换为 C# 7.0
- templates - 错字3 默认根模板从第一页开始,在每一页上显示内容
- javascript - 将 onclick 添加到动态创建的 span 标签
- c# - 在本地 IIS 上运行时调试会出现 404 错误
- angular - 从 Angular 库访问 package.json
- mysql - 如何计算数据库中列的值
- reactjs - Antd Month DatePicker 视图未正确渲染