Search in sources :

Example 1 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testDeleteWithHeaders.

@Test
public void testDeleteWithHeaders() throws Exception {
    //first, INDEX a value
    Map<String, String> map = createIndexedData();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
    String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    //now, verify GET
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GET_BY_ID);
    GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNotNull("response source should not be null", response.getSource());
    //now, perform DELETE
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.DELETE);
    DeleteResponse deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DeleteResponse.class);
    assertNotNull("response should not be null", deleteResponse);
    //now, verify GET fails to find the indexed value
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.GET_BY_ID);
    response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNull("response source should be null", response.getSource());
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) HashMap(java.util.HashMap) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 2 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testDelete.

@Test
public void testDelete() throws Exception {
    //first, INDEX a value
    Map<String, String> map = createIndexedData();
    sendBody("direct:index", map);
    String indexId = template.requestBody("direct:index", map, String.class);
    assertNotNull("indexId should be set", indexId);
    //now, verify GET succeeded
    GetResponse response = template.requestBody("direct:get", indexId, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNotNull("response source should not be null", response.getSource());
    //now, perform DELETE
    DeleteResponse deleteResponse = template.requestBody("direct:delete", indexId, DeleteResponse.class);
    assertNotNull("response should not be null", deleteResponse);
    //now, verify GET fails to find the indexed value
    response = template.requestBody("direct:get", indexId, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNull("response source should be null", response.getSource());
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 3 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testDeleteWithHeaders.

@Test
public void testDeleteWithHeaders() throws Exception {
    //first, INDEX a value
    Map<String, String> map = createIndexedData();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "twitter");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "tweet");
    String indexId = template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    //now, verify GET
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
    GetResponse response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNotNull("response source should not be null", response.getSource());
    //now, perform DELETE
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_DELETE);
    DeleteResponse deleteResponse = template.requestBodyAndHeaders("direct:start", indexId, headers, DeleteResponse.class);
    assertNotNull("response should not be null", deleteResponse);
    //now, verify GET fails to find the indexed value
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_GET_BY_ID);
    response = template.requestBodyAndHeaders("direct:start", indexId, headers, GetResponse.class);
    assertNotNull("response should not be null", response);
    assertNull("response source should be null", response.getSource());
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) HashMap(java.util.HashMap) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 4 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project camel by apache.

the class ElasticsearchGetSearchDeleteExistsUpdateTest method getRequestBody.

@Test
public void getRequestBody() throws Exception {
    String prefix = createPrefix();
    // given
    GetRequest request = new GetRequest(prefix + "foo").type(prefix + "bar");
    // when
    String documentId = template.requestBody("direct:index", new IndexRequest(prefix + "foo", prefix + "bar", prefix + "testId").source("{\"" + prefix + "content\": \"" + prefix + "hello\"}"), String.class);
    GetResponse response = template.requestBody("direct:get", request.id(documentId), GetResponse.class);
    // then
    assertThat(response, notNullValue());
    assertThat(prefix + "hello", equalTo(response.getSourceAsMap().get(prefix + "content")));
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) Test(org.junit.Test)

Example 5 with GetResponse

use of org.elasticsearch.action.get.GetResponse in project storm by apache.

the class EsLookupBolt method lookupValuesInEs.

private Collection<Values> lookupValuesInEs(Tuple tuple) {
    GetRequest request = getRequest.extractFrom(tuple);
    GetResponse response = client.get(request).actionGet();
    return output.toValues(response);
}
Also used : GetRequest(org.elasticsearch.action.get.GetRequest) ElasticsearchGetRequest(org.apache.storm.elasticsearch.ElasticsearchGetRequest) GetResponse(org.elasticsearch.action.get.GetResponse)

Aggregations

GetResponse (org.elasticsearch.action.get.GetResponse)84 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)22 Test (org.junit.Test)18 SearchResponse (org.elasticsearch.action.search.SearchResponse)12 HashMap (java.util.HashMap)11 GetRequest (org.elasticsearch.action.get.GetRequest)11 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)10 Script (org.elasticsearch.script.Script)9 Settings (org.elasticsearch.common.settings.Settings)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 IOException (java.io.IOException)7 Map (java.util.Map)7 Alias (org.elasticsearch.action.admin.indices.alias.Alias)7 CompiledScript (org.elasticsearch.script.CompiledScript)7 ExecutableScript (org.elasticsearch.script.ExecutableScript)7 SearchScript (org.elasticsearch.script.SearchScript)7 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)6 IndexResponse (org.elasticsearch.action.index.IndexResponse)5 VersionConflictEngineException (org.elasticsearch.index.engine.VersionConflictEngineException)5 Path (java.nio.file.Path)4