弹性搜索:“术语”,“匹配短语”和“查询字符串”之间的区别 [英] Elastic Search: Difference between "Term", "Match Phrase", and "Query String"

查看:136
本文介绍了弹性搜索:“术语”,“匹配短语”和“查询字符串”之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里新增弹性搜索,并尝试更好地了解这些查询之间的区别。据我所知,术语匹配单个术语(需要小写匹配才能工作),而匹配短语查询字符串匹配一串文本。

New here to elastic search and trying to get a better understanding on the difference between these queries. As far as I can tell, term matchings a single term (needs to be lowercase for the match to work?), and both match phrase and query string matches a string of text.

推荐答案

p> 术语查询符合单个术语:该值为未分析
所以,根据你所索引的内容,它不一定要更低。

term query matches a single term as it is : the value is not analyzed. So, it doesn't have to be lowercased depending on what you have indexed.

如果你提供了 Bennett 在索引时间,值不分析,以下查询不会返回任何内容:

If you provided Bennett at index time and the value is not analyzed, the following query won't return anything :

{
  "query": {
    "term" : { "user" : "bennett" }
  }
}

match_phrase 查询将分析输入,如果为查询字段定义分析器,并查找符合以下标准的文档:

match_phrase query will analyze the input if analyzers are defined for the queried field and find documents matching the following criterias :


  • 所有条款必须出现在字段

  • 中,他们必须具有相同的订单作为输入值

  • all the terms must appear in the field
  • they must have the same order as the input value

例如,如果您索引以下文档(使用标准分析器的字段 foo ):

For example, if you index the following documents (using standard analyzer for the field foo):

{ "foo":"I just said hello world" }

{ "foo":"Hello world" }

{ "foo":"World Hello" }

这个 match_phrase 查询只会返回第一个和第二个文档:

This match_phrase query will only return the first and second documents :

{
  "query": {
    "match_phrase": {
      "foo": "Hello World"
    }
  }
}

query_string 查询搜索,默认情况下,一个href =http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-all-field.html#mapping-all-field =noreferrer> _ all 字段它同时包含几个文本字段的文本。除此之外,它已被解析并支持一些运算符(AND / OR ...),通配符等(参见相关语法)。

query_string query search, by default, on a _all field which contains the text of several text fields at once. On top of that, it's parsed and supports some operators (AND/OR...), wildcards and so on (see related syntax).

作为 match_phrase 查询,根据查询字段上设置的分析器对输入进行分析。

As the match_phrase queries, the input is analyzed according to the analyzer set on the queried field.

match_phrase 不同,分析后获得的条款不必是相同的顺序,除非用户在输入周围使用引号。

Unlike the match_phrase, the terms obtained after analysis don't have to be in the same order, unless the user has used quotes around the input.

例如,使用与以前相同的文档,此查询将返回所有文档:

For example, using the same documents as before, this query will return all the documents :

{
  "query": {
    "query_string": {
      "query": "hello World"
    }
  }
}

但是这个查询将返回相同的2个文档 match_phrase 查询:

But this query will return the same 2 documents as the match_phrase query :

{
  "query": {
    "query_string": {
      "query": "\"Hello World\""
    }
  }
}

有更多关于这些查询的不同选项,请查看相关文档:

There is much more to say about the different options for those queries, please take a look at the related documentation :

  • term
  • match_phrase
  • query_string

希望这很清楚,这将有所帮助。

Hope this is clear enough and it will help.

这篇关于弹性搜索:“术语”,“匹配短语”和“查询字符串”之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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