当前位置: 首页>>代码示例>>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;未经允许,请勿转载。