Link Search Menu Expand Document Documentation Menu

Keyword analyzer

The keyword analyzer doesn’t tokenize text at all. Instead, it treats the entire input as a single token and does not break it into individual tokens. The keyword analyzer is often used for fields containing email addresses, URLs, or product IDs and in other cases where tokenization is not desirable.

Example

Use the following command to create an index named my_keyword_index with a keyword analyzer:

PUT /my_keyword_index
{
  "mappings": {
    "properties": {
      "my_field": {
        "type": "text",
        "analyzer": "keyword"
      }
    }
  }
}

Configuring a custom analyzer

Use the following command to configure an index with a custom analyzer that is equivalent to the keyword analyzer:

PUT /my_custom_keyword_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_keyword_analyzer": {
          "tokenizer": "keyword"
        }
      }
    }
  }
}

Generated tokens

Use the following request to examine the tokens generated using the analyzer:

POST /my_custom_keyword_index/_analyze
{
  "analyzer": "my_keyword_analyzer",
  "text": "Just one token"
}

The response contains the generated tokens:

{
  "tokens": [
    {
      "token": "Just one token",
      "start_offset": 0,
      "end_offset": 14,
      "type": "word",
      "position": 0
    }
  ]
}
350 characters left

Have a question? .

Want to contribute? or .