elasticsearch - elasticsearch 中的 query_string 与组匹配

标签 elasticsearch

这样的查询有什么区别:

"query": {
"bool": {
 ...
  "should": [
    {
      "match": {
        "description": {
          "query": "test"              
        }
      }
    },
    {
      "match": {
        "address": {
          "query": "test",              
        }
      }
    },
    {
      "match": {
        "country": {
          "query": "test"              
        }
      }
    },
    {
      "match": {
        "city": {
          "query": "test"
        }
      }
    }        
  ]
}}

还有那个:

"query": {
"bool": {
 ...      
  "should": [        
    {
      "query_string": {
        "query": "test",
        "fields": [
          "description",
          "address",
          "country",
          "city"              
        ]
      }
    }
  ]
}}

性能、相关性?

提前致谢!

最佳答案

查询是根据字段分析器进行分析的(除非您在查询本身中指定分析器),因此使用单个查询查询多个字段并不一定意味着只分析一次查询。

请记住,query_string 支持 lucene query syntax : AND 和 OR 运算符,查询特定字段,通配符,短语查询等因此需要对其进行解析,我认为这在性能方面不会有太大差异,但它容易出错并可能导致错误。如果您不需要所有这些功能,请坚持使用匹配查询,如果您想对多个字段执行相同的查询,请查看 multi_match query ,它执行您对 query_string 所做的操作,但在内部转换为多个匹配查询。

此外,如果您比较多个匹配查询的输出和您的 query_string 返回的分数可能会完全不同。使用 bool 查询可以有效地构建一个 lucene bool 查询,而 query_string 默认使用 "use_dis_max":"true",这意味着它在内部使用 dis_max query默认情况下。使用 multi_match 查询也会发生同样的情况。如果将 use_dis_max 设置为 false,则将在内部使用 bool 查询。

关于elasticsearch - elasticsearch 中的 query_string 与组匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19937680/

相关文章:

elasticsearch - 如何仅在Elasticsearch中的嵌套对象数组中搜索最近插入的对象(通过日期字段知道)

arrays - 在 Elasticsearch 中聚合值数组

json - Elasticsearch查询检索所有ID的特定类型的特定_source值

python-3.x - 无法在 Elasticsearch 中搜索带有符号的查询

elasticsearch - 是否可以通过过滤器在Elastic Search中添加数据?

python - django-haystack 自动完成功能无法正常工作

elasticsearch - 安装 Elasticsearch 7 时出错 - 依赖项失败

elasticsearch - Elasticsearch:没有任期时会积极插入

elasticsearch - 通过gradle运行弹性后如何停止弹性?

elasticsearch - 如何在elasticsearch中对时间戳进行减法运算?