ASCII folding token filter

edit

Converts alphabetic, numeric, and symbolic characters that are not in the Basic Latin Unicode block (first 127 ASCII characters) to their ASCII equivalent, if one exists. For example, the filter changes à to a.

This filter uses Lucene’s ASCIIFoldingFilter.

Example

edit

The following analyze API request uses the asciifolding filter to drop the diacritical marks in 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"
}

The filter produces the following tokens:

[ acai, a, la, carte ]

Add to an analyzer

edit

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

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" ]
        }
      }
    }
  }
}

Configurable parameters

edit
preserve_original
(Optional, Boolean) If true, emit both original tokens and folded tokens. Defaults to false.

Customize

edit

To customize the asciifolding filter, duplicate it to create the basis for a new custom token filter. You can modify the filter using its configurable parameters.

For example, the following request creates a custom asciifolding filter with preserve_original set to 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
        }
      }
    }
  }
}