Keyword data type
editKeyword data type
editA field to index structured content such as IDs, email addresses, hostnames, status codes, zip codes or tags.
They are typically used for filtering (Find me all blog posts where
status
is published
), for sorting, and for aggregations. Keyword
fields are only searchable by their exact value.
If you need to index full text content such as email bodies or product
descriptions, it is likely that you should rather use a text
field.
Below is an example of a mapping for a keyword field:
PUT my-index-000001 { "mappings": { "properties": { "tags": { "type": "keyword" } } } }
Mapping numeric identifiers
Not all numeric data should be mapped as a numeric field data type.
Elasticsearch optimizes numeric fields, such as integer
or long
, for
range
queries. However, keyword
fields
are better for term
and other
term-level queries.
Identifiers, such as an ISBN or a product ID, are rarely used in range
queries. However, they are often retrieved using term-level queries.
Consider mapping a numeric identifier as a keyword
if:
-
You don’t plan to search for the identifier data using
range
queries. -
Fast retrieval is important.
term
query searches onkeyword
fields are often faster thanterm
searches on numeric fields.
If you’re unsure which to use, you can use a multi-field to map
the data as both a keyword
and a numeric data type.
Parameters for keyword fields
editThe following parameters are accepted by keyword
fields:
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 global ordinals be loaded eagerly on refresh? Accepts |
|
Multi-fields allow the same string value to be indexed in multiple ways for different purposes, such as one field for search and a multi-field for sorting and aggregations. |
|
Do not index any string longer than this value. Defaults to |
|
Should the field be searchable? Accepts |
|
What information should be stored in the index, for scoring purposes.
Defaults to |
|
Whether field-length should be taken into account when scoring queries.
Accepts |
|
Accepts a string value which is substituted for any explicit |
|
Whether the field value should be stored and retrievable separately from
the |
|
Which scoring algorithm or similarity should be used. Defaults
to |
|
How to pre-process the keyword prior to indexing. Defaults to |
|
|
Whether full text queries should split the input on whitespace
when building a query for this field.
Accepts |
Metadata about the field. |
Indexes imported from 2.x do not support keyword
. Instead they will
attempt to downgrade keyword
into string
. This allows you to merge modern
mappings with legacy mappings. Long lived indexes will have to be recreated
before upgrading to 6.x but mapping downgrade gives you the opportunity to do
the recreation on your own schedule.