Token count field type
A field of type token_count is really an integer field which accepts string values, analyzes them, then indexes the number of tokens in the string.
For instance:
PUT my-index-000001
{
"mappings": {
"properties": {
"name": {
"type": "text",
"fields": {
"length": {
"type": "token_count",
"analyzer": "standard"
}
}
}
}
}
}
PUT my-index-000001/_doc/1
{ "name": "John Smith" }
PUT my-index-000001/_doc/2
{ "name": "Rachel Alice Williams" }
GET my-index-000001/_search
{
"query": {
"term": {
"name.length": 3
}
}
} | The | |
| The | |
| This query matches only the document containing |
Parameters for token_count fields
The following parameters are accepted by token_count fields:
| The analyzer which should be used to analyze the string value. Required. For best performance, use an analyzer without token filters. | |
| | Indicates if position increments should be counted. Set to |
| Mapping field-level query time boosting. Accepts a floating point number, defaults to | |
| Should the field be stored on disk in a column-stride fashion, so that it can later be used for sorting, aggregations, or scripting? Accepts | |
| Should the field be searchable? Accepts | |
| Accepts a numeric value of the same | |
| Whether the field value should be stored and retrievable separately from the |
© 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/7.17/token-count.html