You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2017/10/17 08:59:14 UTC

camel git commit: CAMEL-11915: Updating the documentation to follow the new component operations and types - Update operation pas the body object into the ElasticsearchActionRequestConverter.toUpdateRequest - Bulk operation pas the body object into the E

Repository: camel
Updated Branches:
  refs/heads/master ff0a1310a -> b3619ddb6


CAMEL-11915: Updating the documentation to follow the new component operations and types
- Update operation pas the body object into the
ElasticsearchActionRequestConverter.toUpdateRequest
- Bulk operation pas the body object into the
ElasticsearchActionRequestConverter.toBulkRequest
- Add missing query parameter for enable SSL. This is useful
if you want to point out a specific instance in the cluster for
specific routes


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b3619ddb
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b3619ddb
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b3619ddb

Branch: refs/heads/master
Commit: b3619ddb684c9539677890b0835491af3bee4bc3
Parents: ff0a131
Author: fharms <fl...@gmail.com>
Authored: Tue Oct 17 10:39:46 2017 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Oct 17 10:46:54 2017 +0200

----------------------------------------------------------------------
 .../docs/elasticsearch5-rest-component.adoc     | 101 +++++++++++++++----
 .../ElasticsearchConfiguration.java             |   3 +-
 .../elasticsearch5/ElasticsearchProducer.java   |   2 +-
 .../ElasticsearchActionRequestConverter.java    |   3 +
 4 files changed, 87 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b3619ddb/components/camel-elasticsearch5-rest/src/main/docs/elasticsearch5-rest-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5-rest/src/main/docs/elasticsearch5-rest-component.adoc b/components/camel-elasticsearch5-rest/src/main/docs/elasticsearch5-rest-component.adoc
index f17abaa..cbca9c6 100644
--- a/components/camel-elasticsearch5-rest/src/main/docs/elasticsearch5-rest-component.adoc
+++ b/components/camel-elasticsearch5-rest/src/main/docs/elasticsearch5-rest-component.adoc
@@ -12,7 +12,7 @@ for this component:
 ----
 <dependency>
     <groupId>org.apache.camel</groupId>
-    <artifactId>camel-elasticsearch5</artifactId>
+    <artifactId>camel-elasticsearch5-rest</artifactId>
     <version>x.x.x</version>
     <!-- use the same version as your Camel core version -->
 </dependency>
@@ -69,13 +69,14 @@ with the following path and query parameters:
 | *clusterName* | *Required* Name of the cluster |  | String
 |===
 
