es批量搜索

    xiaoxiao2021-03-25  164

    TermsBuilder termsBuilder = AggregationBuilders.terms("events") .field("eventId").include(eventIds); FilterAggregationBuilder filterAggregationBuilder = AggregationBuilders.filter("hit") .filter(QueryBuilders.termQuery("hit", "1")); termsBuilder.subAggregation(filterAggregationBuilder); termsBuilder.subAggregation(AggregationBuilders.terms("hitPunish").field("hitPunish") .size(0) .order(Order.term(true))); termsBuilder.subAggregation(AggregationBuilders.terms("hitExps").field("hitExps") .size(0) .order(Order.term(true))); RangeQueryBuilder nowRangeQuery = QueryBuilders.rangeQuery("requestTime") .gte(1486921330000L) .lte(1486921457000L) .format("epoch_millis") ; RangeQueryBuilder yoyRangeQuery = QueryBuilders.rangeQuery("requestTime") .gte(1486921457000L) .lte(1486947847000L) .format("epoch_millis") ; RangeQueryBuilder momRangeQuery = QueryBuilders.rangeQuery("requestTime") .gte(1486947847000L) .lte(1486947999000L) .format("epoch_millis") ; RangeQueryBuilder[] rangeQueryBuilders = new RangeQueryBuilder[] {nowRangeQuery, yoyRangeQuery, momRangeQuery}; MultiSearchRequestBuilder multiSearchRequestBuilder = client.prepareMultiSearch(); for(RangeQueryBuilder rangeQueryBuilder: rangeQueryBuilders) { SearchRequestBuilder searchRequestBuilder = client.prepareSearch("minos2log*") .setQuery(rangeQueryBuilder) .addAggregation(termsBuilder) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setSize(0); multiSearchRequestBuilder.add(searchRequestBuilder); } MultiSearchResponse multiSearchResponse =multiSearchRequestBuilder.execute().actionGet(); return multiSearchResponse.toString();
    转载请注明原文地址: https://ju.6miu.com/read-2193.html

    最新回复(0)