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 ) ; }
Tries to find object ids for a given query in an index .