Update operation does not work with BinaryData object.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with the testBinaryDataUpdateIngestion reproducer and trace the UpdateRequest.doc(BinaryData) entry point through the client’s request serialization. Run the reproducer against Elasticsearch and confirm that the created document contains {"foo":"bar"} and that the existing response assertions pass.
Written by the indexing model from the issue text.
Description
Java API client version
7.17.10
Java version
11
Elasticsearch Version
7.17.9
Problem description
If you try and perform an update when using the BinaryData object the document will be created but it will be empty.
I have created a test for a reproducer.
public void testBinaryDataUpdateIngestion() throws Exception {
String index = "binary-ingestion-test";
String id = "foo-bar";
BinaryData data = BinaryData.of("{\"foo\":\"bar\"}".getBytes(), ContentType.APPLICATION_JSON);
UpdateResponse<BinaryData> response = esAsyncClient.update(UpdateRequest.of(u -> u
.index(index)
.id(id)
.doc(data)
.docAsUpsert(true)
.refresh(Refresh.True)), BinaryData.class).get();
Assertions.assertEquals(response.result().toString(), "Created");
GetResponse<BinaryData> getResponse =
esAsyncClient.get(g -> g.index(index)
.id(id)
,BinaryData.class
).get();
Assertions.assertEquals(id, getResponse.id());
Assertions.assertEquals(
"{\"foo\":\"bar\"}",
new String(getResponse.source().asByteBuffer().array(), StandardCharsets.UTF_8)
);
}
I was able to get this to work using a similar object and implementing JsonpSerializable like so.
@Override
public void serialize(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper) {
if(generator instanceof JacksonJsonpGenerator){
// data is a byte[] containing raw JSON data
String json = new String(data, StandardCharsets.UTF_8);
try {
((JacksonJsonpGenerator) generator).jacksonGenerator().writeRawValue(json);
} catch (IOException e) {
throw new IllegalStateException("Unable to write raw json", e);
}
}else{
throw new UnsupportedOperationException("Only JacksonJsonpGenerator is supported");
}
}
- Dominant language
- Java
- Stars
- 524
- Forks
- 300
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from elastic/elasticsearch-java
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
elastic/elasticsearch-java#1339 · 3 comments · 1 assignee ·
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
elastic/elasticsearch-java#1212 · 8 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
elastic/elasticsearch-java#1165 · 5 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
elastic/elasticsearch-java#1083 · 2 comments ·
-
Area: Generator Category: Enhancement
Difficulty 3/5 1-2 days Newbie friendliness 48/100
elastic/elasticsearch-java#1034 · 2 comments ·
All issues in elastic/elasticsearch-java
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100