-==== Query Parameters (10 parameters):
+==== Query Parameters (11 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
 | *connectionTimeout* (producer) | The time in ms to wait before connection will timeout. | 30000 | int
 | *disconnect* (producer) | Disconnect after it finish calling the producer | false | boolean
+| *enableSSL* (producer) | Enable SSL | false | boolean
 | *hostAddresses* (producer) | *Required* Comma separated list with ip:port formatted remote transport addresses to use. The ip and port options must be left blank for hostAddresses to be considered instead. |  | String
 | *indexName* (producer) | The name of the index to act against |  | String
 | *indexType* (producer) | The type of the index to act against |  | String
@@ -99,40 +100,58 @@ other parameters or the message body to be set.
 |===
 |operation |message body |description
 
-|INDEX |Map, String, byte[] or XContentBuilder content to index |Adds content to an index and returns the content's indexId in the body.
+|Index |*Map*, *String*, *byte[]*, *XContentBuilder* or *IndexRequest* content to index |Adds content to an index and returns the content's indexId in the body.
 You can set the indexId by setting the message header with
 the key "indexId".
 
-|GET_BY_ID |index id of content to retrieve |Retrieves the specified index and returns a GetResult object in the body
+|GetById |*String* or *GetRequest* index id of content to retrieve |Retrieves the specified index and returns a GetResult object in the body
 
-|DELETE |index name and type of content to delete |Deletes the specified indexName and indexType and returns a DeleteResponse object in the
+|Delete |*String* or *DeleteRequest* index name and type of content to delete |Deletes the specified indexName and indexType and returns a DeleteResponse object in the
 body
 
-|DELETE_INDEX |index name of content to delete |Deletes the specified indexName and returns a DeleteIndexResponse object in the
+|DeleteIndex |*String* or *DeleteRequest* index name of the index to delete |Deletes the specified indexName and returns a status code the
 body
 
-|BULK_INDEX | a *List* or *Collection* of any type that is already accepted
+|BulkIndex | a *List*, *BulkRequest*, or *Collection* of any type that is already accepted
 (XContentBuilder, Map, byte[], String) |Adds content to an index and return a List of the id of the
 successfully indexed documents in the body
 
-|BULK |a *List* or *Collection* of any type that is already accepted
-(XContentBuilder, Map, byte[], String) |Adds content to an index and returns the BulkResponse
+|Bulk |a *List*, *BulkRequest*, or *Collection* of any type that is already accepted
+       (XContentBuilder, Map, byte[], String) |Adds content to an index and returns the BulkItemResponse[]
 object in the body
 
-|SEARCH |Map, String or SearchRequest Object |Search the content with the map of query string
+|Search |*Map*, *String* or *SearchRequest* |Search the content with the map of query string
 
-|MULTIGET |List of MultigetRequest.Item object |Retrieves the specified indexes, types etc. in
-MultigetRequest and returns a MultigetResponse object in the body
+|Exists |Index name(indexName) as header  |Checks the index exists or not and returns a Boolean flag in the body
 
-|MULTISEARCH |List of SearchRequest object |Search for parameters specified in MultiSearchRequest and
-returns a MultiSearchResponse object in the body
-
-|EXISTS |Index name as header |Checks the index exists or not and returns a Boolean flag in the body
-
-|UPDATE |Map, String, byte[] or XContentBuilder content to update |Updates content to an index and returns the content's
+|Update |*Map*, *UpdateRequest*, *String*, *byte[]* or *XContentBuilder* content to update |Updates content to an index and returns the content's
 indexId in the body.
 |===
 
+=== Configure the component and enable basic authentication
+To use the Elasticsearch component is has to be configured with a minimum configuration.
+
+[source,java]
+----
+ElasticsearchComponent elasticsearchComponent = new ElasticsearchComponent();
+elasticsearchComponent.setHostAddresses("myelkhost:9200");
+camelContext.addComponent("elasticsearch-rest", elasticsearchComponent);
+----
+
+For basic authentication with elasticsearch or using reverse http proxy in front of the elasticsearch cluster, simply setup
+basic authentication and SSL on the component like the example below
+
+[source,java]
+----
+ElasticsearchComponent elasticsearchComponent = new ElasticsearchComponent();
+elasticsearchComponent.setHostAddresses("myelkhost:9200");
+elasticsearchComponent.setUser("elkuser");
+elasticsearchComponent.setPassword("secure!!");
+elasticsearchComponent.setEnableSSL(true);
+
+camelContext.addComponent("elasticsearch-rest", elasticsearchComponent);
+----
+
 === Index Example
 
 Below is a simple INDEX example
@@ -140,14 +159,14 @@ Below is a simple INDEX example
 [source,java]
 ----
 from("direct:index")
-  .to("elasticsearch5-rest://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet");
+  .to("elasticsearch5-rest://elasticsearch?operation=Index&indexName=twitter&indexType=tweet");
 ----
 
 [source,xml]
 ----
 <route>
     <from uri="direct:index" />
-    <to uri="elasticsearch5-rest://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet"/>
+    <to uri="elasticsearch5-rest://elasticsearch?operation=Index&indexName=twitter&indexType=tweet"/>
 </route>
 ----
 
@@ -160,3 +179,45 @@ Map<String, String> map = new HashMap<String, String>();
 map.put("content", "test");
 String indexId = template.requestBody("direct:index", map, String.class);
 ----
+
+=== Search Example
+
+Searching on specific field(s) and value use the Operation ´Search´.
+Pass in the query JSON String or the Map
+
+[source,java]
+----
+from("direct:search")
+  .to("elasticsearch5-rest://elasticsearch?operation=Search&indexName=twitter&indexType=tweet");
+----
+
+[source,xml]
+----
+<route>
+    <from uri="direct:search" />
+    <to uri="eelasticsearch5-rest://elasticsearch?operation=Search&indexName=twitter&indexType=tweet"/>
+</route>
+----
+
+[source,java]
+----
+String query = "{\"query\":{\"match\":{\"content\":\"new release of ApacheCamel\"}}}";
+SearchHits response = template.requestBody("direct:search", query, SearchHits.class);
+
+----
+
+Search on specific field(s) using Map.
+
+[source,java]
+----
+Map<String, Object> actualQuery = new HashMap<>();
+actualQuery.put("content", "new release of ApacheCamel");
+
+Map<String, Object> match = new HashMap<>();
+match.put("match", actualQuery);
+
+Map<String, Object> query = new HashMap<>();
+query.put("query", match);
+SearchHits response = template.requestBody("direct:search", query, SearchHits.class);
+
+----

http://git-wip-us.apache.org/repos/asf/camel/blob/b3619ddb/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
index e1f109b..2d26990 100644
--- a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
+++ b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchConfiguration.java
@@ -49,10 +49,11 @@ public class ElasticsearchConfiguration {
     private int connectionTimeout = ElasticsearchConstants.DEFAULT_CONNECTION_TIMEOUT;
     @UriParam(defaultValue = "false")
     private boolean disconnect;
+    @UriParam(defaultValue = "false")
+    private boolean enableSSL;
 
     private String user;
     private String password;
-    private boolean enableSSL;
     //Sniffer parameter.
     private boolean enableSniffer;
     private int snifferInterval = ElasticsearchConstants.DEFAULT_SNIFFER_INTERVAL;

http://git-wip-us.apache.org/repos/asf/camel/blob/b3619ddb/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
index f87fb54..620174d 100644
--- a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
+++ b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/ElasticsearchProducer.java
@@ -160,7 +160,7 @@ public class ElasticsearchProducer extends DefaultProducer {
             IndexRequest indexRequest = ElasticsearchActionRequestConverter.toIndexRequest(message.getBody(), exchange);
             message.setBody(restHighLevelClient.index(indexRequest).getId());
         } else if (operation == ElasticsearchOperation.Update) {
-            UpdateRequest updateRequest = ElasticsearchActionRequestConverter.toUpdateRequest(message.getBody(Map.class), exchange);
+            UpdateRequest updateRequest = ElasticsearchActionRequestConverter.toUpdateRequest(message.getBody(), exchange);
             message.setBody(restHighLevelClient.update(updateRequest).getId());
         } else if (operation == ElasticsearchOperation.GetById) {
             GetRequest getRequest = ElasticsearchActionRequestConverter.toGetRequest(message.getBody(), exchange);

http://git-wip-us.apache.org/repos/asf/camel/blob/b3619ddb/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java
index bec9583..0d4cfe8 100644
--- a/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java
+++ b/components/camel-elasticsearch5-rest/src/main/java/org/apache/camel/component/elasticsearch5/converter/ElasticsearchActionRequestConverter.java
@@ -150,6 +150,9 @@ public final class ElasticsearchActionRequestConverter {
     }
 
     public static SearchRequest toSearchRequest(Object queryObject, Exchange exchange) throws IOException {
+        if (queryObject instanceof SearchRequest) {
+            return (SearchRequest) queryObject;
+        }
         SearchRequest searchRequest = new SearchRequest(exchange.getIn()
             .getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class))
             .types(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class));