我正在尝试创建一个执行以下操作的弹性搜索查询:文档包含 ids ( ) 列表["id1", "id2", "id2"]。我有另一个 id 列表,我想显示其中任何 id 与此列表匹配的文档,并在更多文档 id 与提供的列表匹配时进行提升。我正在使用术语查询,如下所示:
"query": {
"bool": {
"must": {
"terms": {
"ids": ["id1", "id2", "id3"],
"boost": 10
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这会正确过滤掉没有任何ids匹配的文档id1, id2, or id3,但它会为具有任意数量的匹配 id 的任何文档提供相同的 id _score。因此,如果文档具有] ids: ["id1", "id4"],则其得分与具有ids: ["id1", "id2", "id3"] 的文档相同。
有谁知道如何根据elasticsearch中相交数组元素的数量正确增强此类术语查询?
Alk*_*ris -1
我已经尝试过以下内容并且它按预期工作。分数不一样
PUT my_index/my_type/1
{
"ids": ["id1", "id2", "id3"]
}
PUT my_index/my_type/2
{
"ids": ["id1"]
}
GET my_index/_search
{
"query": {
"bool": {
"must": {
"terms": {
"ids": [
"id1",
"id2",
"id3"
],
"boost": 10
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 7.594807,
"hits": [
{
"_index": "my_index",
"_type": "my_type",
"_id": "1",
"_score": 7.594807,
"_source": {
"ids": [
"id1",
"id2",
"id3"
]
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "2",
"_score": 2.8768208,
"_source": {
"ids": [
"id1"
]
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
697 次 |
| 最近记录: |