# Elasticsearch NEST API handle failed bulk updates

**URL:** https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986
**Category:** Elasticsearch
**Created:** [August 18, 2018, 4:06am UTC](https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986 "2018-08-18T04:06:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![muthucse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthucse/32/45217_2.png) [@muthucse](https://discuss.elastic.co/u/muthucse)
#### Post date: [August 18, 2018, 4:06am UTC](https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986/1 "2018-08-18T04:06:29Z")

</div>

Updating a nested document using painless script. The document will be updated only when the condition is met. Trying to get noop response for the failed conditions but not able to get the response in dotNet's NEST bulk update API. How to achieve this ?

Elasticsearch version: 6.2.4,  
NEST: 6  
Script Query send from dotNet application is given below

Sample code:

```
POST _bulk
{  
   "update":{  
      "_index":"test-index",
      "_type":"doc",
      "_id":456,
      "routing":123
   }
}{  
   "script":{  
      "params":{  
         "userStatus":"Approved",
         "users":{  
            "uId":6,
            "name":"Test"
         }
      },
      "source":" def found = false; for(i in ctx._source.users){ if (i.uId == 6) { i.userStatus = params.userStatus ;}else{ctx.op = 'none'}}"
   }
}

```

There is another option where we can throw exception's. Is this the right approach to use ?

```
else{ Debug.explain(ctx._source); ctx.op = 'none'; }}.

```

Please advice.

---

<div class="post-metadata">

### Author: ![muthucse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthucse/32/45217_2.png) [@muthucse](https://discuss.elastic.co/u/muthucse)
#### Post date: [August 18, 2018, 1:11pm UTC](https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986/2 "2018-08-18T13:11:41Z")

</div>

Any updates on the above question ?

---

<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: [August 20, 2018, 12:03am UTC](https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986/3 "2018-08-20T00:03:14Z")

</div>

Please can you edit your question to

- indicate what version of NEST you're using
- indicate what version of Elasticsearch you're targeting
- show the call you're making with NEST
- how you're handling the response, and what you're not able to get on it

With this information, it should be possible to understand what the issue is.

---

<div class="post-metadata">

### Author: ![muthucse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthucse/32/45217_2.png) [@muthucse](https://discuss.elastic.co/u/muthucse)
#### Post date: [August 21, 2018, 7:30am UTC](https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986/4 "2018-08-21T07:30:18Z")

</div>

This doesn't include the result parameter to get noop response

public interface IBulkResponseItem  
{  
//  
// Summary:  
// The type of bulk operation  
string Operation { get; }  
//  
// Summary:  
// The index against which the bulk operation ran  
[JsonPropertyAttribute("\_index")]  
string Index { get; }  
//  
// Summary:  
// The type against which the bulk operation ran  
[JsonPropertyAttribute("\_type")]  
string Type { get; }  
//  
// Summary:  
// The id of the document for the bulk operation  
[JsonPropertyAttribute("\_id")]  
string Id { get; }  
//  
// Summary:  
// The version of the document  
[JsonPropertyAttribute("\_version")]  
long Version { get; }  
//  
// Summary:  
// The status of the bulk operation  
[JsonPropertyAttribute("status")]  
int Status { get; }  
//  
// Summary:  
// The error associated with the bulk operation  
[JsonPropertyAttribute("error")]  
BulkError Error { get; }  
//  
// Summary:  
// The shards associated with the bulk operation  
[JsonPropertyAttribute("\_shards")]  
ShardStatistics Shards { get; }  
[JsonPropertyAttribute("\_seq\_no")]  
long SequenceNumber { get; }  
[JsonPropertyAttribute("\_primary\_term")]  
long PrimaryTerm { get; }  
//  
// Summary:  
// Specifies wheter this particular bulk operation succeeded or not  
bool IsValid { get; }  
}

---

<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: [August 22, 2018, 12:48am UTC](https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986/5 "2018-08-22T00:48:04Z")

</div>

Thanks, I've opened [an issue](https://github.com/elastic/elasticsearch-net/issues/3375) to address for the next release.

---

<div class="post-metadata">

### Author: ![muthucse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthucse/32/45217_2.png) [@muthucse](https://discuss.elastic.co/u/muthucse)
#### Post date: [August 22, 2018, 2:18am UTC](https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986/6 "2018-08-22T02:18:52Z")

</div>

Is it a best practice to use ```

`else{ Debug.explain(ctx._source); ctx.op = 'none'; }}.`

To get `404 exception` and handle the noop scenario as an interim solution ?

---

<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: [September 19, 2018, 2:18am UTC](https://discuss.elastic.co/t/elasticsearch-nest-api-handle-failed-bulk-updates/144986/7 "2018-09-19T02:18:59Z")

</div>

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