Skip to content

Commit dc6734d

Browse files
authored
DATAES-839 - ReactiveElasticsearchTemplate should use RequestFactory.
Original PR: spring-projects#466
1 parent bcd7c2a commit dc6734d

File tree

6 files changed

+82
-163
lines changed

6 files changed

+82
-163
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.elasticsearch;
17+
18+
import org.springframework.dao.DataRetrievalFailureException;
19+
20+
import java.util.Map;
21+
22+
/**
23+
* @author Peter-Josef Meisch
24+
* @since 4.1
25+
*/
26+
public class BulkFailureException extends DataRetrievalFailureException {
27+
private final Map<String, String> failedDocuments;
28+
29+
public BulkFailureException(String msg, Map<String, String> failedDocuments) {
30+
super(msg);
31+
this.failedDocuments = failedDocuments;
32+
}
33+
34+
public Map<String, String> getFailedDocuments() {
35+
return failedDocuments;
36+
}
37+
}

src/main/java/org/springframework/data/elasticsearch/UncategorizedElasticsearchException.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @since 4.0
2323
*/
2424
public class UncategorizedElasticsearchException extends UncategorizedDataAccessException {
25+
2526
public UncategorizedElasticsearchException(String msg, Throwable cause) {
2627
super(msg, cause);
2728
}

src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.springframework.context.ApplicationContext;
3737
import org.springframework.context.ApplicationContextAware;
3838
import org.springframework.data.convert.EntityReader;
39-
import org.springframework.data.elasticsearch.ElasticsearchException;
39+
import org.springframework.data.elasticsearch.BulkFailureException;
4040
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
4141
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
4242
import org.springframework.data.elasticsearch.core.document.Document;
@@ -405,7 +405,7 @@ protected List<String> checkForBulkOperationFailure(BulkResponse bulkResponse) {
405405
if (item.isFailed())
406406
failedDocuments.put(item.getId(), item.getFailureMessage());
407407
}
408-
throw new ElasticsearchException(
408+
throw new BulkFailureException(
409409
"Bulk operation has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages ["
410410
+ failedDocuments + ']',
411411
failedDocuments);

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public String delete(String id, IndexCoordinates index) {
210210
Assert.notNull(id, "id must not be null");
211211
Assert.notNull(index, "index must not be null");
212212

213-
DeleteRequest request = new DeleteRequest(index.getIndexName(), elasticsearchConverter.convertId(id));
213+
DeleteRequest request = requestFactory.deleteRequest(elasticsearchConverter.convertId(id), index);
214214
return execute(client -> client.delete(request, RequestOptions.DEFAULT).getId());
215215
}
216216

0 commit comments

Comments
 (0)