當前位置: 首頁>>代碼示例>>Java>>正文


Java MultiSearchResponse.Item方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.search.MultiSearchResponse.Item方法的典型用法代碼示例。如果您正苦於以下問題:Java MultiSearchResponse.Item方法的具體用法?Java MultiSearchResponse.Item怎麽用?Java MultiSearchResponse.Item使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.search.MultiSearchResponse的用法示例。


在下文中一共展示了MultiSearchResponse.Item方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSimpleMultiSearchMoreRequests

import org.elasticsearch.action.search.MultiSearchResponse; //導入方法依賴的package包/類
public void testSimpleMultiSearchMoreRequests() {
    createIndex("test");
    int numDocs = randomIntBetween(0, 16);
    for (int i = 0; i < numDocs; i++) {
        client().prepareIndex("test", "type", Integer.toString(i)).setSource("{}", XContentType.JSON).get();
    }
    refresh();

    int numSearchRequests = randomIntBetween(1, 64);
    MultiSearchRequest request = new MultiSearchRequest();
    if (randomBoolean()) {
        request.maxConcurrentSearchRequests(randomIntBetween(1, numSearchRequests));
    }
    for (int i = 0; i < numSearchRequests; i++) {
        request.add(client().prepareSearch("test"));
    }

    MultiSearchResponse response = client().multiSearch(request).actionGet();
    assertThat(response.getResponses().length, equalTo(numSearchRequests));
    for (MultiSearchResponse.Item item : response) {
        assertNoFailures(item.getResponse());
        assertHitCount(item.getResponse(), numDocs);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:MultiSearchIT.java

示例2: testSimpleMultiSearch

import org.elasticsearch.action.search.MultiSearchResponse; //導入方法依賴的package包/類
public void testSimpleMultiSearch() {
    createIndex("test");
    ensureGreen();
    client().prepareIndex("test", "type", "1").setSource("field", "xxx").execute().actionGet();
    client().prepareIndex("test", "type", "2").setSource("field", "yyy").execute().actionGet();
    refresh();
    MultiSearchResponse response = client().prepareMultiSearch()
            .add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "xxx")))
            .add(client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "yyy")))
            .add(client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()))
            .execute().actionGet();

    for (MultiSearchResponse.Item item : response) {
       assertNoFailures(item.getResponse());
    }
    assertThat(response.getResponses().length, equalTo(3));
    assertHitCount(response.getResponses()[0].getResponse(), 1L);
    assertHitCount(response.getResponses()[1].getResponse(), 1L);
    assertHitCount(response.getResponses()[2].getResponse(), 2L);
    assertFirstHit(response.getResponses()[0].getResponse(), hasId("1"));
    assertFirstHit(response.getResponses()[1].getResponse(), hasId("2"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:MultiSearchIT.java

示例3: 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());
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:27,代碼來源:ElasticsearchGetSearchDeleteExistsUpdateTest.java

示例4: 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);
}
 
開發者ID:destiny1020,項目名稱:elasticsearch-java-client-examples,代碼行數:26,代碼來源:SearchApiOfficial.java

示例5: 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();
        }

    }
 
開發者ID:xuzhikethinker,項目名稱:t4f-data,代碼行數:26,代碼來源:ElasticSearchTest.java

示例6: 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();
    }
}
 
開發者ID:dzh,項目名稱:jframe,代碼行數:16,代碼來源:TestTransportClient.java

示例7: 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();
		}
	}
}
 
開發者ID:ameizi,項目名稱:elasticsearch-jest-example,代碼行數:37,代碼來源:TransportClient.java

示例8: 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;
}
 
開發者ID:tootedom,項目名稱:related,代碼行數:12,代碼來源:ElasticSearchFrequentlyRelatedItemSearchProcessor.java

示例9: 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"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:78,代碼來源:PercolatorQuerySearchIT.java

示例10: testProfileMatchesRegular

import org.elasticsearch.action.search.MultiSearchResponse; //導入方法依賴的package包/類
/**
 * This test generates 1-10 random queries and executes a profiled and non-profiled
 * search for each query.  It then does some basic sanity checking of score and hits
 * to make sure the profiling doesn't interfere with the hits being returned
 */
