This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch camel-2.21.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit b7ab8f553a71269318c844840b12ba0d09234704 Author: lbout...@jouve.com <lbout...@jouve.com> AuthorDate: Wed Apr 4 15:04:35 2018 +0200 CAMEL-12419 - camel-elasticsearch-rest, return the complete bulk index item response to the exchange body --- .../component/elasticsearch/ElasticsearchProducer.java | 11 ++--------- .../component/elasticsearch/ElasticsearchBulkTest.java | 16 +++++++--------- 2 files changed, 9 insertions(+), 18 deletions(-) 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 349a63a..8a224bd 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,8 @@ package org.apache.camel.component.elasticsearch; import java.lang.reflect.InvocationTargetException; import java.net.UnknownHostException; -import java.util.Arrays; import java.util.Collections; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import org.apache.camel.Exchange; import org.apache.camel.Message; @@ -36,7 +33,6 @@ import org.apache.http.client.CredentialsProvider; 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; @@ -171,10 +167,7 @@ public class ElasticsearchProducer extends DefaultProducer { 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()); @@ -303,4 +296,4 @@ public class ElasticsearchProducer extends DefaultProducer { super(restClient, (client) -> { }, Collections.emptyList()); } } -} \ No newline at end of file +} 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 75a2a8a..6d3e112 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.ArrayList; 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 class ElasticsearchBulkTest extends ElasticsearchBaseTest { // 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 -- To stop receiving notification emails like this one, please contact acosent...@apache.org.