.size(350) .sort(SortBuilders.fieldSort(FieldSortBuilder.DOC_FIELD_NAME)) .toString();
searchSourceBuilder.query(queryBuilder); searchSourceBuilder.from(start); searchSourceBuilder.size(size);
final String query = searchSource() .aggregation(builder) .size(0) .toString();
&& sr.source().aggregations().getAggregatorFactories() != null && sr.source().aggregations().getAggregatorFactories().size() == 1 && sr.source().size() == 0) { AggregationBuilder ab = sr.source().aggregations().getAggregatorFactories().iterator().next(); if( ab instanceof TermsAggregationBuilder
searchSourceBuilder.size(limit);
private long totalCount(final String[] indexNames) { // Return 0 if there are no indices in the given index set. If we run the query with an empty index list, // Elasticsearch will count all documents in all indices and thus return a wrong count. if (indexNames.length == 0) { return 0L; } final List<String> indices = Arrays.asList(indexNames); final String query = new SearchSourceBuilder() .query(QueryBuilders.matchAllQuery()) .size(0) .toString(); final Search request = new Search.Builder(query) .addIndex(indices) .build(); final MultiSearch multiSearch = new MultiSearch.Builder(request).build(); final MultiSearchResult searchResult = JestUtils.execute(jestClient, multiSearch, () -> "Fetching message count failed for indices " + indices); final List<MultiSearchResult.MultiSearchResponse> responses = searchResult.getResponses(); long total = 0L; for (MultiSearchResult.MultiSearchResponse response : responses) { if (response.isError) { throw JestUtils.specificException(() -> "Fetching message count failed for indices " + indices, response.error); } total += response.searchResult.getTotal(); } return total; } }
private SearchRequest prepareScroll(Query query, long scrollTimeInMillis) { SearchRequest request = new SearchRequest(toArray(query.getIndices())); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); request.types(toArray(query.getTypes())); request.scroll(TimeValue.timeValueMillis(scrollTimeInMillis)); if (query.getPageable().isPaged()) { searchSourceBuilder.size(query.getPageable().getPageSize()); } if (!isEmpty(query.getFields())) { searchSourceBuilder.fetchSource(toArray(query.getFields()), null); } request.source(searchSourceBuilder); return request; }
searchSourceBuilder.query(queryBuilder); searchSourceBuilder.from(start); searchSourceBuilder.size(size);
searchSourceBuilder.size(pageable.getPageSize());
/** * The number of search hits to return. Defaults to {@code 10}. */ public SearchRequestBuilder setSize(int size) { sourceBuilder().size(size); return this; }
sourceBuilder.size(query.getPageable().getPageSize());
/** * The scroll size to control number of documents processed per batch */ public DeleteByQueryRequest setBatchSize(int size) { getSearchRequest().source().size(size); return this; }
/** * Gets the batch size for this request */ public int getBatchSize() { return getSearchRequest().source().size(); }
/** * Sets the scroll size for setting how many documents are to be processed in one batch during reindex */ public ReindexRequest setSourceBatchSize(int size) { this.getSearchRequest().source().size(size); return this; }
/** * The scroll size to control number of documents processed per batch */ public UpdateByQueryRequest setBatchSize(int size) { getSearchRequest().source().size(size); return this; }
/** * Gets the batch size for this request */ public int getBatchSize() { return getSearchRequest().source().size(); }
/** * Constructor for actual use. * * @param searchRequest the search request to execute to get the documents to process * @param setDefaults should this request set the defaults on the search request? Usually set to true but leave it false to support * request slicing */ public AbstractBulkByScrollRequest(SearchRequest searchRequest, boolean setDefaults) { this.searchRequest = searchRequest; // Set the defaults which differ from SearchRequest's defaults. if (setDefaults) { searchRequest.scroll(DEFAULT_SCROLL_TIMEOUT); searchRequest.source(new SearchSourceBuilder()); searchRequest.source().size(DEFAULT_SCROLL_SIZE); } }
public long count() { return this.esClient.search(Requests.searchRequest(indexName).types(indexType).source(SearchSourceBuilder.searchSource().size(0))).actionGet().getHits() .getTotalHits(); } }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { SearchRequest searchRequest = new SearchRequest(); /* * We have to pull out the call to `source().size(size)` because * _update_by_query and _delete_by_query uses this same parsing * path but sets a different variable when it sees the `size` * url parameter. * * Note that we can't use `searchRequest.source()::size` because * `searchRequest.source()` is null right now. We don't have to * guard against it being null in the IntConsumer because it can't * be null later. If that is confusing to you then you are in good * company. */ IntConsumer setSize = size -> searchRequest.source().size(size); request.withContentOrSourceParamParserOrNull(parser -> parseSearchRequest(searchRequest, request, parser, setSize)); return channel -> client.search(searchRequest, new RestStatusToXContentListener<>(channel)); }
/** * Returns a new ArraySearchPhaseResults instance. This might return an instance that reduces search responses incrementally. */ InitialSearchPhase.ArraySearchPhaseResults<SearchPhaseResult> newSearchPhaseResults(SearchRequest request, int numShards) { SearchSourceBuilder source = request.source(); boolean isScrollRequest = request.scroll() != null; final boolean hasAggs = source != null && source.aggregations() != null; final boolean hasTopDocs = source == null || source.size() != 0; final boolean trackTotalHits = source == null || source.trackTotalHits(); if (isScrollRequest == false && (hasAggs || hasTopDocs)) { // no incremental reduce if scroll is used - we only hit a single shard or sometimes more... if (request.getBatchedReduceSize() < numShards) { // only use this if there are aggs and if there are more shards than we should reduce at once return new QueryPhaseResultConsumer(this, numShards, request.getBatchedReduceSize(), hasTopDocs, hasAggs); } } return new InitialSearchPhase.ArraySearchPhaseResults<SearchPhaseResult>(numShards) { @Override ReducedQueryPhase reduce() { return reducedQueryPhase(results.asList(), isScrollRequest, trackTotalHits); } }; }