-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
91b11cb
commit 1a45bf7
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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: | ||
|
||
```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 | ||
} | ||
] | ||
} | ||
``` |