Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between keyword and text in ElasticSearch

Can someone explain the difference between keyword and text in ElasticSearch with an example?

like image 295
archura Avatar asked Oct 16 '18 23:10

archura


People also ask

What are keywords in Elasticsearch?

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.

What is field keyword?

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 .

What is the maximum length for text type in Elasticsearch?

The maximum bytes can be at most 32766. You will get a following error reason when the bytes go beyond 32766.

What is Elasticsearch full text search?

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.


1 Answers

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

like image 114
Tarek Essam Avatar answered Oct 02 '22 13:10

Tarek Essam