Elasticsearch saves document as string of array, not array of strings

83 Views Asked by At

I am trying to contain array as a document value. I succeed it in "tags" field as below;

This document contains array of strings.

curl -XGET localhost:9200/MY_INDEX/_doc/132328908

#=> {
  "_index":"MY_INDEX",
  "_type":"_doc",
  "_id":"132328908",
  "found":true,
  "_source": {
    "tags": ["food"]
  }
}

However, when I am putting items in the same way as above,
the document is SOMETIMES like that;

curl -XGET localhost:9200/MY_INDEX/_doc/328098989

#=> {
  "_index":"MY_INDEX",
  "_type":"_doc",
  "_id":"328098989",
  "found":true,
  "_source": {
    "tags": "[\"food\"]"
  }
}

This is string of array, not array of strings, which I expected.

"tags": "[\"food\"]"

It seems that this situation happens randomly and I could not predict it. How could it happen?

Note: ・I use elasticsearch-ruby client to index a document.
This is my actual code;

es_client = Elasticsearch::Client.new url: MY_ENDPOINT

es_client.index(
   index: MY_INDEX,
   id: random_id, # defined elsewhere
   body: {
      doc:  {
         "tags": ["food"]
      },
   }
)

Thank you in advance.

0

There are 0 best solutions below