Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add keyword analyzer docs #8535

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions _analyzers/keyword.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
layout: default
title: Keyword analyzer
nav_order: 80
---

# Keyword analyzer

The `keyword` analyzer doesn’t tokenize the text at all. Instead, it treats the entire input as a single token. This is useful when you want the entire content of a field to be indexed as is, without breaking it into smaller pieces (tokens). The `keyword` analyzer is often used for fields like email addresses, URLs, product IDs, and other cases where tokenization is not desirable.
kolchfa-aws marked this conversation as resolved.
Show resolved Hide resolved

## Example

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

```json
PUT /my_keyword_index
{
"mappings": {
"properties": {
"my_field": {
"type": "text",
"analyzer": "keyword"
}
}
}
}
```
{% include copy-curl.html %}

## Configuring a custom analyzer

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

```json
PUT /my_custom_keyword_index
{
"settings": {
"analysis": {
"analyzer": {
"my_keyword_analyzer": {
"tokenizer": "keyword"
}
}
}
}
}
```
{% include copy-curl.html %}

## Generated tokens

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

```json
POST /my_custom_keyword_index/_analyze
{
"analyzer": "my_keyword_analyzer",
"text": "Just one token"
}
```
{% include copy-curl.html %}

The response contains the generated tokens:

```json
{
"tokens": [
{
"token": "Just one token",
"start_offset": 0,
"end_offset": 14,
"type": "word",
"position": 0
}
]
}
```
Loading