Low level REST API : bulk request and array problem


#1

Dear all,

I am currently working on ES 6.0, using the low rest client to communicate with an ES 6.0.

I am wondering few things, among them :

  • is it possible, via the low rest client, to get a response like this one after doing a bulk request :

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

{
   "took": 4,
   "errors": false, 
   "items": [
      {  "delete": {
            "_index":   "website",
            "_type":    "blog",
            "_id":      "123",
            "_version": 2,
            "status":   200,
            "found":    true
      }},
      {  "create": {
            "_index":   "website",
            "_type":    "blog",
            "_id":      "123",
            "_version": 3,
            "status":   201
      }},
      {  "create": {
            "_index":   "website",
            "_type":    "blog",
            "_id":      "EiwfApScQiiy7TIKFxRCTw",
            "_version": 1,
            "status":   201
      }},
      {  "update": {
            "_index":   "website",
            "_type":    "blog",
            "_id":      "123",
            "_version": 4,
            "status":   200
      }}
   ]
}

I currently only get a 200 OK HTTP answer (or 400 Bad Request).

  • using the transport client, I can update a document, let's say a document that contains an array of phone numbers: "phones" : [ "800800800" ]
    Using the low-level rest client, I want to do the same but I get the following error :
    "Malformed action/metadata line [1], expected a simple value for field [phones] but found [START_ARRAY]
    Do you have any idea of what could be my mistake ? ES seems to recognize that it is an array, so the request should not be the problem. As for the document, using the transport client it can create the "phones" field (as an array) when it is not present. I wonder why it does not do the same with the low-level REST client.

Looking forward to having a discussion, I wish you a pleasant day.

Regards.


(David Pilato) #2

Please don't post images of text as they are hardly readable and not searchable.

Instead paste the text and format it with </> icon. Check the preview window.

What did you pass as JSON to the Low Level client?


#3

Done.

For the first point :

I send the exact same format as explained in https://www.elastic.co/guide/en/elasticsearch/guide/current/bulk.html

{ "index" : { "_index" : "myindex", "_type" : "mytype", "_id" : 1} }
{"name": "Foo"}
{ "index" : { "_index" : "myindex", "_type" : "mytype", "_id" : 2} }
{"name": "Bar"}
{ "index" : { "_index" : "myindex", "_type" : "mytype", "_id" : 3} }
{"name": "FooBar"}
{ "index" : { "_index" : "myindex", "_type" : "mytype", "_id" : 4} }
{"name": "BarFoo"}

This problem is solved by looking more deeply into the Response object : the full JSON answer is in (the response Object).getEntity().getContent()

For the second point :

{ "update" : { "_index" : "myindex", "_type" : "mytype", "_id" : 4, "phones": ["0123456"]}}

Thank you.

Regards


(David Pilato) #4

The doc says that an update should be done like this:

{ "update" : {"_id" : "1", "_type" : "_doc", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }

#5

Oh, ok, I should have read more carefully.

Thank you very much.

Regards