mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-08 13:12:10 +00:00
IndexQuery's id get ignored in bulkIndexOperation.
Original Pull Request #2407 Closdes #2405
This commit is contained in:
parent
2fb90621a2
commit
4d7d0955f9
@ -96,6 +96,7 @@ import org.springframework.util.StringUtils;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
* @author Sascha Woo
|
* @author Sascha Woo
|
||||||
* @author cdalxndr
|
* @author cdalxndr
|
||||||
|
* @author scoobyzhang
|
||||||
* @since 4.4
|
* @since 4.4
|
||||||
*/
|
*/
|
||||||
class RequestConverter {
|
class RequestConverter {
|
||||||
@ -440,7 +441,7 @@ class RequestConverter {
|
|||||||
Object queryObject = query.getObject();
|
Object queryObject = query.getObject();
|
||||||
|
|
||||||
if (queryObject != null) {
|
if (queryObject != null) {
|
||||||
String id = !StringUtils.hasText(query.getId()) ? getPersistentEntityId(queryObject) : query.getId();
|
String id = StringUtils.hasText(query.getId()) ? query.getId() : getPersistentEntityId(queryObject);
|
||||||
builder //
|
builder //
|
||||||
.id(id) //
|
.id(id) //
|
||||||
.document(elasticsearchConverter.mapObject(queryObject));
|
.document(elasticsearchConverter.mapObject(queryObject));
|
||||||
@ -492,7 +493,7 @@ class RequestConverter {
|
|||||||
Object queryObject = query.getObject();
|
Object queryObject = query.getObject();
|
||||||
|
|
||||||
if (queryObject != null) {
|
if (queryObject != null) {
|
||||||
String id = StringUtils.hasText(query.getId()) ? getPersistentEntityId(queryObject) : query.getId();
|
String id = StringUtils.hasText(query.getId()) ? query.getId() : getPersistentEntityId(queryObject);
|
||||||
builder //
|
builder //
|
||||||
.id(id) //
|
.id(id) //
|
||||||
.document(elasticsearchConverter.mapObject(queryObject));
|
.document(elasticsearchConverter.mapObject(queryObject));
|
||||||
@ -533,7 +534,7 @@ class RequestConverter {
|
|||||||
Object queryObject = query.getObject();
|
Object queryObject = query.getObject();
|
||||||
|
|
||||||
if (queryObject != null) {
|
if (queryObject != null) {
|
||||||
String id = StringUtils.hasText(query.getId()) ? getPersistentEntityId(queryObject) : query.getId();
|
String id = StringUtils.hasText(query.getId()) ? query.getId() : getPersistentEntityId(queryObject);
|
||||||
builder //
|
builder //
|
||||||
.id(id) //
|
.id(id) //
|
||||||
.document(elasticsearchConverter.mapObject(queryObject));
|
.document(elasticsearchConverter.mapObject(queryObject));
|
||||||
|
@ -128,6 +128,7 @@ import org.springframework.lang.Nullable;
|
|||||||
* @author Peer Mueller
|
* @author Peer Mueller
|
||||||
* @author Sijia Liu
|
* @author Sijia Liu
|
||||||
* @author Haibo Liu
|
* @author Haibo Liu
|
||||||
|
* @author scoobyzhang
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
public abstract class ElasticsearchIntegrationTests {
|
public abstract class ElasticsearchIntegrationTests {
|
||||||
@ -215,6 +216,26 @@ public abstract class ElasticsearchIntegrationTests {
|
|||||||
assertThatThrownBy(() -> operations.update(sampleEntity)).isInstanceOf(DataAccessException.class);
|
assertThatThrownBy(() -> operations.update(sampleEntity)).isInstanceOf(DataAccessException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // #2405
|
||||||
|
public void shouldNotIgnoreIdFromIndexQuery() {
|
||||||
|
String indexName = indexNameProvider.indexName();
|
||||||
|
IndexCoordinates indexCoordinates = IndexCoordinates.of(indexName);
|
||||||
|
|
||||||
|
SampleEntity object1 = SampleEntity.builder().id("objectId1").message("objectMessage1").build();
|
||||||
|
SampleEntity object2 = SampleEntity.builder().id("objectId2").message("objectMessage2").build();
|
||||||
|
List<IndexQuery> indexQueries = Arrays.asList(
|
||||||
|
new IndexQueryBuilder().withIndex(indexName).withId("idFromQuery1").withObject(object1)
|
||||||
|
.withOpType(IndexQuery.OpType.INDEX).build(),
|
||||||
|
new IndexQueryBuilder().withIndex(indexName).withId("idFromQuery2").withObject(object2)
|
||||||
|
.withOpType(IndexQuery.OpType.CREATE).build());
|
||||||
|
operations.bulkIndex(indexQueries, indexCoordinates);
|
||||||
|
|
||||||
|
boolean foundObject1 = operations.exists("idFromQuery1", indexCoordinates);
|
||||||
|
assertThat(foundObject1).isTrue();
|
||||||
|
boolean foundObject2 = operations.exists("idFromQuery2", indexCoordinates);
|
||||||
|
assertThat(foundObject2).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldThrowDataAccessExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
|
public void shouldThrowDataAccessExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user