I am implementing a bulk update operation using an OpenSearch Java client for existing documents stored in the OpenSearch provisioned by AWS.
The BulkRequest
request object looks like this:
BulkRequest request = new BulkRequest.Builder().operations(o -> o.update(u -> u.index(indexName).id(String.valueOf(id)).document(doc))).build();
openSearchClient.bulk(request);
The doc
object is a POJO object that reflects a document inside the index.
public class ProgramSelectionInfoBase implements Serializable {
private static final long serialVersionUID = 6880667215923483985L;
private long id;
private String status35;
// other fields, getters, setters.
}
The response I am getting is 400 Bad Request
In the debug mode, the parsed bulk request looks different as it should per the bulk update documentation. It lacks the "doc"
parent object, which should wrap the partially updated document:
{ "update" : { "_id" : "361710", "_index" : "program_search" }}
{ "status35": "draft" }. <- doc is missing.
{ "update": { "_index": "movies", "_id": "tt0816711" } }
{ "doc": { "title": "World War Z" } }
If I replace a bulk update request with a single document update request, I get successful results. The parsed request structure matches the documentation one:
UpdateRequest<Object, Object> request = new UpdateRequest.Builder<>().id(String.valueOf(id)).doc(doc).index(indexName).build();
openSearchClient.update(request, Object.class);
{"doc":{"status35":"active"}}
Question: Am I building a BulkRequest
object incorrectly? Or this is the client library issue?
UPDATE I am using the latest available OpenSearch Java client version