Search in sources :

Example 1 with Item

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

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testMultiGet.

@Test
public void testMultiGet() throws Exception {
    //first, INDEX two values
    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");
    headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "1");
    template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    headers.clear();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "facebook");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "status");
    headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "2");
    template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    headers.clear();
    //now, verify MULTIGET
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchOperation.MULTIGET);
    Item item1 = new Item("twitter", "tweet", "1");
    Item item2 = new Item("facebook", "status", "2");
    Item item3 = new Item("instagram", "latest", "3");
    List<Item> list = new ArrayList<Item>();
    list.add(item1);
    list.add(item2);
    list.add(item3);
    MultiGetResponse response = template.requestBodyAndHeaders("direct:start", list, headers, MultiGetResponse.class);
    MultiGetItemResponse[] responses = response.getResponses();
    assertNotNull("response should not be null", response);
    assertEquals("response should contains three multiGetResponse object", 3, response.getResponses().length);
    assertEquals("response 1 should contains tweet as type", "tweet", responses[0].getResponse().getType().toString());
    assertEquals("response 2 should contains status as type", "status", responses[1].getResponse().getType().toString());
    assertFalse("response 1 should be ok", responses[0].isFailed());
    assertFalse("response 2 should be ok", responses[1].isFailed());
    assertTrue("response 3 should be failed", responses[2].isFailed());
}
Also used : Item(org.elasticsearch.action.get.MultiGetRequest.Item) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with Item

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

the class ElasticsearchActionRequestConverter method toMultiGetRequest.

@SuppressWarnings("unchecked")
@Converter
public static MultiGetRequest toMultiGetRequest(Object document, Exchange exchange) {
    List<Item> items = (List<Item>) document;
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    Iterator<Item> it = items.iterator();
    while (it.hasNext()) {
        MultiGetRequest.Item item = it.next();
        multiGetRequest.add(item);
    }
    return multiGetRequest;
}
Also used : Item(org.elasticsearch.action.get.MultiGetRequest.Item) List(java.util.List) Item(org.elasticsearch.action.get.MultiGetRequest.Item) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) Converter(org.apache.camel.Converter)

Example 3 with Item

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

the class ElasticsearchActionRequestConverter method toMultiGetRequest.

@Converter
public static MultiGetRequest toMultiGetRequest(Object document, Exchange exchange) {
    List<Item> items = (List<Item>) document;
    MultiGetRequest multiGetRequest = new MultiGetRequest();
    Iterator<Item> it = items.iterator();
    while (it.hasNext()) {
        MultiGetRequest.Item item = it.next();
        multiGetRequest.add(item);
    }
    return multiGetRequest;
}
Also used : Item(org.elasticsearch.action.get.MultiGetRequest.Item) List(java.util.List) Item(org.elasticsearch.action.get.MultiGetRequest.Item) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) Converter(org.apache.camel.Converter)

Example 4 with Item

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

the class ElasticsearchGetSearchDeleteExistsUpdateTest method testMultiGet.

@Test
public void testMultiGet() throws Exception {
    //first, INDEX two values
    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");
    headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "1");
    template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    headers.clear();
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_INDEX);
    headers.put(ElasticsearchConstants.PARAM_INDEX_NAME, "facebook");
    headers.put(ElasticsearchConstants.PARAM_INDEX_TYPE, "status");
    headers.put(ElasticsearchConstants.PARAM_INDEX_ID, "2");
    template.requestBodyAndHeaders("direct:start", map, headers, String.class);
    headers.clear();
    //now, verify MULTIGET
    headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTIGET);
    Item item1 = new Item("twitter", "tweet", "1");
    Item item2 = new Item("facebook", "status", "2");
    Item item3 = new Item("instagram", "latest", "3");
    List<Item> list = new ArrayList<Item>();
    list.add(item1);
    list.add(item2);
    list.add(item3);
    MultiGetResponse response = template.requestBodyAndHeaders("direct:start", list, headers, MultiGetResponse.class);
    MultiGetItemResponse[] responses = response.getResponses();
    assertNotNull("response should not be null", response);
    assertEquals("response should contains three multiGetResponse object", 3, response.getResponses().length);
    assertEquals("response 1 should contains tweet as type", "tweet", responses[0].getResponse().getType().toString());
    assertEquals("response 2 should contains status as type", "status", responses[1].getResponse().getType().toString());
    assertFalse("response 1 should be ok", responses[0].isFailed());
    assertFalse("response 2 should be ok", responses[1].isFailed());
    assertTrue("response 3 should be failed", responses[2].isFailed());
}
Also used : Item(org.elasticsearch.action.get.MultiGetRequest.Item) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetItemResponse(org.elasticsearch.action.get.MultiGetItemResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Item (org.elasticsearch.action.get.MultiGetRequest.Item)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Converter (org.apache.camel.Converter)2 MultiGetItemResponse (org.elasticsearch.action.get.MultiGetItemResponse)2 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)2 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)2 Test (org.junit.Test)2