private SearchResult<String> searchObjectIds(String indexName, QueryBuilder queryBuilder, int start, int size, List<String> sortOptions, String docType) throws IOException {

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.query(queryBuilder);
        searchSourceBuilder.from(start);
        searchSourceBuilder.size(size);

        if (sortOptions != null && !sortOptions.isEmpty()) {

            for (String sortOption : sortOptions) {
                SortOrder order = SortOrder.ASC;
                String field = sortOption;
                int index = sortOption.indexOf(":");
                if (index > 0) {
                    field = sortOption.substring(0, index);
                    order = SortOrder.valueOf(sortOption.substring(index + 1));
                }
                searchSourceBuilder.sort(new FieldSortBuilder(field).order(order));
            }
        }

        // Generate the actual request to send to ES.
        SearchRequest searchRequest = new SearchRequest(indexName);
        searchRequest.types(docType);
        searchRequest.source(searchSourceBuilder);

        SearchResponse response = elasticSearchClient.search(searchRequest);

        List<String> result = new LinkedList<>();
        response.getHits().forEach(hit -> result.add(hit.getId()));
        long count = response.getHits().getTotalHits();
        return new SearchResult<>(count, result);
    }
private SearchResult < String > searchObjectIds ( String indexName , QueryBuilder queryBuilder , int start , int size , List < String > sortOptions , String docType ) throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder ( ) ; searchSourceBuilder . query ( queryBuilder ) ; searchSourceBuilder . from ( start ) ; searchSourceBuilder . size ( size ) ; if ( sortOptions != null && ! sortOptions . isEmpty ( ) ) { for ( String sortOption : sortOptions ) { SortOrder order = SortOrder . ASC ; String field = sortOption ; int index = sortOption . indexOf ( ":" ) ; if ( index > 0 ) { field = sortOption . substring ( 0 , index ) ; order = SortOrder . valueOf ( sortOption . substring ( index + 1 ) ) ; } searchSourceBuilder . sort ( new FieldSortBuilder ( field ) . order ( order ) ) ; } } SearchRequest searchRequest = new SearchRequest ( indexName ) ; searchRequest . types ( docType ) ; searchRequest . source ( searchSourceBuilder ) ; SearchResponse response = elasticSearchClient . search ( searchRequest ) ; List < String > result = new LinkedList < > ( ) ; response . getHits ( ) . forEach ( hit -> result . add ( hit . getId ( ) ) ) ; long count = response . getHits ( ) . getTotalHits ( ) ; return new SearchResult < > ( count , result ) ; }
Tries to find object ids for a given query in an index.

@param indexName The name of the index.
@param queryBuilder The query to use for searching.
@param start The start to use.
@param size The total return size.
@param sortOptions A list of string options to sort in the form VALUE:ORDER; where ORDER is optional and can be either ASC OR DESC.
@param docType The document type to searchObjectIdsViaExpression for.

@return The SearchResults which includes the count and IDs that were found.
@throws IOException If we cannot communicate with ES.