Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Do a Mapping of Array of Strings in Elasticsearch

I can't find any examples of how to structure an array of strings in elasticsearch when trying to PUT a mapping to an index.

What I have for the field mapping:

:tags {:type :array :store true}

The error i get:

{:type "mapper_parsing_exception",  :reason "No handler for type [array] declared on field [tags]"} 
like image 482
Micah Avatar asked Apr 20 '17 21:04

Micah


People also ask

How do I store an array in Elasticsearch?

In Elasticsearch, there is no dedicated array type. Any field can contain zero or more values by default, however, all values in the array must be of the same datatype. So you don't have to specify anything specific in the mapping to store an array of values.

What is a mapping in Elasticsearch?

Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. Each document is a collection of fields, which each have their own data type. When mapping your data, you create a mapping definition, which contains a list of fields that are pertinent to the document.

How do I show mappings in Elasticsearch?

These can be accessed from your dashboard by choosing Stack Settings > Elasticsearch . The next step is to write a a curl -x get command to retrieve the mappings from Elasticsearch. You will be returned with a json output similar to the below screenshot.


2 Answers

In Elasticsearch, there is no dedicated array type. Any field can contain zero or more values by default, however, all values in the array must be of the same datatype.

So you don't have to specify anything specific in the mapping to store an array of values.

For more information look at: https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html

like image 135
pippobaudos Avatar answered Sep 20 '22 22:09

pippobaudos


Just write

:tags { "type" : "text" } 

It works for store array in Elasticsearch.

like image 33
dhruvil talaviya Avatar answered Sep 21 '22 22:09

dhruvil talaviya