analyzer
Только поля типа text поддерживают параметр отображения analyzer.
Параметр analyzer указывает анализатор, используемый для анализа текста при индексировании или поиске поля text.
Если этот анализатор не переопределён параметром отображения search_analyzer, он используется как для анализа при индексировании, так и при поиске. См. Укажите анализатор.
Рекомендуется тестировать анализаторы перед использованием их в рабочей среде. См. Тестирование анализатора.
Параметр analyzer не может быть обновлён для существующих полей с помощью API обновления отображения update mapping API.
search_quote_analyzer
Параметр search_quote_analyzer позволяет указать анализатор для фраз, что особенно полезно при отключении стоп-слов для фраз в запросах.
Для отключения стоп-слов для фраз необходимо использовать три параметра анализатора:
- Параметр
analyzerдля индексирования всех терминов, включая стоп-слова - Параметр
search_analyzerдля запросов, не являющихся запросами по фразам, который удаляет стоп-слова - Параметр
search_quote_analyzerдля запросов по фразам, который не удаляет стоп-слова
resp = client.indices.create(
index="my-index-000001",
settings={
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase"
]
},
"my_stop_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"english_stop"
]
}
},
"filter": {
"english_stop": {
"type": "stop",
"stopwords": "_english_"
}
}
}
},
mappings={
"properties": {
"title": {
"type": "text",
"analyzer": "my_analyzer",
"search_analyzer": "my_stop_analyzer",
"search_quote_analyzer": "my_analyzer"
}
}
},
)
print(resp)
resp1 = client.index(
index="my-index-000001",
id="1",
document={
"title": "The Quick Brown Fox"
},
)
print(resp1)
resp2 = client.index(
index="my-index-000001",
id="2",
document={
"title": "A Quick Brown Fox"
},
)
print(resp2)
resp3 = client.search(
index="my-index-000001",
query={
"query_string": {
"query": "\"the quick brown fox\""
}
},
)
print(resp3) response = client.indices.create(
index: 'my-index-000001',
body: {
settings: {
analysis: {
analyzer: {
my_analyzer: {
type: 'custom',
tokenizer: 'standard',
filter: [
'lowercase'
]
},
my_stop_analyzer: {
type: 'custom',
tokenizer: 'standard',
filter: [
'lowercase',
'english_stop'
]
}
},
filter: {
english_stop: {
type: 'stop',
stopwords: '_english_'
}
}
}
},
mappings: {
properties: {
title: {
type: 'text',
analyzer: 'my_analyzer',
search_analyzer: 'my_stop_analyzer',
search_quote_analyzer: 'my_analyzer'
}
}
}
}
)
puts response
response = client.index(
index: 'my-index-000001',
id: 1,
body: {
title: 'The Quick Brown Fox'
}
)
puts response
response = client.index(
index: 'my-index-000001',
id: 2,
body: {
title: 'A Quick Brown Fox'
}
)
puts response
response = client.search(
index: 'my-index-000001',
body: {
query: {
query_string: {
query: '"the quick brown fox"'
}
}
}
)
puts response const response = await client.indices.create({
index: "my-index-000001",
settings: {
analysis: {
analyzer: {
my_analyzer: {
type: "custom",
tokenizer: "standard",
filter: ["lowercase"],
},
my_stop_analyzer: {
type: "custom",
tokenizer: "standard",
filter: ["lowercase", "english_stop"],
},
},
filter: {
english_stop: {
type: "stop",
stopwords: "_english_",
},
},
},
},
mappings: {
properties: {
title: {
type: "text",
analyzer: "my_analyzer",
search_analyzer: "my_stop_analyzer",
search_quote_analyzer: "my_analyzer",
},
},
},
});
console.log(response);
const response1 = await client.index({
index: "my-index-000001",
id: 1,
document: {
title: "The Quick Brown Fox",
},
});
console.log(response1);
const response2 = await client.index({
index: "my-index-000001",
id: 2,
document: {
title: "A Quick Brown Fox",
},
});
console.log(response2);
const response3 = await client.search({
index: "my-index-000001",
query: {
query_string: {
query: '"the quick brown fox"',
},
},
});
console.log(response3); PUT my-index-000001
{
"settings":{
"analysis":{
"analyzer":{
"my_analyzer":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase"
]
},
"my_stop_analyzer":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase",
"english_stop"
]
}
},
"filter":{
"english_stop":{
"type":"stop",
"stopwords":"_english_"
}
}
}
},
"mappings":{
"properties":{
"title": {
"type":"text",
"analyzer":"my_analyzer",
"search_analyzer":"my_stop_analyzer",
"search_quote_analyzer":"my_analyzer"
}
}
}
}
PUT my-index-000001/_doc/1
{
"title":"The Quick Brown Fox"
}
PUT my-index-000001/_doc/2
{
"title":"A Quick Brown Fox"
}
GET my-index-000001/_search
{
"query":{
"query_string":{
"query":"\"the quick brown fox\""
}
}
} Параметр search_quote_analyzer может быть обновлён для существующих полей с помощью API обновления отображения update mapping API.
| Анализатор | |
| Анализатор | |
| Параметр | |
| Параметр | |
| Параметр | |
| Так как запрос заключён в кавычки, он распознаётся как запрос по фразе, поэтому срабатывает параметр |
© 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/analyzer.html