Updating/creating index using high level java client

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
opensearch-rest-high-level-client:2.4.0

Describe the issue:
Index is being created as string instead of json

Configuration:
Here is the code snippet
RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, “https”))
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
});
try (RestHighLevelClient client = new RestHighLevelClient(builder):wink: {

		IndexRequest request = new IndexRequest("record_index_pg"));
		request.id(uuid);

		HashMap<String, String> stringMapping = new HashMap<String, String>();
		
		stringMapping.put("record", json);
		request.source(stringMapping, XContentType.JSON);//this is not being honored and it is being passed as a string instead of json, resulting in the below representation
		IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
	} catch (IOException ex) {
		logger.error("IOException in OpenSearchService ", ex);
	} catch (Exception ex) {
		logger.error("Exception in OpenSearchService ", ex);
	}

The following is the index, please note that the double quotes after “record:” “{…}”
{
“_index”: “record_index”,
“_type”: “_doc”,
“_id”: “123456”,
“_version”: 1,
“_score”: 0,
“_source”: {
“record”: “{\n "uuid": "123456",\n "status": "S",\n "comments": "Test record only"}”
}
}

Relevant Logs or Screenshots:

This seems like a bug. Maybe report it here: Sign in to GitHub · GitHub

There is a more supported client here: GitHub - opensearch-project/opensearch-java: Java Client for OpenSearch

Specifically, there is an async client implemented in opensearch-java:

Thanks, for your response, is there a way to update part of an existing index with json?
For eg:
Current index
{
“_index”: “record_index”,
“_type”: “_doc”,
“_id”: “123456”,
“_version”: 1,
“_score”: 0,
“_source”: {
“record”: “{\n “uuid”: “123456”,\n “status”: “S”,\n “comments”: “Test record only”}”
}
}

update it to
{
“_index”: “record_index”,
“_type”: “_doc”,
“_id”: “123456”,
“_version”: 1,
“_score”: 0,
“_source”: {
“record”: “XYZ”
}
}

where XYZ is a json

something like this
XContentBuilder jb = XContentFactory.jsonBuilder();
jb.startObject().field(“record”, XYZ).endObject();

I’m not sure and I hope someone else can pipe up on this.

@Din please take a look at Update API: Update document - OpenSearch documentation