从 1.7 移动到 5.4 时,Elasticsearch 查询结果不同
Elasticsearch query results different when moving from 1.7 to 5.4
我正在将一个 Elasticsearch 实例从 1.7 升级到 5.4.3,我注意到两个系统的搜索结果不同,即使使用相同的查询也是如此。
Elasticsearch 1.7 查询
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "something",
"fields": [
"field1",
"field2",
"field3"
],
"operator": "and"
}
}
}
}
}
Elasticsearch 5.4 查询
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "something",
"fields": [
"field1",
"field2",
"field3"
],
"operator": "and"
}
}
]
}
}
}
Elasticsearch 1.7 中的第 1 个搜索结果成为 Elasticsearch 5.4 中的第 71 个结果。当我使用 _explain
端点查看 1.7 和 5.4 之间的相同搜索结果时,我发现评分的方式不同。此外,此查询包含搜索查询匹配的同义词。
解释 Elasticsearch 1.7
{
"_index": "...",
"_type": "...",
"_id": "...",
"matched": true,
"explanation": {
"value": 9.963562,
"description": "max of:",
"details": [
{
"value": 3.1413355,
"description": "sum of:",
"details": [
{
"value": 1.0609967,
"description": "weight(field1:something in 13) [PerFieldSimilarity], result of:",
"details": [
...remainder removed for brevity
针对 Elasticsearch 5.4 的解释
{
"_index": "...",
"_type": "...",
"_id": "...",
"matched": true,
"explanation": {
"value": 7.1987557,
"description": "sum of:",
"details": [
{
"value": 7.1987557,
"description": "max of:",
"details": [
{
"value": 6.659632,
"description": "weight(Synonym(field1:something field1:something2 field1:something3) in 113) [PerFieldSimilarity], result of:",
"details": [
...remainder removed for brevity
问题
- 为什么我的搜索结果对于两个版本中的等效查询如此不同有什么明显的原因吗?
- Elasticsearch 1.7 的
_explain
查询是否显示 max of
高于 sum of
的计算结果, 相反 对于Elasticsearch 5.4,指出部分问题?
Elasticsearch 5.0 中的默认 "similarity" 已从 TF/IDF 更改为 BM25
从技术上讲,这实际上是迁移到 Lucene 6.2(Elasticsearch 5.0.0 的默认设置)时的一个更改。
Elasticsearch 5.0.0 Release Notes 包括以下行:
您可以阅读有关 Elasticsearch similarity here 的更多信息。这就是两个字段相互比较的方式(尤其是具有 "text" 映射的字段)。在5.0.0之前,默认的相似度是TF/IDF(term frequency, inverse document frequency),后来改为BM25(Best Match 25)。此更改将导致一组不同的结果,旨在成为一组更好的搜索结果。
如果你想使用以前的行为你可以改变映射文件中的similarity
以使用classic
(指的是TF/IDF).例如,您的 YAML 映射文件可能包含:
description:
type: text
similarity: classic
包含更多信息的有用链接:
我正在将一个 Elasticsearch 实例从 1.7 升级到 5.4.3,我注意到两个系统的搜索结果不同,即使使用相同的查询也是如此。
Elasticsearch 1.7 查询
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "something",
"fields": [
"field1",
"field2",
"field3"
],
"operator": "and"
}
}
}
}
}
Elasticsearch 5.4 查询
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "something",
"fields": [
"field1",
"field2",
"field3"
],
"operator": "and"
}
}
]
}
}
}
Elasticsearch 1.7 中的第 1 个搜索结果成为 Elasticsearch 5.4 中的第 71 个结果。当我使用 _explain
端点查看 1.7 和 5.4 之间的相同搜索结果时,我发现评分的方式不同。此外,此查询包含搜索查询匹配的同义词。
解释 Elasticsearch 1.7
{
"_index": "...",
"_type": "...",
"_id": "...",
"matched": true,
"explanation": {
"value": 9.963562,
"description": "max of:",
"details": [
{
"value": 3.1413355,
"description": "sum of:",
"details": [
{
"value": 1.0609967,
"description": "weight(field1:something in 13) [PerFieldSimilarity], result of:",
"details": [
...remainder removed for brevity
针对 Elasticsearch 5.4 的解释
{
"_index": "...",
"_type": "...",
"_id": "...",
"matched": true,
"explanation": {
"value": 7.1987557,
"description": "sum of:",
"details": [
{
"value": 7.1987557,
"description": "max of:",
"details": [
{
"value": 6.659632,
"description": "weight(Synonym(field1:something field1:something2 field1:something3) in 113) [PerFieldSimilarity], result of:",
"details": [
...remainder removed for brevity
问题
- 为什么我的搜索结果对于两个版本中的等效查询如此不同有什么明显的原因吗?
- Elasticsearch 1.7 的
_explain
查询是否显示max of
高于sum of
的计算结果, 相反 对于Elasticsearch 5.4,指出部分问题?
Elasticsearch 5.0 中的默认 "similarity" 已从 TF/IDF 更改为 BM25
从技术上讲,这实际上是迁移到 Lucene 6.2(Elasticsearch 5.0.0 的默认设置)时的一个更改。
Elasticsearch 5.0.0 Release Notes 包括以下行:
您可以阅读有关 Elasticsearch similarity here 的更多信息。这就是两个字段相互比较的方式(尤其是具有 "text" 映射的字段)。在5.0.0之前,默认的相似度是TF/IDF(term frequency, inverse document frequency),后来改为BM25(Best Match 25)。此更改将导致一组不同的结果,旨在成为一组更好的搜索结果。
如果你想使用以前的行为你可以改变映射文件中的similarity
以使用classic
(指的是TF/IDF).例如,您的 YAML 映射文件可能包含:
description:
type: text
similarity: classic
包含更多信息的有用链接: