How to Do a Mapping of Array of Strings in Elasticsearch
Asked Answered
B

2

39

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]"}
Brookite answered 20/4, 2017 at 21:57 Comment(0)
E
50

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

Erwinery answered 20/4, 2017 at 22:41 Comment(2)
what if i want to specify analyzer for array elements?Oast
@Oast you specify an analyser as if the elements were not in an array. That analyser is applied to each item. They are not analysed as a whole array or group.Versatile
H
2

Just write

:tags { "type" : "text" }

It works for store array in Elasticsearch.

Haiti answered 23/5, 2021 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.