Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Анализ текста ›Справочник встроенных анализаторов

Анализатор Stop

Анализатор stop идентичен анализатору simple, но добавляет поддержку удаления стоп-слов. По умолчанию используются стоп-слова из списка _english_.

Пример вывода

resp = client.indices.analyze(
    analyzer="stop",
    text="The 2 QUICK Brown-Foxes jumped over the lazy dog's bone.",
)
print(resp)
response = client.indices.analyze(
  body: {
    analyzer: 'stop',
    text: "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  }
)
puts response
const response = await client.indices.analyze({
  analyzer: "stop",
  text: "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone.",
});
console.log(response);
POST _analyze
{
  "analyzer": "stop",
  "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
}

Предложение выше даст следующие термины:

[ quick, brown, foxes, jumped, over, lazy, dog, s, bone ]

Настройка

Анализатор stop принимает следующие параметры:

stopwords

Предопределенный список стоп-слов, например, _english_, или массив, содержащий список стоп-слов. По умолчанию используется _english_.

stopwords_path

Путь к файлу, содержащему стоп-слова. Путь относительный к каталогу Elasticsearch config.

Подробнее о настройке стоп-слов см. в разделе Фильтр токенов Stop.

Пример конфигурации

В этом примере мы настраиваем анализатор stop для использования указанного списка слов в качестве стоп-слов:

resp = client.indices.create(
    index="my-index-000001",
    settings={
        "analysis": {
            "analyzer": {
                "my_stop_analyzer": {
                    "type": "stop",
                    "stopwords": [
                        "the",
                        "over"
                    ]
                }
            }
        }
    },
)
print(resp)

resp1 = client.indices.analyze(
    index="my-index-000001",
    analyzer="my_stop_analyzer",
    text="The 2 QUICK Brown-Foxes jumped over the lazy dog's bone.",
)
print(resp1)
response = client.indices.create(
  index: 'my-index-000001',
  body: {
    settings: {
      analysis: {
        analyzer: {
          my_stop_analyzer: {
            type: 'stop',
            stopwords: [
              'the',
              'over'
            ]
          }
        }
      }
    }
  }
)
puts response

response = client.indices.analyze(
  index: 'my-index-000001',
  body: {
    analyzer: 'my_stop_analyzer',
    text: "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
  }
)
puts response
const response = await client.indices.create({
  index: "my-index-000001",
  settings: {
    analysis: {
      analyzer: {
        my_stop_analyzer: {
          type: "stop",
          stopwords: ["the", "over"],
        },
      },
    },
  },
});
console.log(response);

const response1 = await client.indices.analyze({
  index: "my-index-000001",
  analyzer: "my_stop_analyzer",
  text: "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone.",
});
console.log(response1);
PUT my-index-000001
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_stop_analyzer": {
          "type": "stop",
          "stopwords": ["the", "over"]
        }
      }
    }
  }
}

POST my-index-000001/_analyze
{
  "analyzer": "my_stop_analyzer",
  "text": "The 2 QUICK Brown-Foxes jumped over the lazy dog's bone."
}

В этом примере будут получены следующие термины:

[ quick, brown, foxes, jumped, lazy, dog, s, bone ]

Определение

Он состоит из:

Токенизатор
  • Токенизатор Lower Case
Фильтры токенов
  • Фильтр токенов Stop

Если вам нужно настроить анализатор stop дальше, чем параметры конфигурации, то нужно создать его как анализатор custom и изменить его, обычно добавив фильтры токенов. Это позволит воссоздать встроенный анализатор stop и использовать его в качестве отправной точки для дальнейшей настройки:

resp = client.indices.create(
    index="stop_example",
    settings={
        "analysis": {
            "filter": {
                "english_stop": {
                    "type": "stop",
                    "stopwords": "_english_"
                }
            },
            "analyzer": {
                "rebuilt_stop": {
                    "tokenizer": "lowercase",
                    "filter": [
                        "english_stop"
                    ]
                }
            }
        }
    },
)
print(resp)
response = client.indices.create(
  index: 'stop_example',
  body: {
    settings: {
      analysis: {
        filter: {
          english_stop: {
            type: 'stop',
            stopwords: '_english_'
          }
        },
        analyzer: {
          rebuilt_stop: {
            tokenizer: 'lowercase',
            filter: [
              'english_stop'
            ]
          }
        }
      }
    }
  }
)
puts response
const response = await client.indices.create({
  index: "stop_example",
  settings: {
    analysis: {
      filter: {
        english_stop: {
          type: "stop",
          stopwords: "_english_",
        },
      },
      analyzer: {
        rebuilt_stop: {
          tokenizer: "lowercase",
          filter: ["english_stop"],
        },
      },
    },
  },
});
console.log(response);
PUT /stop_example
{
  "settings": {
    "analysis": {
      "filter": {
        "english_stop": {
          "type":       "stop",
          "stopwords":  "_english_" 
        }
      },
      "analyzer": {
        "rebuilt_stop": {
          "tokenizer": "lowercase",
          "filter": [
            "english_stop"          
          ]
        }
      }
    }
  }
}

Стоп-слова по умолчанию можно переопределить с помощью параметров stopwords или stopwords_path.

Вы бы добавили любые фильтры токенов после english_stop.

© 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/analysis-stop-analyzer.html

Spec-Zone.ru

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