Запрос match phrase
Запрос match_phrase анализирует текст и создает запрос phrase из проанализированного текста. Например:
resp = client.search(
query={
"match_phrase": {
"message": "this is a test"
}
},
)
print(resp) response = client.search(
body: {
query: {
match_phrase: {
message: 'this is a test'
}
}
}
)
puts response res, err := es.Search(
es.Search.WithBody(strings.NewReader(`{
"query": {
"match_phrase": {
"message": "this is a test"
}
}
}`)),
es.Search.WithPretty(),
)
fmt.Println(res, err) const response = await client.search({
query: {
match_phrase: {
message: "this is a test",
},
},
});
console.log(response); GET /_search
{
"query": {
"match_phrase": {
"message": "this is a test"
}
}
} Параметры для <field>
-
query -
(Обязательно) Текст, число, булево значение или дата, которые вы хотите найти в предоставленном
<field>. -
analyzer - (Необязательно, строка) Анализатор, используемый для преобразования текста в значении
queryв токены. По умолчанию используется анализатор индексации, сопоставленный для<field>. Если анализатор не сопоставлен, используется анализатор по умолчанию индекса. -
slop - (Необязательно, целое число) Максимальное количество позиций, разрешенных между сопоставленными токенами. По умолчанию
0. Для переставленных терминов значение2. -
zero_terms_query -
(Необязательно, строка) Указывает, возвращаются ли какие-либо документы, если
analyzerудаляет все токены, например, при использовании фильтраstop. Допустимые значения:-
none(По умолчанию) - Если
analyzerудаляет все токены, то документы не возвращаются. -
all - Возвращает все документы, аналогично запросу
match_all.
-
Запрос phrase сопоставляет термины в пределах настраиваемого slop (по умолчанию 0) в любом порядке. Переставленные термины имеют разницу в позициях (slop) 2.
Анализатор в запросе match phrase
Анализатор можно настроить, чтобы управлять процессом анализа текста. По умолчанию используется явное сопоставление поля или анализатор по умолчанию для поиска, например:
resp = client.search(
query={
"match_phrase": {
"message": {
"query": "this is a test",
"analyzer": "my_analyzer"
}
}
},
)
print(resp) response = client.search(
body: {
query: {
match_phrase: {
message: {
query: 'this is a test',
analyzer: 'my_analyzer'
}
}
}
}
)
puts response res, err := es.Search(
es.Search.WithBody(strings.NewReader(`{
"query": {
"match_phrase": {
"message": {
"query": "this is a test",
"analyzer": "my_analyzer"
}
}
}
}`)),
es.Search.WithPretty(),
)
fmt.Println(res, err) const response = await client.search({
query: {
match_phrase: {
message: {
query: "this is a test",
analyzer: "my_analyzer",
},
},
},
});
console.log(response); GET /_search
{
"query": {
"match_phrase": {
"message": {
"query": "this is a test",
"analyzer": "my_analyzer"
}
}
}
}
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/query-dsl-match-query-phrase.html
|
|