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());
}
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;
}
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;
}
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());
}
Aggregations