Skip to content

Commit

Permalink
Inconsistency between java client and OpenSearch update by query resp…
Browse files Browse the repository at this point in the history
…onses

Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta committed Dec 4, 2024
1 parent aefc6cb commit c1eec75
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ public ByQueryResponse byQueryResponse(UpdateByQueryResponse response) {
builder.withDeleted(response.deleted());
}

if (response.updated() != null) {
builder.withUpdated(response.updated());
}

if (response.batches() != null) {
builder.withBatches(Math.toIntExact(response.batches()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3669,6 +3669,36 @@ public void shouldDeleteDocumentForGivenQueryUsingParameters() {
IndexCoordinates.of(indexName));
assertThat(searchHits.getTotalHits()).isEqualTo(0);
}

@Test // OS-GH-387
public void shouldUpdateDocumentForGivenQueryUsingParameters() {
// Given
String documentId = nextIdAsString();
SampleEntity sampleEntity = SampleEntity.builder().id(documentId).message("some message")
.version(System.currentTimeMillis()).build();

IndexQuery indexQuery = getIndexQuery(sampleEntity);
String indexName = indexNameProvider.indexName();

operations.index(indexQuery, IndexCoordinates.of(indexName));

// When
final Query query = getTermQuery("id", documentId);
org.springframework.data.elasticsearch.core.document.Document document = org.springframework.data.elasticsearch.core.document.Document
.create();
document.put("message", "another message");

final UpdateQuery updateQuery = UpdateQuery.builder(query).withSlices(2).withDocument(document).build();
ByQueryResponse result = operations.updateByQuery(updateQuery, IndexCoordinates.of(indexName));

// Then
assertThat(result.getDeleted()).isEqualTo(0);
assertThat(result.getUpdated()).isEqualTo(1);
SearchHits<SampleEntity> searchHits = operations.search(query, SampleEntity.class,
IndexCoordinates.of(indexName));
assertThat(searchHits.getTotalHits()).isEqualTo(1);
}


@Test
public void shouldDeleteDocumentForGivenQueryAndUnavailableIndex() {
Expand Down

0 comments on commit c1eec75

Please sign in to comment.