Can someone explain the difference between keyword and text in ElasticSearch with an example?
The keyword family includes the following field types: keyword , which is used for structured content such as IDs, email addresses, hostnames, status codes, zip codes, or tags. constant_keyword for keyword fields that always contain the same value.
keyword field takes the same input and keeps as one large string, meaning it can be aggregated on, and you can use wildcard searches on it. Aggregatable means you can use it in aggregations in elasticsearch, which resembles a sql group by if you are familiar with that. In Kibana you would probably use the .
The maximum bytes can be at most 32766. You will get a following error reason when the bytes go beyond 32766.
Overview. Full-text search queries and performs linguistic searches against documents. It includes single or multiple words or phrases and returns documents that match search condition. ElasticSearch is a search engine based on Apache Lucene, a free and open-source information retrieval software library.
keyword type: if you define a field to be of type keyword like this.
PUT products { "mappings": { "_doc": { "properties": { "name": { "type": "keyword" } } } } }
Then when you make a search query on this field you have to insert the whole value (keyword search) so keyword field.
POST products/_doc { "name": "washing machine" }
when you execute search like this:
GET products/_search { "query": { "match": { "name": "washing" } } }
it will not match any docs. You have to search with the whole word "washing machine".
text type on the other hand is analyzed and you can search using tokens from the field value. a full text search in the whole value:
PUT products { "mappings": { "_doc": { "properties": { "name": { "type": "text" } } } } }
and the search :
GET products/_search { "query": { "match": { "name": "washing" } } }
will return a matching documents.
You can check this to more details keyword Vs. text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With