3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
-
7
6
package org .opensearch .sql .opensearch .client ;
8
7
9
8
import com .google .common .collect .ImmutableList ;
@@ -49,8 +48,7 @@ public class OpenSearchRestClient implements OpenSearchClient {
49
48
@ Override
50
49
public boolean exists (String indexName ) {
51
50
try {
52
- return client .indices ().exists (
53
- new GetIndexRequest (indexName ), RequestOptions .DEFAULT );
51
+ return client .indices ().exists (new GetIndexRequest (indexName ), RequestOptions .DEFAULT );
54
52
} catch (IOException e ) {
55
53
throw new IllegalStateException ("Failed to check if index [" + indexName + "] exist" , e );
56
54
}
@@ -59,8 +57,9 @@ public boolean exists(String indexName) {
59
57
@ Override
60
58
public void createIndex (String indexName , Map <String , Object > mappings ) {
61
59
try {
62
- client .indices ().create (
63
- new CreateIndexRequest (indexName ).mapping (mappings ), RequestOptions .DEFAULT );
60
+ client
61
+ .indices ()
62
+ .create (new CreateIndexRequest (indexName ).mapping (mappings ), RequestOptions .DEFAULT );
64
63
} catch (IOException e ) {
65
64
throw new IllegalStateException ("Failed to create index [" + indexName + "]" , e );
66
65
}
@@ -80,27 +79,29 @@ public Map<String, IndexMapping> getIndexMappings(String... indexExpression) {
80
79
81
80
@ Override
82
81
public Map <String , Integer > getIndexMaxResultWindows (String ... indexExpression ) {
83
- GetSettingsRequest request = new GetSettingsRequest ()
84
- .indices (indexExpression ).includeDefaults (true );
82
+ GetSettingsRequest request =
83
+ new GetSettingsRequest () .indices (indexExpression ).includeDefaults (true );
85
84
try {
86
85
GetSettingsResponse response = client .indices ().getSettings (request , RequestOptions .DEFAULT );
87
86
Map <String , Settings > settings = response .getIndexToSettings ();
88
87
Map <String , Settings > defaultSettings = response .getIndexToDefaultSettings ();
89
88
Map <String , Integer > result = new HashMap <>();
90
89
91
- defaultSettings .forEach ((key , value ) -> {
92
- Integer maxResultWindow = value .getAsInt ("index.max_result_window" , null );
93
- if (maxResultWindow != null ) {
94
- result .put (key , maxResultWindow );
95
- }
96
- });
97
-
98
- settings .forEach ((key , value ) -> {
99
- Integer maxResultWindow = value .getAsInt ("index.max_result_window" , null );
100
- if (maxResultWindow != null ) {
101
- result .put (key , maxResultWindow );
102
- }
103
- });
90
+ defaultSettings .forEach (
91
+ (key , value ) -> {
92
+ Integer maxResultWindow = value .getAsInt ("index.max_result_window" , null );
93
+ if (maxResultWindow != null ) {
94
+ result .put (key , maxResultWindow );
95
+ }
96
+ });
97
+
98
+ settings .forEach (
99
+ (key , value ) -> {
100
+ Integer maxResultWindow = value .getAsInt ("index.max_result_window" , null );
101
+ if (maxResultWindow != null ) {
102
+ result .put (key , maxResultWindow );
103
+ }
104
+ });
104
105
105
106
return result ;
106
107
} catch (IOException e ) {
@@ -126,8 +127,7 @@ public OpenSearchResponse search(OpenSearchRequest request) {
126
127
throw new IllegalStateException (
127
128
"Failed to perform scroll operation with request " + req , e );
128
129
}
129
- }
130
- );
130
+ });
131
131
}
132
132
133
133
/**
@@ -142,7 +142,8 @@ public List<String> indices() {
142
142
client .indices ().get (new GetIndexRequest (), RequestOptions .DEFAULT );
143
143
final Stream <String > aliasStream =
144
144
ImmutableList .copyOf (indexResponse .getAliases ().values ()).stream ()
145
- .flatMap (Collection ::stream ).map (AliasMetadata ::alias );
145
+ .flatMap (Collection ::stream )
146
+ .map (AliasMetadata ::alias );
146
147
return Stream .concat (Arrays .stream (indexResponse .getIndices ()), aliasStream )
147
148
.collect (Collectors .toList ());
148
149
} catch (IOException e ) {
@@ -173,16 +174,17 @@ public Map<String, String> meta() {
173
174
174
175
@ Override
175
176
public void cleanup (OpenSearchRequest request ) {
176
- request .clean (scrollId -> {
177
- try {
178
- ClearScrollRequest clearRequest = new ClearScrollRequest ();
179
- clearRequest .addScrollId (scrollId );
180
- client .clearScroll (clearRequest , RequestOptions .DEFAULT );
181
- } catch (IOException e ) {
182
- throw new IllegalStateException (
183
- "Failed to clean up resources for search request " + request , e );
184
- }
185
- });
177
+ request .clean (
178
+ scrollId -> {
179
+ try {
180
+ ClearScrollRequest clearRequest = new ClearScrollRequest ();
181
+ clearRequest .addScrollId (scrollId );
182
+ client .clearScroll (clearRequest , RequestOptions .DEFAULT );
183
+ } catch (IOException e ) {
184
+ throw new IllegalStateException (
185
+ "Failed to clean up resources for search request " + request , e );
186
+ }
187
+ });
186
188
}
187
189
188
190
@ Override
0 commit comments