Spec-Zone.ru › Elasticsearch 8
›Elasticsearch Guide [8.17] ›Text analysis ›Token filter reference

Reverse token filter

Reverses each token in a stream. For example, you can use the reverse filter to change cat to tac.

Reversed tokens are useful for suffix-based searches, such as finding words that end in -ion or searching file names by their extension.

This filter uses Lucene’s ReverseStringFilter.

Example

The following analyze API request uses the reverse filter to reverse each token in quick fox jumps:

resp = client.indices.analyze(
    tokenizer="standard",
    filter=[
        "reverse"
    ],
    text="quick fox jumps",
)
print(resp)
response = client.indices.analyze(
  body: {
    tokenizer: 'standard',
    filter: [
      'reverse'
    ],
    text: 'quick fox jumps'
  }
)
puts response
const response = await client.indices.analyze({
  tokenizer: "standard",
  filter: ["reverse"],
  text: "quick fox jumps",
});
console.log(response);
GET _analyze
{
  "tokenizer" : "standard",
  "filter" : ["reverse"],
  "text" : "quick fox jumps"
}

The filter produces the following tokens:

[ kciuq, xof, spmuj ]

Add to an analyzer

The following create index API request uses the reverse filter to configure a new custom analyzer.

resp = client.indices.create(
    index="reverse_example",
    settings={
        "analysis": {
            "analyzer": {
                "whitespace_reverse": {
                    "tokenizer": "whitespace",
                    "filter": [
                        "reverse"
                    ]
                }
            }
        }
    },
)
print(resp)
response = client.indices.create(
  index: 'reverse_example',
  body: {
    settings: {
      analysis: {
        analyzer: {
          whitespace_reverse: {
            tokenizer: 'whitespace',
            filter: [
              'reverse'
            ]
          }
        }
      }
    }
  }
)
puts response
const response = await client.indices.create({
  index: "reverse_example",
  settings: {
    analysis: {
      analyzer: {
        whitespace_reverse: {
          tokenizer: "whitespace",
          filter: ["reverse"],
        },
      },
    },
  },
});
console.log(response);
PUT reverse_example
{
  "settings" : {
    "analysis" : {
      "analyzer" : {
        "whitespace_reverse" : {
          "tokenizer" : "whitespace",
          "filter" : ["reverse"]
        }
      }
    }
  }
}

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

Spec-Zone.ru

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