# Low level REST API : bulk request and array problem

**URL:** https://discuss.elastic.co/t/low-level-rest-api-bulk-request-and-array-problem/119775
**Category:** Elasticsearch
**Created:** [February 14, 2018, 10:55am UTC](https://discuss.elastic.co/t/low-level-rest-api-bulk-request-and-array-problem/119775 "2018-02-14T10:55:36Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![yutanpo](https://avatars.discourse-cdn.com/v4/letter/y/6f9a4e/32.png) [@yutanpo](https://discuss.elastic.co/u/yutanpo)
#### Post date: [February 14, 2018, 10:55am UTC](https://discuss.elastic.co/t/low-level-rest-api-bulk-request-and-array-problem/119775/1 "2018-02-14T10:55:36Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 14, 2018, 11:08am UTC](https://discuss.elastic.co/t/low-level-rest-api-bulk-request-and-array-problem/119775/2 "2018-02-14T11:08:55Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![yutanpo](https://avatars.discourse-cdn.com/v4/letter/y/6f9a4e/32.png) [@yutanpo](https://discuss.elastic.co/u/yutanpo)
#### Post date: [February 14, 2018, 1:05pm UTC](https://discuss.elastic.co/t/low-level-rest-api-bulk-request-and-array-problem/119775/3 "2018-02-14T13:05:31Z")

</div>

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](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

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [February 14, 2018, 1:25pm UTC](https://discuss.elastic.co/t/low-level-rest-api-bulk-request-and-array-problem/119775/4 "2018-02-14T13:25:33Z")

</div>

The [doc](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/docs-bulk.html) says that an update should be done like this:

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

```

---

<div class="post-metadata">

### Author: ![yutanpo](https://avatars.discourse-cdn.com/v4/letter/y/6f9a4e/32.png) [@yutanpo](https://discuss.elastic.co/u/yutanpo)
#### Post date: [February 14, 2018, 1:44pm UTC](https://discuss.elastic.co/t/low-level-rest-api-bulk-request-and-array-problem/119775/5 "2018-02-14T13:44:09Z")

</div>

Oh, ok, I should have read more carefully.

Thank you very much.

Regards

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 14, 2018, 1:44pm UTC](https://discuss.elastic.co/t/low-level-rest-api-bulk-request-and-array-problem/119775/6 "2018-03-14T13:44:28Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