public void testProfileMatchesRegular() throws Exception {
    createIndex("test");
    ensureGreen();

    int numDocs = randomIntBetween(100, 150);
    IndexRequestBuilder[] docs = new IndexRequestBuilder[numDocs];
    for (int i = 0; i < numDocs; i++) {
        docs[i] = client().prepareIndex("test", "type1", String.valueOf(i)).setSource(
                "field1", English.intToEnglish(i),
                "field2", i
        );
    }

    List<String> stringFields = Arrays.asList("field1");
    List<String> numericFields = Arrays.asList("field2");

    indexRandom(true, docs);

    refresh();
    int iters = between(1, 10);
    for (int i = 0; i < iters; i++) {
        QueryBuilder q = randomQueryBuilder(stringFields, numericFields, numDocs, 3);
        logger.info("Query: {}", q);

        SearchRequestBuilder vanilla = client().prepareSearch("test")
                .setQuery(q)
                .setProfile(false)
                .addSort("_uid", SortOrder.ASC)
                .setPreference("_primary")
                .setSearchType(SearchType.QUERY_THEN_FETCH);

        SearchRequestBuilder profile = client().prepareSearch("test")
                .setQuery(q)
                .setProfile(true)
                .addSort("_uid", SortOrder.ASC)
                .setPreference("_primary")
                .setSearchType(SearchType.QUERY_THEN_FETCH);

        MultiSearchResponse.Item[] responses = client().prepareMultiSearch()
                .add(vanilla)
                .add(profile)
                .execute().actionGet().getResponses();

        SearchResponse vanillaResponse = responses[0].getResponse();
        SearchResponse profileResponse = responses[1].getResponse();

        float vanillaMaxScore = vanillaResponse.getHits().getMaxScore();
        float profileMaxScore = profileResponse.getHits().getMaxScore();
        if (Float.isNaN(vanillaMaxScore)) {
            assertTrue("Vanilla maxScore is NaN but Profile is not [" + profileMaxScore + "]",
                    Float.isNaN(profileMaxScore));
        } else {
            assertTrue("Profile maxScore of [" + profileMaxScore + "] is not close to Vanilla maxScore [" + vanillaMaxScore + "]",
                    nearlyEqual(vanillaMaxScore, profileMaxScore, 0.001));
        }

        assertThat(
                "Profile totalHits of [" + profileResponse.getHits().getTotalHits() + "] is not close to Vanilla totalHits ["
                        + vanillaResponse.getHits().getTotalHits() + "]",
                vanillaResponse.getHits().getTotalHits(), equalTo(profileResponse.getHits().getTotalHits()));

        SearchHit[] vanillaHits = vanillaResponse.getHits().getHits();
        SearchHit[] profileHits = profileResponse.getHits().getHits();

        for (int j = 0; j < vanillaHits.length; j++) {
            assertThat("Profile hit #" + j + " has a different ID from Vanilla",
                vanillaHits[j].getId(), equalTo(profileHits[j].getId()));
        }

    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:77,代碼來源:QueryProfilerIT.java

示例11: CoordinateMultiSearchResponse

import org.elasticsearch.action.search.MultiSearchResponse; //導入方法依賴的package包/類
CoordinateMultiSearchResponse() {
  // hack: empty constructor is private, use this one instead
  // we use an empty array to avoid NPE during serialization
  super(new MultiSearchResponse.Item[0]);
}
 
開發者ID:sirensolutions,項目名稱:siren-join,代碼行數:6,代碼來源:CoordinateMultiSearchResponse.java

示例12: iterator

import org.elasticsearch.action.search.MultiSearchResponse; //導入方法依賴的package包/類
@Override
public Iterator<MultiSearchResponse.Item> iterator() {
  return Iterators.forArray((MultiSearchResponse.Item[]) items);
}
 
開發者ID:sirensolutions,項目名稱:siren-join,代碼行數:5,代碼來源:CoordinateMultiSearchResponse.java

示例13: allReader

import org.elasticsearch.action.search.MultiSearchResponse; //導入方法依賴的package包/類
public void allReader(ElastisearchCrawlerMultipleHits crawler) throws Exception {
	try {
		MultiSearchResponse.Item[] items = Elasticsearch.withRetry(new ElasticsearchWithRetry<Item[]>() {
			public Item[] call(Client client) throws NoNodeAvailableException {
				MultiSearchRequestBuilder multisearchrequestbuilder = new MultiSearchRequestBuilder(client);
				for (int pos = 0; pos < queries.size(); pos++) {
					multisearchrequestbuilder.add(queries.get(pos).getRequest());
				}
				return multisearchrequestbuilder.execute().actionGet().getResponses();
			}
		});
		
		SearchHit[] hits;
		SearchResponse response;
		for (int pos_response = 0; pos_response < items.length; pos_response++) {
			if (items[pos_response].isFailure()) {
				Loggers.ElasticSearch.warn("Search failed", new Exception(items[pos_response].getFailureMessage()));
				continue;
			}
			response = items[pos_response].getResponse();
			if (response == null) {
				continue;
			}
			if (response.getHits() == null) {
				continue;
			}
			hits = response.getHits().hits();
			if (hits.length == 0) {
				continue;
			}
			if (crawler.onMultipleResponse(response, Arrays.asList(hits)) == false) {
				return;
			}
		}
	} catch (IndexMissingException ime) {
		/**
		 * No items == no callbacks
		 */
		Loggers.ElasticSearch.debug("Index missing", ime);
		return;
	} catch (SearchPhaseExecutionException e) {
		Loggers.ElasticSearch.debug("No datas", e);
	}
}
 
開發者ID:hdsdi3g,項目名稱:MyDMAM,代碼行數:45,代碼來源:ElastisearchMultipleCrawlerReader.java


注:本文中的org.elasticsearch.action.search.MultiSearchResponse.Item方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。