[ 
https://issues.apache.org/jira/browse/CAMEL-12419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16425505#comment-16425505
 ] 

ASF GitHub Bot commented on CAMEL-12419:
----------------------------------------

oscerd closed pull request #2278: CAMEL-12419: camel-elasticsearch-rest should 
return complete bulk response instead of just ids
URL: https://github.com/apache/camel/pull/2278
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
 
b/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
index d2adc19fbd7..5e2dc94b9c4 100644
--- 
a/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
+++ 
b/components/camel-elasticsearch-rest/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchProducer.java
@@ -18,11 +18,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.net.UnknownHostException;
-import java.util.Arrays;
 import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import 
org.apache.camel.component.elasticsearch.converter.ElasticsearchActionRequestConverter;
@@ -35,7 +31,6 @@
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.elasticsearch.ElasticsearchStatusException;
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
-import org.elasticsearch.action.bulk.BulkItemResponse;
 import org.elasticsearch.action.bulk.BulkRequest;
 import org.elasticsearch.action.delete.DeleteRequest;
 import org.elasticsearch.action.get.GetRequest;
@@ -170,10 +165,7 @@ public void process(Exchange exchange) throws Exception {
             message.setBody(restHighLevelClient.bulk(bulkRequest).getItems());
         } else if (operation == ElasticsearchOperation.BulkIndex) {
             BulkRequest bulkRequest = 
ElasticsearchActionRequestConverter.toBulkRequest(message.getBody(), exchange);
-            List<String> indexedIds = 
Arrays.stream(restHighLevelClient.bulk(bulkRequest).getItems())
-                .map(BulkItemResponse::getId)
-                .collect(Collectors.toList());
-            message.setBody(indexedIds);
+            message.setBody(restHighLevelClient.bulk(bulkRequest).getItems());
         } else if (operation == ElasticsearchOperation.Delete) {
             DeleteRequest deleteRequest = 
ElasticsearchActionRequestConverter.toDeleteRequest(message.getBody(), 
exchange);
             
message.setBody(restHighLevelClient.delete(deleteRequest).getResult());
diff --git 
a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchBulkTest.java
 
b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchBulkTest.java
index 75a2a8a29a3..6d3e112277d 100644
--- 
a/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchBulkTest.java
+++ 
b/components/camel-elasticsearch-rest/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchBulkTest.java
@@ -20,22 +20,19 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.camel.builder.RouteBuilder;
 import org.elasticsearch.action.bulk.BulkItemResponse;
 import org.elasticsearch.action.bulk.BulkRequest;
 import org.elasticsearch.action.index.IndexRequest;
-import org.junit.Test;
-
 import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.hasItem;
 import static org.hamcrest.CoreMatchers.notNullValue;
+import org.junit.Test;
 
 public class ElasticsearchBulkTest extends ElasticsearchBaseTest {
 
     @Test
     public void testBulkIndex() throws Exception {
-        List<Map<String, String>> documents = new ArrayList<Map<String, 
String>>();
+        List<Map<String, String>> documents = new ArrayList<>();
         Map<String, String> document1 = createIndexedData("1");
         Map<String, String> document2 = createIndexedData("2");
 
@@ -76,12 +73,13 @@ public void bulkIndexRequestBody() throws Exception {
 
         // when
         @SuppressWarnings("unchecked")
-        List<String> indexedDocumentIds = 
template.requestBody("direct:bulk_index", request, List.class);
+        BulkItemResponse[] response = 
template.requestBody("direct:bulk_index", request, BulkItemResponse[].class);
 
         // then
-        assertThat(indexedDocumentIds, notNullValue());
-        assertThat(indexedDocumentIds.size(), equalTo(1));
-        assertThat(indexedDocumentIds, hasItem(prefix + "baz"));
+        assertThat(response, notNullValue());
+        assertThat(response.length, equalTo(1));
+        assertThat(response[0].isFailed(), equalTo(false));
+        assertThat(response[0].getId(), equalTo(prefix + "baz"));
     }
 
     @Test


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> camel-elasticsearch-rest should return complete bulk response instead of just 
> ids
> ---------------------------------------------------------------------------------
>
>                 Key: CAMEL-12419
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12419
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-elasticsearch-rest
>    Affects Versions: 2.21.0
>            Reporter: Ludovic Boutros
>            Priority: Major
>             Fix For: 2.21.1, 2.22.0
>
>
> Currently, when bulk indexing requests are used, only document ids are 
> returned in the exchange body.
> That not enough if you really want a good indexing failure management.
> Instead, it should return the complete bulk item response. 
> This way, we could get the exact error messages.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to