Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Анализ текста ›Настройка анализа текста

Настройка встроенных анализаторов

Встроенные анализаторы можно использовать напрямую без какой-либо настройки. Однако некоторые из них поддерживают параметры настройки для изменения их поведения. Например, анализатор standard можно настроить для поддержки списка стоп-слов:

resp = client.indices.create(
    index="my-index-000001",
    settings={
        "analysis": {
            "analyzer": {
                "std_english": {
                    "type": "standard",
                    "stopwords": "_english_"
                }
            }
        }
    },
    mappings={
        "properties": {
            "my_text": {
                "type": "text",
                "analyzer": "standard",
                "fields": {
                    "english": {
                        "type": "text",
                        "analyzer": "std_english"
                    }
                }
            }
        }
    },
)
print(resp)

resp1 = client.indices.analyze(
    index="my-index-000001",
    field="my_text",
    text="The old brown cow",
)
print(resp1)

resp2 = client.indices.analyze(
    index="my-index-000001",
    field="my_text.english",
    text="The old brown cow",
)
print(resp2)
response = client.indices.create(
  index: 'my-index-000001',
  body: {
    settings: {
      analysis: {
        analyzer: {
          std_english: {
            type: 'standard',
            stopwords: '_english_'
          }
        }
      }
    },
    mappings: {
      properties: {
        my_text: {
          type: 'text',
          analyzer: 'standard',
          fields: {
            english: {
              type: 'text',
              analyzer: 'std_english'
            }
          }
        }
      }
    }
  }
)
puts response

response = client.indices.analyze(
  index: 'my-index-000001',
  body: {
    field: 'my_text',
    text: 'The old brown cow'
  }
)
puts response

response = client.indices.analyze(
  index: 'my-index-000001',
  body: {
    field: 'my_text.english',
    text: 'The old brown cow'
  }
)
puts response
const response = await client.indices.create({
  index: "my-index-000001",
  settings: {
    analysis: {
      analyzer: {
        std_english: {
          type: "standard",
          stopwords: "_english_",
        },
      },
    },
  },
  mappings: {
    properties: {
      my_text: {
        type: "text",
        analyzer: "standard",
        fields: {
          english: {
            type: "text",
            analyzer: "std_english",
          },
        },
      },
    },
  },
});
console.log(response);

const response1 = await client.indices.analyze({
  index: "my-index-000001",
  field: "my_text",
  text: "The old brown cow",
});
console.log(response1);

const response2 = await client.indices.analyze({
  index: "my-index-000001",
  field: "my_text.english",
  text: "The old brown cow",
});
console.log(response2);
PUT my-index-000001
{
  "settings": {
    "analysis": {
      "analyzer": {
        "std_english": { 
          "type":      "standard",
          "stopwords": "_english_"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "my_text": {
        "type":     "text",
        "analyzer": "standard", 
        "fields": {
          "english": {
            "type":     "text",
            "analyzer": "std_english" 
          }
        }
      }
    }
  }
}

POST my-index-000001/_analyze
{
  "field": "my_text", 
  "text": "The old brown cow"
}

POST my-index-000001/_analyze
{
  "field": "my_text.english", 
  "text": "The old brown cow"
}

Мы определяем анализатор std_english, основанный на анализаторе standard, но настроенный на удаление предварительно определённого списка английских стоп-слов.

Поле my_text использует анализатор standard напрямую без какой-либо настройки. Из этого поля не будут удалены стоп-слова. Результирующие термины: [ the, old, brown, cow ]

Поле my_text.english использует анализатор std_english, поэтому английские стоп-слова будут удалены. Результирующие термины: [ old, brown, cow ]

© 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/configuring-analyzers.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API