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

Фильтр токенов ASCII folding

Преобразует буквенные, числовые и символьные знаки, которые не входят в блок Basic Latin Unicode (первые 127 символов ASCII), в их ASCII эквиваленты, если таковые существуют. Например, фильтр преобразует à в a.

Этот фильтр использует ASCIIFoldingFilter Lucene.

Пример

Следующий запрос API анализа использует фильтр asciifolding, чтобы удалить диакритические знаки в açaí à la carte:

resp = client.indices.analyze(
    tokenizer="standard",
    filter=[
        "asciifolding"
    ],
    text="açaí à la carte",
)
print(resp)
response = client.indices.analyze(
  body: {
    tokenizer: 'standard',
    filter: [
      'asciifolding'
    ],
    text: 'açaí à la carte'
  }
)
puts response
const response = await client.indices.analyze({
  tokenizer: "standard",
  filter: ["asciifolding"],
  text: "açaí à la carte",
});
console.log(response);
GET /_analyze
{
  "tokenizer" : "standard",
  "filter" : ["asciifolding"],
  "text" : "açaí à la carte"
}

Фильтр производит следующие токены:

[ acai, a, la, carte ]

Добавление в анализатор

Следующий запрос API создания индекса использует фильтр asciifolding для настройки нового пользовательского анализатора.

resp = client.indices.create(
    index="asciifold_example",
    settings={
        "analysis": {
            "analyzer": {
                "standard_asciifolding": {
                    "tokenizer": "standard",
                    "filter": [
                        "asciifolding"
                    ]
                }
            }
        }
    },
)
print(resp)
response = client.indices.create(
  index: 'asciifold_example',
  body: {
    settings: {
      analysis: {
        analyzer: {
          standard_asciifolding: {
            tokenizer: 'standard',
            filter: [
              'asciifolding'
            ]
          }
        }
      }
    }
  }
)
puts response
const response = await client.indices.create({
  index: "asciifold_example",
  settings: {
    analysis: {
      analyzer: {
        standard_asciifolding: {
          tokenizer: "standard",
          filter: ["asciifolding"],
        },
      },
    },
  },
});
console.log(response);
PUT /asciifold_example
{
  "settings": {
    "analysis": {
      "analyzer": {
        "standard_asciifolding": {
          "tokenizer": "standard",
          "filter": [ "asciifolding" ]
        }
      }
    }
  }
}

Настраиваемые параметры

preserve_original
(Необязательно, Булево) Если true, выводить как исходные токены, так и преобразованные. По умолчанию false.

Настройка

Чтобы настроить фильтр asciifolding, дублируйте его, чтобы создать основу для нового пользовательского фильтра токенов. Вы можете изменить фильтр, используя его настраиваемые параметры.

Например, следующий запрос создаёт пользовательский фильтр asciifolding с параметром preserve_original, установленным в true:

resp = client.indices.create(
    index="asciifold_example",
    settings={
        "analysis": {
            "analyzer": {
                "standard_asciifolding": {
                    "tokenizer": "standard",
                    "filter": [
                        "my_ascii_folding"
                    ]
                }
            },
            "filter": {
                "my_ascii_folding": {
                    "type": "asciifolding",
                    "preserve_original": True
                }
            }
        }
    },
)
print(resp)
response = client.indices.create(
  index: 'asciifold_example',
  body: {
    settings: {
      analysis: {
        analyzer: {
          standard_asciifolding: {
            tokenizer: 'standard',
            filter: [
              'my_ascii_folding'
            ]
          }
        },
        filter: {
          my_ascii_folding: {
            type: 'asciifolding',
            preserve_original: true
          }
        }
      }
    }
  }
)
puts response
const response = await client.indices.create({
  index: "asciifold_example",
  settings: {
    analysis: {
      analyzer: {
        standard_asciifolding: {
          tokenizer: "standard",
          filter: ["my_ascii_folding"],
        },
      },
      filter: {
        my_ascii_folding: {
          type: "asciifolding",
          preserve_original: true,
        },
      },
    },
  },
});
console.log(response);
PUT /asciifold_example
{
  "settings": {
    "analysis": {
      "analyzer": {
        "standard_asciifolding": {
          "tokenizer": "standard",
          "filter": [ "my_ascii_folding" ]
        }
      },
      "filter": {
        "my_ascii_folding": {
          "type": "asciifolding",
          "preserve_original": true
        }
      }
    }
  }
}

© 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-asciifolding-tokenfilter.html

Spec-Zone.ru

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