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


Java SearchResponse類代碼示例

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


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

示例1: minMaxQuery

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
private SearchResponse minMaxQuery(ScoreMode scoreMode, int minChildren, Integer maxChildren) throws SearchPhaseExecutionException {
    HasChildQueryBuilder hasChildQuery = hasChildQuery(
            "child",
            QueryBuilders.functionScoreQuery(constantScoreQuery(QueryBuilders.termQuery("foo", "two")),
                    new FunctionScoreQueryBuilder.FilterFunctionBuilder[]{
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(weightFactorFunction(1)),
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("foo", "three"), weightFactorFunction(1)),
                            new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("foo", "four"), weightFactorFunction(1))
                    }).boostMode(CombineFunction.REPLACE).scoreMode(FiltersFunctionScoreQuery.ScoreMode.SUM), scoreMode)
            .minMaxChildren(minChildren, maxChildren != null ? maxChildren : HasChildQueryBuilder.DEFAULT_MAX_CHILDREN);

    return client()
            .prepareSearch("test")
            .setQuery(hasChildQuery)
            .addSort("_score", SortOrder.DESC).addSort("id", SortOrder.ASC).get();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:ChildQuerySearchIT.java

示例2: testPostingsHighlighterFuzzyQuery

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testPostingsHighlighterFuzzyQuery() throws Exception {
    assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
    ensureGreen();

    client().prepareIndex("test", "type1")
        .setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
    refresh();

    for (String type : UNIFIED_AND_NULL) {
        logger.info("--> highlighting and searching on field2");
        SearchSourceBuilder source = searchSource().query(fuzzyQuery("field2", "quck"))
            .highlighter(highlight().field("field2").highlighterType(type));
        SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();

        assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:HighlighterSearchIT.java

示例3: testSingleValuedNumericValueScript

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testSingleValuedNumericValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(
                    cardinality("cardinality")
                            .precisionThreshold(precisionThreshold)
                            .field(singleNumericField())
                            .script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:CardinalityIT.java

示例4: deleteByQuery

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
/**
 * Delete documents using a query. Check what would be deleted first with a normal search query!
 * Elasticsearch once provided a native prepareDeleteByQuery method, but this was removed
 * in later versions. Instead, there is a plugin which iterates over search results,
 * see https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html
 * We simulate the same behaviour here without the need of that plugin.
 * 
 * @param q
 * @return delete document count
 */
public int deleteByQuery(String indexName, final QueryBuilder q) {
    Map<String, String> ids = new TreeMap<>();
    SearchResponse response = elasticsearchClient.prepareSearch(indexName).setSearchType(SearchType.QUERY_THEN_FETCH)
        .setScroll(new TimeValue(60000)).setQuery(q).setSize(100).execute().actionGet();
    while (true) {
        // accumulate the ids here, don't delete them right now to prevent an interference of the delete with the
        // scroll
        for (SearchHit hit : response.getHits().getHits()) {
            ids.put(hit.getId(), hit.getType());
        }
        response = elasticsearchClient.prepareSearchScroll(response.getScrollId()).setScroll(new TimeValue(600000))
            .execute().actionGet();
        // termination
        if (response.getHits().getHits().length == 0)
            break;
    }
    return deleteBulk(indexName, ids);
}
 
開發者ID:yacy,項目名稱:yacy_grid_mcp,代碼行數:29,代碼來源:ElasticsearchClient.java

示例5: assertNoDocCountError

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
private void assertNoDocCountError(int size, SearchResponse accurateResponse, SearchResponse testResponse) {
    Terms accurateTerms = accurateResponse.getAggregations().get("terms");
    assertThat(accurateTerms, notNullValue());
    assertThat(accurateTerms.getName(), equalTo("terms"));
    assertThat(accurateTerms.getDocCountError(), equalTo(0L));

    Terms testTerms = testResponse.getAggregations().get("terms");
    assertThat(testTerms, notNullValue());
    assertThat(testTerms.getName(), equalTo("terms"));
    assertThat(testTerms.getDocCountError(), equalTo(0L));
    Collection<Bucket> testBuckets = testTerms.getBuckets();
    assertThat(testBuckets.size(), lessThanOrEqualTo(size));
    assertThat(accurateTerms.getBuckets().size(), greaterThanOrEqualTo(testBuckets.size()));

    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket, notNullValue());
        Terms.Bucket accurateBucket = accurateTerms.getBucketByKey(testBucket.getKeyAsString());
        assertThat(accurateBucket, notNullValue());
        assertThat(accurateBucket.getDocCountError(), equalTo(0L));
        assertThat(testBucket.getDocCountError(), equalTo(0L));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:TermsDocCountErrorIT.java

示例6: testIndexDirIsDeletedWhenShardRemoved

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testIndexDirIsDeletedWhenShardRemoved() throws Exception {
    Environment env = getInstanceFromNode(Environment.class);
    Path idxPath = env.sharedDataFile().resolve(randomAsciiOfLength(10));
    logger.info("--> idxPath: [{}]", idxPath);
    Settings idxSettings = Settings.builder()
        .put(IndexMetaData.SETTING_DATA_PATH, idxPath)
        .build();
    createIndex("test", idxSettings);
    ensureGreen("test");
    client().prepareIndex("test", "bar", "1").setSource("{}", XContentType.JSON).setRefreshPolicy(IMMEDIATE).get();
    SearchResponse response = client().prepareSearch("test").get();
    assertHitCount(response, 1L);
    client().admin().indices().prepareDelete("test").get();
    assertAllIndicesRemovedAndDeletionCompleted(Collections.singleton(getInstanceFromNode(IndicesService.class)));
    assertPathHasBeenCleared(idxPath);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:IndexShardIT.java

示例7: testSingleValuedStringValueScript

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testSingleValuedStringValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(
                    cardinality("cardinality")
                            .precisionThreshold(precisionThreshold)
                            .field("str_value")
                            .script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:CardinalityIT.java

示例8: testPostingsHighlighterPrefixQuery

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testPostingsHighlighterPrefixQuery() throws Exception {
    assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
    ensureGreen();

    client().prepareIndex("test", "type1")
        .setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get();
    refresh();
    logger.info("--> highlighting and searching on field2");

    for (String type : UNIFIED_AND_NULL) {
        SearchSourceBuilder source = searchSource().query(prefixQuery("field2", "qui"))
            .highlighter(highlight().field("field2").highlighterType(type));
        SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
        assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The <em>quick</em> brown fox jumps over the lazy dog!"));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:HighlighterSearchIT.java

示例9: testThatCustomHighlighterReceivesFieldsInOrder

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testThatCustomHighlighterReceivesFieldsInOrder() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("test").setTypes("test")
            .setQuery(QueryBuilders.boolQuery().must(QueryBuilders.matchAllQuery()).should(QueryBuilders
                    .termQuery("name", "arbitrary")))
            .highlighter(
                    new HighlightBuilder().highlighterType("test-custom").field("name").field("other_name").field("other_other_name")
                            .useExplicitFieldOrder(true))
            .get();

    assertHighlight(searchResponse, 0, "name", 0, equalTo("standard response for name at position 1"));
    assertHighlight(searchResponse, 0, "other_name", 0, equalTo("standard response for other_name at position 2"));
    assertHighlight(searchResponse, 0, "other_other_name", 0, equalTo("standard response for other_other_name at position 3"));
    assertHighlight(searchResponse, 1, "name", 0, equalTo("standard response for name at position 1"));
    assertHighlight(searchResponse, 1, "other_name", 0, equalTo("standard response for other_name at position 2"));
    assertHighlight(searchResponse, 1, "other_other_name", 0, equalTo("standard response for other_other_name at position 3"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:CustomHighlighterSearchIT.java

示例10: testScoreRange

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testScoreRange() throws Exception {
    // all random scores should be in range [0.0, 1.0]
    createIndex("test");
    ensureGreen();
    int docCount = randomIntBetween(100, 200);
    for (int i = 0; i < docCount; i++) {
        String id = randomRealisticUnicodeOfCodepointLengthBetween(1, 50);
        index("test", "type", id, jsonBuilder().startObject().endObject());
    }
    flush();
    refresh();
    int iters = scaledRandomIntBetween(10, 20);
    for (int i = 0; i < iters; ++i) {
        int seed = randomInt();
        SearchResponse searchResponse = client().prepareSearch()
                .setQuery(functionScoreQuery(matchAllQuery(), randomFunction(seed)))
                .setSize(docCount)
                .execute().actionGet();

        assertNoFailures(searchResponse);
        for (SearchHit hit : searchResponse.getHits().getHits()) {
            assertThat(hit.getScore(), allOf(greaterThanOrEqualTo(0.0f), lessThanOrEqualTo(1.0f)));
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:RandomScoreFunctionIT.java

示例11: testPostingsHighlighterPrefixQueryWithinBooleanQuery

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testPostingsHighlighterPrefixQueryWithinBooleanQuery() throws Exception {
    assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()));
    ensureGreen();

    client().prepareIndex("test", "type1").setSource("field1", "The photography word will get highlighted").get();
    refresh();

    for (String type : UNIFIED_AND_NULL) {
        logger.info("--> highlighting and searching on field1");
        SearchSourceBuilder source = searchSource()
            .query(boolQuery().must(prefixQuery("field1", "photo")).should(matchQuery("field1", "test").minimumShouldMatch("0")))
            .highlighter(highlight().field("field1").highlighterType(type));
        SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get();
        assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("The <em>photography</em> word will get highlighted"));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:HighlighterSearchIT.java

示例12: testMatchQueryNumeric

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testMatchQueryNumeric() throws Exception {
    assertAcked(prepareCreate("test").addMapping("type1", "long", "type=long", "double", "type=double"));

    indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("long", 1L, "double", 1.0d),
            client().prepareIndex("test", "type1", "2").setSource("long", 2L, "double", 2.0d),
            client().prepareIndex("test", "type1", "3").setSource("long", 3L, "double", 3.0d));

    SearchResponse searchResponse = client().prepareSearch().setQuery(matchQuery("long", "1")).get();
    assertHitCount(searchResponse, 1L);
    assertFirstHit(searchResponse, hasId("1"));

    searchResponse = client().prepareSearch().setQuery(matchQuery("double", "2")).get();
    assertHitCount(searchResponse, 1L);
    assertFirstHit(searchResponse, hasId("2"));
    expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch().setQuery(matchQuery("double", "2 3 4")).get());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:SearchQueryIT.java

示例13: testSingleValuedFieldOrderedBySubAggregationAsc

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testSingleValuedFieldOrderedBySubAggregationAsc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.aggregation("sum", true))
                    .subAggregation(max("sum").field("value")))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    assertThat(histo.getBuckets().size(), equalTo(3));

    int i = 0;
    for (Histogram.Bucket bucket : histo.getBuckets()) {
        assertThat(((DateTime) bucket.getKey()), equalTo(new DateTime(2012, i + 1, 1, 0, 0, DateTimeZone.UTC)));
        i++;
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:DateHistogramIT.java

示例14: testSingleValuedFieldOrderedByKeyAsc

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
public void testSingleValuedFieldOrderedByKeyAsc() throws Exception {
    SearchResponse response = client().prepareSearch("idx")
            .addAggregation(dateHistogram("histo")
                    .field("date")
                    .dateHistogramInterval(DateHistogramInterval.MONTH)
                    .order(Histogram.Order.KEY_ASC))
            .execute().actionGet();

    assertSearchResponse(response);

    Histogram histo = response.getAggregations().get("histo");
    assertThat(histo, notNullValue());
    assertThat(histo.getName(), equalTo("histo"));
    List<? extends Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    int i = 0;
    for (Histogram.Bucket bucket : buckets) {
        assertThat(((DateTime) bucket.getKey()), equalTo(new DateTime(2012, i + 1, 1, 0, 0, DateTimeZone.UTC)));
        i++;
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:DateHistogramIT.java

示例15: testUnmapped

import org.elasticsearch.action.search.SearchResponse; //導入依賴的package包/類
@Override
public void testUnmapped() throws Exception {
    int sigDigits = randomSignificantDigits();
    SearchResponse searchResponse = client()
            .prepareSearch("idx_unmapped")
            .setQuery(matchAllQuery())
            .addAggregation(
                    percentileRanks("percentile_ranks").method(PercentilesMethod.HDR).numberOfSignificantValueDigits(sigDigits)
                    .field("value").values(0, 10, 15, 100))
            .execute().actionGet();

    assertThat(searchResponse.getHits().getTotalHits(), equalTo(0L));

    PercentileRanks reversePercentiles = searchResponse.getAggregations().get("percentile_ranks");
    assertThat(reversePercentiles, notNullValue());
    assertThat(reversePercentiles.getName(), equalTo("percentile_ranks"));
    assertThat(reversePercentiles.percent(0), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(10), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(15), equalTo(Double.NaN));
    assertThat(reversePercentiles.percent(100), equalTo(Double.NaN));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:HDRPercentileRanksIT.java


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