Elasticsearch:“条款”,“匹配词组”和“查询字符串”之间的区别 [英] Elasticsearch: Difference between "Term", "Match Phrase", and "Query String"
问题描述
Elasticsearch的新功能,试图更好地了解这些查询之间的区别。据我所知, term
匹配单个术语(匹配是否需要小写?)和两个 match短语
和查询字符串
匹配文本字符串。
New here to Elasticsearch and trying to get a better understanding on the difference between these queries. As far as I can tell, term
matches a single term (needs to be lowercase for the match to work?), and both match phrase
and query string
matches a string of text.
推荐答案
term
查询按原样匹配单个术语:未分析。
因此,不必根据所索引的内容将其小写。
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
例如,如果您索引以下文档(使用<$ c $字段 foo
的c> standard 分析器:
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" }
T他的 match_phrase
查询将只返回第一个和第二个文档:
This match_phrase
query will only return the first and second documents :
{
"query": {
"match_phrase": {
"foo": "Hello World"
}
}
}
query_string
默认情况下,在 _ 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.
这篇关于Elasticsearch:“条款”,“匹配词组”和“查询字符串”之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!