3535import org .apache .hc .core5 .http .ContentType ;
3636import org .apache .hc .core5 .http .io .entity .StringEntity ;
3737import org .opensearch .OpenSearchException ;
38- import org .opensearch .Version ;
3938import org .opensearch .action .search .SearchRequest ;
4039import org .opensearch .client .Request ;
4140import org .opensearch .common .logging .DeprecationLogger ;
@@ -74,7 +73,7 @@ final class RemoteRequestBuilders {
7473
7574 private RemoteRequestBuilders () {}
7675
77- static Request initialSearch (SearchRequest searchRequest , BytesReference query , Version remoteVersion ) {
76+ static Request initialSearch (SearchRequest searchRequest , BytesReference query , RemoteVersion remoteVersion ) {
7877 // It is nasty to build paths with StringBuilder but we'll be careful....
7978 StringBuilder path = new StringBuilder ("/" );
8079 addIndices (path , searchRequest .indices ());
@@ -84,7 +83,7 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
8483 if (searchRequest .scroll () != null ) {
8584 TimeValue keepAlive = searchRequest .scroll ().keepAlive ();
8685 // V_5_0_0
87- if (remoteVersion .before (Version . fromId ( 5000099 ) )) {
86+ if (remoteVersion .before (RemoteVersion . ELASTICSEARCH_5_0_0 )) {
8887 /* Versions of Elasticsearch before 5.0 couldn't parse nanos or micros
8988 * so we toss out that resolution, rounding up because more scroll
9089 * timeout seems safer than less. */
@@ -103,7 +102,7 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
103102 if (searchRequest .source ().sorts () != null ) {
104103 boolean useScan = false ;
105104 // Detect if we should use search_type=scan rather than a sort
106- if (remoteVersion .before (Version . fromId ( 2010099 ) )) {
105+ if (remoteVersion .before (RemoteVersion . ELASTICSEARCH_2_1_0 )) {
107106 for (SortBuilder <?> sort : searchRequest .source ().sorts ()) {
108107 if (sort instanceof FieldSortBuilder ) {
109108 FieldSortBuilder f = (FieldSortBuilder ) sort ;
@@ -124,10 +123,10 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
124123 request .addParameter ("sort" , sorts .toString ());
125124 }
126125 }
127- if (remoteVersion .before (Version . fromId ( 2000099 ) )) {
126+ if (remoteVersion .before (RemoteVersion . ELASTICSEARCH_2_0_0 )) {
128127 // Versions before 2.0.0 need prompting to return interesting fields. Note that timestamp isn't available at all....
129128 searchRequest .source ().storedField ("_parent" ).storedField ("_routing" ).storedField ("_ttl" );
130- if (remoteVersion .before (Version . fromId ( 1000099 ) )) {
129+ if (remoteVersion .before (RemoteVersion . ELASTICSEARCH_1_0_0 )) {
131130 // Versions before 1.0.0 don't support `"_source": true` so we have to ask for the _source in a funny way.
132131 if (false == searchRequest .source ().storedFields ().fieldNames ().contains ("_source" )) {
133132 searchRequest .source ().storedField ("_source" );
@@ -140,11 +139,11 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
140139 fields .append (',' ).append (searchRequest .source ().storedFields ().fieldNames ().get (i ));
141140 }
142141 // V_5_0_0
143- String storedFieldsParamName = remoteVersion .before (Version . fromId ( 5000099 ) ) ? "fields" : "stored_fields" ;
142+ String storedFieldsParamName = remoteVersion .before (RemoteVersion . ELASTICSEARCH_5_0_0 ) ? "fields" : "stored_fields" ;
144143 request .addParameter (storedFieldsParamName , fields .toString ());
145144 }
146145
147- if (remoteVersion .onOrAfter (Version . fromId ( 6030099 ) )) {
146+ if (remoteVersion .onOrAfter (RemoteVersion . ELASTICSEARCH_6_3_0 )) {
148147 // allow_partial_results introduced in 6.3, running remote reindex against earlier versions still silently discards RED shards.
149148 request .addParameter ("allow_partial_search_results" , "false" );
150149 }
@@ -173,7 +172,7 @@ static Request initialSearch(SearchRequest searchRequest, BytesReference query,
173172 if (searchRequest .source ().fetchSource () != null ) {
174173 entity .field ("_source" , searchRequest .source ().fetchSource ());
175174 } else {
176- if (remoteVersion .onOrAfter (Version . fromId ( 1000099 ) )) {
175+ if (remoteVersion .onOrAfter (RemoteVersion . ELASTICSEARCH_1_0_0 )) {
177176 // Versions before 1.0 don't support `"_source": true` so we have to ask for the source as a stored field.
178177 entity .field ("_source" , true );
179178 }
@@ -225,19 +224,18 @@ private static String sortToUri(SortBuilder<?> sort) {
225224 throw new IllegalArgumentException ("Unsupported sort [" + sort + "]" );
226225 }
227226
228- static Request scroll (String scroll , TimeValue keepAlive , Version remoteVersion ) {
227+ static Request scroll (String scroll , TimeValue keepAlive , RemoteVersion remoteVersion ) {
229228 Request request = new Request ("POST" , "/_search/scroll" );
230229
231- // V_5_0_0
232- if (remoteVersion .before (Version .fromId (5000099 ))) {
230+ if (remoteVersion .before (RemoteVersion .ELASTICSEARCH_5_0_0 )) {
233231 /* Versions of Elasticsearch before 5.0 couldn't parse nanos or micros
234232 * so we toss out that resolution, rounding up so we shouldn't end up
235233 * with 0s. */
236234 keepAlive = timeValueMillis ((long ) Math .ceil (keepAlive .millisFrac ()));
237235 }
238236 request .addParameter ("scroll" , keepAlive .getStringRep ());
239237
240- if (remoteVersion .before (Version . fromId ( 2000099 ) )) {
238+ if (remoteVersion .before (RemoteVersion . ELASTICSEARCH_2_0_0 )) {
241239 // Versions before 2.0.0 extract the plain scroll_id from the body
242240 request .setEntity (new StringEntity (scroll , ContentType .TEXT_PLAIN ));
243241 return request ;
@@ -252,10 +250,10 @@ static Request scroll(String scroll, TimeValue keepAlive, Version remoteVersion)
252250 return request ;
253251 }
254252
255- static Request clearScroll (String scroll , Version remoteVersion ) {
253+ static Request clearScroll (String scroll , RemoteVersion remoteVersion ) {
256254 Request request = new Request ("DELETE" , "/_search/scroll" );
257255
258- if (remoteVersion .before (Version . fromId ( 2000099 ) )) {
256+ if (remoteVersion .before (RemoteVersion . ELASTICSEARCH_2_0_0 )) {
259257 // Versions before 2.0.0 extract the plain scroll_id from the body
260258 request .setEntity (new StringEntity (scroll , ContentType .TEXT_PLAIN ));
261259 return request ;
0 commit comments