如何提升个人文件
How to boost individual documents
我有一个非常复杂的查询,现在我想提升一些满足某些条件的文档。我有以下简化的文档结构,我尝试根据 id、流派、标签来提升一些文档。
{
"id": 123,
"genres": ["ACTION", "DRAMA"],
"tags": ["For kids", "Romantic", "Nature"]
}
我想做的就是举例
id: 123 boost: 5
genres: ACTION boost: 3
tags: Romantic boost: 0.2
并提升我的查询中包含的所有文档并符合条件,但我不想将它们过滤掉。所以我猜查询子句提升没有任何帮助。
编辑:让我更容易理解我想要实现的目标(不确定 elasticsearch 是否可行,否也是一个有效的答案)。
我想使用查询进行搜索并获得结果集。在这个集合中,我想增加一些文档。但我不想扩大结果集或过滤它。提升应该独立于查询。
例如,我搜索一个特定的标签,并希望提升结果集中类别为 'ACTION' 的所有文档。但是我不想要结果集中所有类别为 'ACTION' 的文档,而且我不想要只具有特定标签和类别 'ACTION'.
的文档
我认为您需要在查询期间进行动态提升。
第一个匹配 id title with boost,第二个匹配 'genders' ACTION。
{
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "id",
"boost": 5
}
}
},
{
"match": {
"content": "Action"
}
}
]
}
}
}
如果您想 multi_match
根据您的查询进行匹配:
{
"multi_match" : {
"query": "some query terms here",
"fields": [ "id^5", "genders^3", "tags^0.2" ]
}
}
注意:^5 表示对标题的提升。
编辑:
也许您正在从 ES 参考指南中询问不同类型的 multi_match 查询(至少对于 ES 5.x):
best_fields
(default) Finds documents which match any field, but uses
the _score from the best field. See best_fields.
most_fields
Finds documents which match any field and combines the _score from
each field. See most_fields.
cross_fields
Treats fields with the same analyzer as though they were one big
field. Looks for each word in any field. See cross_fields.
短语
Runs a match_phrase query on each field and combines the _score from
each field. See phrase and phrase_prefix.
phrase_prefix
Runs a match_phrase_prefix query on each field and combines the _score
from each field. See phrase and phrase_prefix.
我找到了一个解决方案,它非常简单。我使用增强查询。我现在只是嵌套了不同的提升标准,我的原始查询现在是基本查询。
https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-boosting-query.html
例如:
{
"query": {
"boosting": {
"positive": {
"boosting": {
"positive": {
"match": {
"director": "Spielberg"
}
},
"negative": {
"term": {
"genres": "DRAMA"
}
},
"negative_boost": 1.3
}
},
"negative": {
"term": {
"tags": "Romantic"
}
},
"negative_boost": 1.2
}
}
}
我有一个非常复杂的查询,现在我想提升一些满足某些条件的文档。我有以下简化的文档结构,我尝试根据 id、流派、标签来提升一些文档。
{
"id": 123,
"genres": ["ACTION", "DRAMA"],
"tags": ["For kids", "Romantic", "Nature"]
}
我想做的就是举例
id: 123 boost: 5
genres: ACTION boost: 3
tags: Romantic boost: 0.2
并提升我的查询中包含的所有文档并符合条件,但我不想将它们过滤掉。所以我猜查询子句提升没有任何帮助。
编辑:让我更容易理解我想要实现的目标(不确定 elasticsearch 是否可行,否也是一个有效的答案)。
我想使用查询进行搜索并获得结果集。在这个集合中,我想增加一些文档。但我不想扩大结果集或过滤它。提升应该独立于查询。
例如,我搜索一个特定的标签,并希望提升结果集中类别为 'ACTION' 的所有文档。但是我不想要结果集中所有类别为 'ACTION' 的文档,而且我不想要只具有特定标签和类别 'ACTION'.
的文档我认为您需要在查询期间进行动态提升。
第一个匹配 id title with boost,第二个匹配 'genders' ACTION。
{
"query": {
"bool": {
"should": [
{
"match": {
"title": {
"query": "id",
"boost": 5
}
}
},
{
"match": {
"content": "Action"
}
}
]
}
}
}
如果您想 multi_match
根据您的查询进行匹配:
{
"multi_match" : {
"query": "some query terms here",
"fields": [ "id^5", "genders^3", "tags^0.2" ]
}
}
注意:^5 表示对标题的提升。
编辑: 也许您正在从 ES 参考指南中询问不同类型的 multi_match 查询(至少对于 ES 5.x):
best_fields
(default) Finds documents which match any field, but uses the _score from the best field. See best_fields.
most_fields
Finds documents which match any field and combines the _score from each field. See most_fields.
cross_fields
Treats fields with the same analyzer as though they were one big field. Looks for each word in any field. See cross_fields.
短语
Runs a match_phrase query on each field and combines the _score from each field. See phrase and phrase_prefix.
phrase_prefix
Runs a match_phrase_prefix query on each field and combines the _score from each field. See phrase and phrase_prefix.
我找到了一个解决方案,它非常简单。我使用增强查询。我现在只是嵌套了不同的提升标准,我的原始查询现在是基本查询。
https://www.elastic.co/guide/en/elasticsearch/reference/2.3/query-dsl-boosting-query.html
例如:
{
"query": {
"boosting": {
"positive": {
"boosting": {
"positive": {
"match": {
"director": "Spielberg"
}
},
"negative": {
"term": {
"genres": "DRAMA"
}
},
"negative_boost": 1.3
}
},
"negative": {
"term": {
"tags": "Romantic"
}
},
"negative_boost": 1.2
}
}
}