# Bulk API "lies" in the response

**URL:** https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674
**Category:** Elasticsearch
**Created:** [September 15, 2020, 12:42pm UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674 "2020-09-15T12:42:31Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![JulGor](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@JulGor](https://discuss.elastic.co/u/JulGor)
#### Post date: [September 15, 2020, 12:42pm UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/1 "2020-09-15T12:42:31Z")

</div>

Hello,

I'm having some problems using the Bulk API because it is lying in the response it returns.

I'm using the following request:

```auto
    POST /_bulk?refresh=true
    { "index": { "_index": "my_index", "_id": 123 } },
    { "internal_id": 123, "attr1": "value1", "attr2": "value2", ... }

```

And I'm getting the response below:

```auto
    {
      "took": 16,
      "errors": false,
      "items": [
        {
          "index": {
            "_index": "my_index",
            "_type": "_doc",
            "_id": "123",
            "_version": 1,
            "result": "created",
            "forced_refresh": true,
            "_shards": {
              "total": 1,
              "successful": 1,
              "failed": 0
            },
            "_seq_no": 21744,
            "_primary_term": 3,
            "status": 201
          }
        }
      ]
    }

```

That looks great but the actual issue is that when I go to "my\_index" a search for document with id 123, there is no document.

In fact, the number of documents of the index does not change.

The "funny" thing is that this behaviour only happens when I launch the request from a Google Cloud Function but if I launch exactly the same request from my local computer, the document is successfully indexed.

Can anyone help me to identify the problem? I'm going crazy...

Thanks in advance!

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [September 16, 2020, 1:36am UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/2 "2020-09-16T01:36:14Z")

</div>

Can you provide a full reproduction of the requests that you are running for the index and the search, along with the respones?

---

<div class="post-metadata">

### Author: ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)
#### Post date: [September 16, 2020, 5:16am UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/3 "2020-09-16T05:16:05Z")

</div>

> [@JulGor](#):
>
> when I go to "my\_index" a search for document with id 123, there is no document.

I suspect that at the point of searching, the [index has not been refreshed](https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html#refresh-api-desc), so the document does not yet appear in search results. If you [fetch the document using its ID with the Get API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html), it'll be there.

---

<div class="post-metadata">

### Author: ![JulGor](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@JulGor](https://discuss.elastic.co/u/JulGor)
#### Post date: [September 16, 2020, 8:45am UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/4 "2020-09-16T08:45:09Z")

</div>

Thanks for the quick response.

Here is a real request (just changed the values of the attributes and the endpoint, that is in Elastic Cloud as you can see):

```auto
POST https://my_elastic_cloud_id.gcp.cloud.es.io:9243/_bulk?refresh=true
{"index": {"_index": "my_production_index", "_id": 4789467775055}}
{"store": "STORENAME", "my_id": 4789467775055, "product": {"pname": "the name", "pbrand": "the brand", "pphotos": ["https://url.to.photo.1.jpg", "https://url.to.photo.2.jpg"], "pid": "140205970", "pcategory": "the category", "pdesc": "the text of the description", "pvariants": [{"size": "40", "qty": 5}, {"size": "41.5", "qty": 10}], "pcompareatprice": 127, "ptags": ["tag1", "tag2"], "gender": "Female", "age": "Adult", "pprice": 78, "pdiscount": 39, "pdate": "2020-09-16 08:15:48"}}

```

And this is the actual response to that request:

```auto
{
  "took": 13,
  "errors": false,
  "items": [
    {
      "index": {
        "_index": "my_production_index",
        "_type": "_doc",
        "_id": "4789467775055",
        "_version": 1,
        "result": "created",
        "forced_refresh": true,
        "_shards": {
          "total": 1,
          "successful": 1,
          "failed": 0
        },
        "_seq_no": 813,
        "_primary_term": 1,
        "status": 201
      }
    }
  ]
}

```

I also thought in the refresh thing that point @forloop, but as you can see in the request, I force it.

Further, I do check the number of documents of the index before and after the indexing and it doesn't change (being 731 both times):

`GET /_cat/indices`

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/8/4899607e4244791be406610c364ef7ce1e8438e5.png)

The query I'm using to check the document is (launched from the Kibana console):

```auto
GET my_production_index/_search
{
  "query": { 
      "ids": { 
          "values": [4789467775055]
      }
  },
  "size" : 1
}

```

And the response is:

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

And, as I said in the first post, if I do repeat exactly the same request from my laptop or the Kibana console, the request works fine and index the document, but when I launch it from the Google Cloud Function, I get a valid response but the document is not indexed.

Any idea about how I can detect and fix the issue?

Many thanks!

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [September 17, 2020, 12:01am UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/5 "2020-09-17T00:01:42Z")

</div>

I just ran the exact commands you posted (thanks for that!) and my response was;

```auto
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my_production_index",
        "_type" : "_doc",
        "_id" : "4789467775055",
        "_score" : 1.0,
        "_source" : {
          "store" : "STORENAME",
          "my_id" : 4789467775055,
          "product" : {
            "pname" : "the name",
            "pbrand" : "the brand",
            "pphotos" : [
              "https://url.to.photo.1.jpg",
              "https://url.to.photo.2.jpg"
            ],
            "pid" : "140205970",
            "pcategory" : "the category",
            "pdesc" : "the text of the description",
            "pvariants" : [
              {
                "size" : "40",
                "qty" : 5
              },
              {
                "size" : "41.5",
                "qty" : 10
              }
            ],
            "pcompareatprice" : 127,
            "ptags" : [
              "tag1",
              "tag2"
            ],
            "gender" : "Female",
            "age" : "Adult",
            "pprice" : 78,
            "pdiscount" : 39,
            "pdate" : "2020-09-16 08:15:48"
          }
        }
      }
    ]
  }
}

```

What version are you on?

---

<div class="post-metadata">

### Author: ![JulGor](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@JulGor](https://discuss.elastic.co/u/JulGor)
#### Post date: [September 17, 2020, 9:40am UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/6 "2020-09-17T09:40:21Z")

</div>

I'm in 7.9, just migrated last week.

From my laptop, I get that same result, but not from the server.

Is there any way to debug what it is actually happening?

---

<div class="post-metadata">

### Author: ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)
#### Post date: [September 17, 2020, 10:50am UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/7 "2020-09-17T10:50:00Z")

</div>

Possibly-silly question, but are you sure you're indexing into the same cluster as the one against which you're subsequently searching? Check `GET _cluster/state/nodes` from both locations and verify that they're completely identical.

---

<div class="post-metadata">

### Author: ![JulGor](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@JulGor](https://discuss.elastic.co/u/JulGor)
#### Post date: [September 21, 2020, 7:53am UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/8 "2020-09-21T07:53:28Z")

</div>

Hello,

I finally found the problem.

After indexing the document, another process was automatically triggered and it was deleting the indexed document, that's the reason I couldn't find it and everything looked fine during indexing.

Sorry to bother you and thanks again for your help!

---

<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: [October 19, 2020, 7:53am UTC](https://discuss.elastic.co/t/bulk-api-lies-in-the-response/248674/9 "2020-10-19T07:53:37Z")

</div>

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