Elasticsearch NEST API handle failed bulk updates

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.

Any updates on the above question ?

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.

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; }
}

Thanks, I've opened an issue to address for the next release.

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 ?

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