elasticsearchHow do I decide whether to use a keyword or text field when indexing documents in Elasticsearch?
When deciding whether to use a keyword or text field when indexing documents in Elasticsearch, it is important to consider the type of data you are indexing and the desired use cases.
For example, if you are indexing a person's name, you should use a keyword field since you will likely want to search for exact matches.
PUT my_index
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
}
}
}
}
On the other hand, if you are indexing a description of a product, you should use a text field since you will likely want to search for words and phrases within the text.
PUT my_index
{
"mappings": {
"properties": {
"description": {
"type": "text"
}
}
}
}
The main difference between keyword and text fields is that keyword fields are analyzed and indexed as-is, while text fields are tokenized, lower-cased, and indexed as individual words. This means that keyword fields are better for exact matches, while text fields are better for searching words and phrases within a document.
For more information, please refer to the following links:
More of Elasticsearch
- How can I use Elasticsearch and Zabbix together for software development?
- How can I use elasticsearch zone awareness to improve my software development?
- How can I use Elasticsearch to diagnose "yellow" issues?
- How can I use YouTube to learn about Elasticsearch?
- How do I configure xpack.security.authc.realms in Elasticsearch?
- How can I perform a case-insensitive wildcard search using Elasticsearch?
- How do I configure elasticsearch xpack.security.transport.ssl?
- How do I use Yandex with Elasticsearch?
- How do I create an elasticsearch query that is similar to an existing query?
- How can I use Elasticsearch with Zammad?
See more codes...