Elasticsearch-从6.7升级到7.0后,此搜索未返回正确的结果 [英] Elasticsearch - This search doesn't return the correct results after upgrading from 6.7 to 7.0

查看:69
本文介绍了Elasticsearch-从6.7升级到7.0后,此搜索未返回正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{  
  "query":{  
    "constant_score":{  
      "filter":{  
        "bool":{  
          "should":{  
            "terms":{  
              "field_a":[  
                "value1", "value2"
              ]
            }
          },
          "must":{  
            "term":{  
              "field_b":"value"
            }
          }
        }
      }
    }
  }
}

该搜索应该返回在field_a中包含value1或value2并在field_b中包含value的结果.

This search was supposed to return the results containing value1 or value2 in field_a and value in field_b.

类似于此MySQL查询:

So similar to this MySQL query:

SELECT * FROM table WHERE field_a IN ('value1', 'value2') AND field_b = value

升级后,它将返回所有结果,其中field_b =值.查询的第一部分被完全忽略.
有修复建议吗?

After the upgrade it will return all the results where field_b = value. The first part of the query is completely ignored.
Any suggestions for a fix?

推荐答案

您正在遇到

You are running into this breaking change. minimum_should_match is no longer being set to 1. To correct this, explicitly set your minimum_should_match to 1

您的新查询可以这样解决:

Your new query could be fixed like this:

{  
  "query":{  
    "constant_score":{  
      "filter":{  
        "bool":{  
          "should":{  
            "terms":{  
              "field_a":[  
                "value1", "value2"
              ]
            }
          },
          "minimum_should_match": 1,
          "must":{  
            "term":{  
              "field_b":"value"
            }
          }
        }
      }
    }
  }
}

这篇关于Elasticsearch-从6.7升级到7.0后,此搜索未返回正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