org.apache.camel.component.elasticsearch.ElasticsearchConstants Java Examples
The following examples show how to use
org.apache.camel.component.elasticsearch.ElasticsearchConstants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElasticsearchRestResource.java From camel-quarkus with Apache License 2.0 | 5 votes |
@Path("/update") @PATCH @Produces(MediaType.TEXT_PLAIN) public Response updateData(@QueryParam("indexId") String indexId, String indexValue) throws Exception { Map<String, String> data = createIndexedData(indexValue); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_INDEX_ID, indexId); producerTemplate.requestBodyAndHeaders("elasticsearch-rest://elasticsearch?operation=Update&indexName=test", data, headers); return Response.ok().build(); }
Example #2
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testUpdate() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:index") .to("elasticsearch-rest://elasticsearch?operation=Index&indexName=twitter&hostAddresses=" + getElasticsearchHost()); from("direct:update") .to("elasticsearch-rest://elasticsearch?operation=Update&indexName=twitter&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); Map<String, String> map = createIndexedData("testUpdate"); String indexId = template.requestBody("direct:index", map, String.class); Assert.assertNotNull("indexId should be set", indexId); Map<String, String> newMap = new HashMap<>(); newMap.put(PREFIX + "key2", PREFIX + "value2"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_INDEX_ID, indexId); indexId = template.requestBodyAndHeaders("direct:update", newMap, headers, String.class); Assert.assertNotNull("indexId should be set", indexId); } finally { camelctx.close(); } }
Example #3
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testGetWithHeaders() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); //first, Index a value Map<String, String> map = createIndexedData("testGetWithHeaders"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class); //now, verify GET headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GetById); GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class); Assert.assertNotNull("response should not be null", response); Assert.assertNotNull("response source should not be null", response.getSource()); } finally { camelctx.close(); } }
Example #4
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testExistsWithHeaders() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); from("direct:exists") .to("elasticsearch-rest://elasticsearch?operation=Exists&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); //first, Index a value Map<String, String> map = createIndexedData("testExistsWithHeaders"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); template.requestBodyAndHeaders("direct:start", map, headers, String.class); //now, verify GET headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Exists); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); Boolean exists = template.requestBodyAndHeaders("direct:exists", "", headers, Boolean.class); Assert.assertNotNull("response should not be null", exists); Assert.assertTrue("Index should exist", exists); } finally { camelctx.close(); } }
Example #5
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testNotExistsWithHeaders() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); from("direct:exists") .to("elasticsearch-rest://elasticsearch?operation=Exists&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); //first, Index a value Map<String, String> map = createIndexedData("testNotExistsWithHeaders"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); template.requestBodyAndHeaders("direct:start", map, headers, String.class); //now, verify GET headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Exists); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter-tweet"); Boolean exists = template.requestBodyAndHeaders("direct:exists", "", headers, Boolean.class); Assert.assertNotNull("response should not be null", exists); Assert.assertFalse("Index should not exist", exists); } finally { camelctx.close(); } }
Example #6
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testUpdateWithIDInHeader() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); Map<String, String> map = createIndexedData("testUpdateWithIDInHeader"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "123"); String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class); Assert.assertNotNull("indexId should be set", indexId); Assert.assertEquals("indexId should be equals to the provided id", "123", indexId); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Update); indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class); Assert.assertNotNull("indexId should be set", indexId); Assert.assertEquals("indexId should be equals to the provided id", "123", indexId); } finally { camelctx.close(); } }
Example #7
Source File: ElasticsearchIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testDeleteWithHeaders() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .to("elasticsearch-rest://elasticsearch?operation=Index&hostAddresses=" + getElasticsearchHost()); from("direct:delete") .to("elasticsearch-rest://elasticsearch?operation=Delete&indexName=twitter&hostAddresses=" + getElasticsearchHost()); } }); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); //first, Index a value Map<String, String> map = createIndexedData("testDeleteWithHeaders"); Map<String, Object> headers = new HashMap<>(); headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Index); headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter"); String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class); //now, verify GET headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GetById); GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class); Assert.assertNotNull("response should not be null", response); Assert.assertNotNull("response source should not be null", response.getSource()); //now, perform Delete headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.Delete); DocWriteResponse.Result deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DocWriteResponse.Result.class); Assert.assertEquals("response should not be null", DocWriteResponse.Result.DELETED, deleteResponse); //now, verify GET fails to find the indexed value headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GetById); response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class); Assert.assertNotNull("response should not be null", response); Assert.assertNull("response source should be null", response.getSource()); } finally { camelctx.close(); } }