本文整理汇总了Java中org.elasticsearch.action.search.MultiSearchResponse.getResponses方法的典型用法代码示例。如果您正苦于以下问题:Java MultiSearchResponse.getResponses方法的具体用法?Java MultiSearchResponse.getResponses怎么用?Java MultiSearchResponse.getResponses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.search.MultiSearchResponse
的用法示例。
在下文中一共展示了MultiSearchResponse.getResponses方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMultiSearch
import org.elasticsearch.action.search.MultiSearchResponse; //导入方法依赖的package包/类
@Test
public void testMultiSearch() throws Exception {
//first, INDEX two values
Map<String, Object> headers = new HashMap<String, Object>();
node.client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
node.client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
//now, verify MULTISEARCH
headers.put(ElasticsearchConstants.PARAM_OPERATION, ElasticsearchConstants.OPERATION_MULTISEARCH);
SearchRequestBuilder srb1 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "xxx"));
SearchRequestBuilder srb2 = node.client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.termQuery("field", "yyy"));
SearchRequestBuilder srb3 = node.client().prepareSearch("instagram")
.setTypes("type").setQuery(QueryBuilders.termQuery("test-multisearchkey", "test-multisearchvalue"));
List<SearchRequest> list = new ArrayList<>();
list.add(srb1.request());
list.add(srb2.request());
list.add(srb3.request());
MultiSearchResponse response = template.requestBodyAndHeaders("direct:multisearch", list, headers, MultiSearchResponse.class);
MultiSearchResponse.Item[] responses = response.getResponses();
assertNotNull("response should not be null", response);
assertEquals("response should contains three multiSearchResponse object", 3, response.getResponses().length);
assertFalse("response 1 should be ok", responses[0].isFailure());
assertFalse("response 2 should be ok", responses[1].isFailure());
assertTrue("response 3 should be failed", responses[2].isFailure());
}
示例2: testMultiSearch
import org.elasticsearch.action.search.MultiSearchResponse; //导入方法依赖的package包/类
@Test
public void testMultiSearch() {
// query string type
SearchRequestBuilder srb1 =
client.prepareSearch(indexShakeSpeare).setQuery(QueryBuilders.queryString("elephant"))
// size: 10 is the default
.setSize(10);
// match query type
SearchRequestBuilder srb2 =
client.prepareSearch(indexShakeSpeare)
.setQuery(QueryBuilders.matchQuery(fieldShakeSpeare, "havoc")).setSize(10);
// correlate the srbs
MultiSearchResponse sr = client.prepareMultiSearch().add(srb1).add(srb2).execute().actionGet();
// get all individual responses from MultiSearchResponse
long totalHits = 0;
for (MultiSearchResponse.Item item : sr.getResponses()) {
SearchResponse response = item.getResponse();
totalHits += response.getHits().getTotalHits();
}
System.out.println("Total matching for the elephant and havoc: " + totalHits);
}
示例3: testMultiSearch
import org.elasticsearch.action.search.MultiSearchResponse; //导入方法依赖的package包/类
private void testMultiSearch() {
SearchRequestBuilder srb1 = client.prepareSearch() //
.setQuery(QueryBuilders.queryString("elasticsearch")) //
.setSize(1);
SearchRequestBuilder srb2 = client.prepareSearch() //
.setQuery(QueryBuilders.matchQuery("name", "kimchy")) //
.setSize(1);
MultiSearchResponse sr = client.prepareMultiSearch() //
.add(srb1) //
.add(srb2) //
.execute() //
.actionGet();
// You will get all individual responses from
// MultiSearchResponse#responses()
long nbHits = 0;
for (MultiSearchResponse.Item item : sr.getResponses()) {
SearchResponse response = item.getResponse();
nbHits += response.getHits().totalHits();
}
}
示例4: testMultiSearch
import org.elasticsearch.action.search.MultiSearchResponse; //导入方法依赖的package包/类
@Test
public void testMultiSearch() {
SearchRequestBuilder srb1 = client.prepareSearch().setQuery(QueryBuilders.queryStringQuery("elasticsearch")).setSize(1);
SearchRequestBuilder srb2 = client.prepareSearch().setQuery(QueryBuilders.matchQuery("name", "kimchy")).setSize(1);
MultiSearchResponse sr = client.prepareMultiSearch().add(srb1).add(srb2).execute().actionGet();
// You will get all individual responses from
// MultiSearchResponse#getResponses()
long nbHits = 0;
for (MultiSearchResponse.Item item : sr.getResponses()) {
SearchResponse response = item.getResponse();
nbHits += response.getHits().getTotalHits();
}
}
示例5: multiSearch
import org.elasticsearch.action.search.MultiSearchResponse; //导入方法依赖的package包/类
/**
*
* @param queryString
*/
private static void multiSearch(String queryString){
Client client = createTransportClient();
SearchRequestBuilder srb1 = client.prepareSearch()
.setQuery(QueryBuilders.queryStringQuery(queryString));
SearchRequestBuilder srb2 = client.prepareSearch()
.setQuery(QueryBuilders.matchQuery("desc", queryString));
MultiSearchResponse sr = client.prepareMultiSearch()
.add(srb1)
.add(srb2)
.execute().actionGet();
long nbHits = 0;
for (MultiSearchResponse.Item item : sr.getResponses()) {
SearchResponse response = item.getResponse();
nbHits += response.getHits().getTotalHits();
System.out.println("本次查询共匹配到:"+nbHits+"记录");
SearchHits searchHits = response.getHits();
System.out.println("-----------------搜索关键字为:["+queryString+"]---------------------");
System.out.println("共匹配到:"+searchHits.getTotalHits()+"条记录!");
SearchHit[] hits = searchHits.getHits();
for (SearchHit searchHit : hits) {
Map<String, Object> sourceAsMap = searchHit.sourceAsMap();
Set<String> keySet = sourceAsMap.keySet();
for (String string : keySet) {
System.out.println(string+":"+sourceAsMap.get(string));
}
System.out.println();
}
}
}
示例6: processMultiSearchResponse
import org.elasticsearch.action.search.MultiSearchResponse; //导入方法依赖的package包/类
@Override
public SearchResultEventWithSearchRequestKey<FrequentlyRelatedSearchResult[]>[] processMultiSearchResponse(RelatedItemSearch[] searches,MultiSearchResponse searchResponse) {
int i = 0;
SearchResultEventWithSearchRequestKey[] results = new SearchResultEventWithSearchRequestKey[searches.length];
for(MultiSearchResponse.Item item : searchResponse.getResponses()) {
SearchRequestLookupKey key = searches[i].getLookupKey();
results[i] = frequentlyRelatedWithResultsConverter(key,item.getResponse(),item.getFailureMessage(),item.isFailure(),searches[i++].getStartOfRequestNanos());
}
return results;
}
示例7: testPercolatorQueryViaMultiSearch
import org.elasticsearch.action.search.MultiSearchResponse; //导入方法依赖的package包/类
public void testPercolatorQueryViaMultiSearch() throws Exception {
createIndex("test", client().admin().indices().prepareCreate("test")
.addMapping("type", "field1", "type=text")
.addMapping("queries", "query", "type=percolator")
);
client().prepareIndex("test", "queries", "1")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject())
.execute().actionGet();
client().prepareIndex("test", "queries", "2")
.setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject())
.execute().actionGet();
client().prepareIndex("test", "queries", "3")
.setSource(jsonBuilder().startObject().field("query", boolQuery()
.must(matchQuery("field1", "b"))
.must(matchQuery("field1", "c"))
).endObject())
.execute().actionGet();
client().prepareIndex("test", "queries", "4")
.setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject())
.execute().actionGet();
client().prepareIndex("test", "type", "1")
.setSource(jsonBuilder().startObject().field("field1", "c").endObject())
.execute().actionGet();
client().admin().indices().prepareRefresh().get();
MultiSearchResponse response = client().prepareMultiSearch()
.add(client().prepareSearch("test")
.setQuery(new PercolateQueryBuilder("query", "type",
jsonBuilder().startObject().field("field1", "b").endObject().bytes(), XContentType.JSON)))
.add(client().prepareSearch("test")
.setQuery(new PercolateQueryBuilder("query", "type",
yamlBuilder().startObject().field("field1", "c").endObject().bytes(), XContentType.JSON)))
.add(client().prepareSearch("test")
.setQuery(new PercolateQueryBuilder("query", "type",
smileBuilder().startObject().field("field1", "b c").endObject().bytes(), XContentType.JSON)))
.add(client().prepareSearch("test")
.setQuery(new PercolateQueryBuilder("query", "type",
jsonBuilder().startObject().field("field1", "d").endObject().bytes(), XContentType.JSON)))
.add(client().prepareSearch("test")
.setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "1", null, null, null)))
.add(client().prepareSearch("test") // non existing doc, so error element
.setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "2", null, null, null)))
.get();
MultiSearchResponse.Item item = response.getResponses()[0];
assertHitCount(item.getResponse(), 2L);
assertSearchHits(item.getResponse(), "1", "4");
assertThat(item.getFailureMessage(), nullValue());
item = response.getResponses()[1];
assertHitCount(item.getResponse(), 2L);
assertSearchHits(item.getResponse(), "2", "4");
assertThat(item.getFailureMessage(), nullValue());
item = response.getResponses()[2];
assertHitCount(item.getResponse(), 4L);
assertSearchHits(item.getResponse(), "1", "2", "3", "4");
assertThat(item.getFailureMessage(), nullValue());
item = response.getResponses()[3];
assertHitCount(item.getResponse(), 1L);
assertSearchHits(item.getResponse(), "4");
assertThat(item.getFailureMessage(), nullValue());
item = response.getResponses()[4];
assertHitCount(item.getResponse(), 2L);
assertSearchHits(item.getResponse(), "2", "4");
assertThat(item.getFailureMessage(), nullValue());
item = response.getResponses()[5];
assertThat(item.getResponse(), nullValue());
assertThat(item.getFailureMessage(), notNullValue());
assertThat(item.getFailureMessage(), equalTo("all shards failed"));
assertThat(ExceptionsHelper.unwrapCause(item.getFailure().getCause()).getMessage(),
containsString("[test/type/2] couldn't be found"));
}
示例8: execute
import org.elasticsearch.action.search.MultiSearchResponse; //导入方法依赖的package包/类
@Override
public void execute(Tuple input) {
_collector.ack(input);
// this bolt can be connected to anything
// we just want to trigger a new search when the input is a tick tuple
if (!TupleUtils.isTick(input)) {
return;
}
Status[] slist = new Status[] { Status.DISCOVERED, Status.ERROR,
Status.FETCH_ERROR, Status.FETCHED, Status.REDIRECTION };
MultiSearchRequestBuilder multi = connection.getClient()
.prepareMultiSearch();
// should be faster than running the aggregations
// sent as a single multisearch
for (Status s : slist) {
SearchRequestBuilder request = connection.getClient()
.prepareSearch(indexName).setTypes(docType).setFrom(0)
.setSize(0).setExplain(false);
request.setQuery(QueryBuilders.termQuery("status", s.name()));
multi.add(request);
}
long start = System.currentTimeMillis();
MultiSearchResponse response = multi.get();
long end = System.currentTimeMillis();
LOG.info("Multiquery returned in {} msec", end - start);
for (int i = 0; i < response.getResponses().length; i++) {
SearchResponse res = response.getResponses()[i].getResponse();
long total = res.getHits().getTotalHits();
latestStatusCounts.put(slist[i].name(), total);
}
}