2

I want to index document keywords as array datatype, not a string, something like: keywords:['key1', 'key2',...] and from elasticsearch documentation you can have keywords field as a string:

PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "tags": {
          "type":  "keyword"
        }
      }
    }
  }
}

what should I do?

Saro
  • 47
  • 1
  • 9
  • what is your reason to use keyword instead of string here? – deerawan May 22 '18 at 07:45
  • each document has 4 to 8 keywords, to map them as a string, I have 2 options, first to pack them together(something like "key1||key2||key3||..." which isn't efficient for search query(or at least that is what I think ) and the 2nd way is to have 8 text field as key1, key2, key3... which this one is also not efficient since I have 4 million document and its gonna be more , what do you think? – Saro May 22 '18 at 11:15
  • let me add this that I am okay with "key1||key2||key3||..." if somehow configure elasticsearch mapping to detect each one of them as keywords – Saro May 22 '18 at 11:27

1 Answers1

1

In elasticsearch documentation there is a "Array datatype", could you use this mapping?

https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html

javaTry
  • 629
  • 8
  • 22
  • it worked this way, but not as keyword data type, I am not sure which way is better, to have an array of keywords data type or just have an array – Saro May 22 '18 at 06:35