0

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.

user16012143
  • 139
  • 7
  • Can you share an example of how you put the doc into Elastic? all the insert command include the doc – Netanel Malka Jun 27 '22 at 18:07
  • Hi, Thanks. `curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT -d '{ "tags": ["food", "trip" ] localhost:9200/MY_INDEX/_doc/239879` – user16012143 Jun 28 '22 at 00:08
  • This is my PUT command and the response is like that: – user16012143 Jun 28 '22 at 00:09
  • `{"_index":"MY_INDEX","_type":"_doc","_id":"239879","_version":4,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":25,"_primary_term":1}` – user16012143 Jun 28 '22 at 00:09
  • `curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST -d '{ "tags": ["food", "trip" ]}' "localhost:9200/test/_doc` always works fine for me. Are you really inserting all your records using `curl`? – Milen Georgiev Jun 28 '22 at 02:29
  • oh... I am so sorry for my oversimplification. Actually, I use elasticsearch-ruby client to index a document(https://github.com/elastic/elasticsearch-ruby). I add a note for that in my question. Thank you so much. – user16012143 Jun 28 '22 at 02:55

0 Answers0