ElasticSearch 部分词组匹配
ElasticSearch partial phrase matching
我是 ElasticNoob,但我一直在玩一些简单的短语匹配,如下所示:
query: {
match_phrase: {
my_field: {
query: "silly dogs playing about",
slop: 100
}
}
}
但这只匹配具有 所有 4 个术语(silly、dogs、playing、about)的条目。理想情况下,它仍然会匹配 "silly dogs that are playing" 之类没有 "about" 关键字的内容(因此它会得到较低的分数)。
这似乎是文本搜索引擎的一个非常常见的用例,所以我认为我的 Google-fu 一定很弱,因为我找不到关于 partial[=33= 的任何信息] 弹性搜索中的词组匹配。
有人能给我指出正确的方向吗?明确一点:
- 关键字的顺序很重要(
match_phrase
和slop
允许我们这样做)
- number 个关键字匹配很重要(如果 any 个关键字丢失,
match_phrase
简单地排除项目 - 这并不理想对于我的情况)
谢谢!
推荐的解决方案是:
Instead of using proximity matching as an absolute requirement, we can
use it as a signal—as one of potentially many queries, each of which
contributes to the overall score for each document (see Most Fields).
这里有描述它的文章:https://www.elastic.co/guide/en/elasticsearch/guide/current/proximity-relevance.html
所以您的查询看起来像:
query: {
bool: {
must: {
match: {
my_field: {
query: "silly dogs playing about",
minimum_should_match: "30%"
}
}
},
should: {
match_phrase: {
my_field: {
query: "silly dogs playing about",
slop: 50
}
}
}
}
}
您可以使用变量调用 minimum_should_match 来指定需要匹配的单词的百分比或指定应匹配的单词数。
query: {
match_phrase: {
my_field: {
query: "silly dogs playing about",
slop: 100,
minimum_should_match: "75%"
}
}
}
这意味着 4 个词中至少有 3 个词需要匹配才能成为热门词。
我是 ElasticNoob,但我一直在玩一些简单的短语匹配,如下所示:
query: {
match_phrase: {
my_field: {
query: "silly dogs playing about",
slop: 100
}
}
}
但这只匹配具有 所有 4 个术语(silly、dogs、playing、about)的条目。理想情况下,它仍然会匹配 "silly dogs that are playing" 之类没有 "about" 关键字的内容(因此它会得到较低的分数)。
这似乎是文本搜索引擎的一个非常常见的用例,所以我认为我的 Google-fu 一定很弱,因为我找不到关于 partial[=33= 的任何信息] 弹性搜索中的词组匹配。
有人能给我指出正确的方向吗?明确一点:
- 关键字的顺序很重要(
match_phrase
和slop
允许我们这样做) - number 个关键字匹配很重要(如果 any 个关键字丢失,
match_phrase
简单地排除项目 - 这并不理想对于我的情况)
谢谢!
推荐的解决方案是:
Instead of using proximity matching as an absolute requirement, we can use it as a signal—as one of potentially many queries, each of which contributes to the overall score for each document (see Most Fields).
这里有描述它的文章:https://www.elastic.co/guide/en/elasticsearch/guide/current/proximity-relevance.html
所以您的查询看起来像:
query: {
bool: {
must: {
match: {
my_field: {
query: "silly dogs playing about",
minimum_should_match: "30%"
}
}
},
should: {
match_phrase: {
my_field: {
query: "silly dogs playing about",
slop: 50
}
}
}
}
}
您可以使用变量调用 minimum_should_match 来指定需要匹配的单词的百分比或指定应匹配的单词数。
query: {
match_phrase: {
my_field: {
query: "silly dogs playing about",
slop: 100,
minimum_should_match: "75%"
}
}
}
这意味着 4 个词中至少有 3 个词需要匹配才能成为热门词。