@@ -1112,7 +1112,7 @@ public Stream<String> query(IndexQuery query, KeyInformation.IndexRetriever info
11121112 compat .createRequestBody (sr , useScroll ? NULL_PARAMETERS : TRACK_TOTAL_HITS_DISABLED_PARAMETERS ),
11131113 useScroll );
11141114 log .debug ("First Executed query [{}] in {} ms" , query .getCondition (), response .getTook ());
1115- final ElasticSearchScroll resultIterator = new ElasticSearchScroll ( client , response , sr .getSize ());
1115+ final Iterator < RawQuery . Result < String >> resultIterator = getResultsIterator ( useScroll , response , sr .getSize ());
11161116 final Stream <RawQuery .Result <String >> toReturn
11171117 = StreamSupport .stream (Spliterators .spliteratorUnknownSize (resultIterator , Spliterator .ORDERED ), false );
11181118 return (query .hasLimit () ? toReturn .limit (query .getLimit ()) : toReturn ).map (RawQuery .Result ::getResult );
@@ -1121,6 +1121,10 @@ public Stream<String> query(IndexQuery query, KeyInformation.IndexRetriever info
11211121 }
11221122 }
11231123
1124+ private Iterator <RawQuery .Result <String >> getResultsIterator (boolean useScroll , ElasticSearchResponse response , int windowSize ){
1125+ return (useScroll )? new ElasticSearchScroll (client , response , windowSize ) : response .getResults ().iterator ();
1126+ }
1127+
11241128 private String convertToEsDataType (Class <?> dataType , Mapping mapping ) {
11251129 if (String .class .isAssignableFrom (dataType )) {
11261130 return "string" ;
@@ -1206,9 +1210,10 @@ private void addOrderToQuery(KeyInformation.IndexRetriever informations, Elastic
12061210 public Stream <RawQuery .Result <String >> query (RawQuery query , KeyInformation .IndexRetriever information ,
12071211 BaseTransaction tx ) throws BackendException {
12081212 final int size = query .hasLimit () ? Math .min (query .getLimit () + query .getOffset (), batchSize ) : batchSize ;
1209- final ElasticSearchResponse response = runCommonQuery (query , information , tx , size , size >= batchSize );
1213+ final boolean useScroll = size >= batchSize ;
1214+ final ElasticSearchResponse response = runCommonQuery (query , information , tx , size , useScroll );
12101215 log .debug ("First Executed query [{}] in {} ms" , query .getQuery (), response .getTook ());
1211- final ElasticSearchScroll resultIterator = new ElasticSearchScroll ( client , response , size );
1216+ final Iterator < RawQuery . Result < String >> resultIterator = getResultsIterator ( useScroll , response , size );
12121217 final Stream <RawQuery .Result <String >> toReturn
12131218 = StreamSupport .stream (Spliterators .spliteratorUnknownSize (resultIterator , Spliterator .ORDERED ),
12141219 false ).skip (query .getOffset ());
0 commit comments