2828
2929import static org .hamcrest .Matchers .containsString ;
3030import static org .hamcrest .Matchers .equalTo ;
31+ import static org .hamcrest .Matchers .greaterThan ;
3132import static org .hamcrest .Matchers .hasSize ;
32- import static org .hamcrest .Matchers .lessThanOrEqualTo ;
3333
3434public class EsqlPartialResultsIT extends ESRestTestCase {
3535 @ ClassRule
@@ -106,7 +106,11 @@ public void testPartialResult() throws Exception {
106106 Set <String > okIds = populateIndices ();
107107 String query = """
108108 {
109- "query": "FROM ok-index,failing-index | LIMIT 100 | KEEP fail_me,v"
109+ "query": "FROM ok-index,failing-index | LIMIT 100 | KEEP fail_me,v",
110+ "pragma": {
111+ "max_concurrent_shards_per_node": 1
112+ },
113+ "accept_pragma_risks": true
110114 }
111115 """ ;
112116 // allow_partial_results = true
@@ -123,19 +127,18 @@ public void testPartialResult() throws Exception {
123127 List <?> columns = (List <?>) results .get ("columns" );
124128 assertThat (columns , equalTo (List .of (Map .of ("name" , "fail_me" , "type" , "long" ), Map .of ("name" , "v" , "type" , "long" ))));
125129 List <?> values = (List <?>) results .get ("values" );
126- assertThat (values .size (), lessThanOrEqualTo (okIds .size ()));
130+ assertThat (values .size (), equalTo (okIds .size ()));
127131 Map <String , Object > localInfo = (Map <String , Object >) XContentMapValues .extractValue (
128132 results ,
129133 "_clusters" ,
130134 "details" ,
131135 "(local)"
132136 );
133137 assertNotNull (localInfo );
134- assertThat (XContentMapValues .extractValue (localInfo , "_shards" , "successful" ), equalTo (0 ));
135- assertThat (
136- XContentMapValues .extractValue (localInfo , "_shards" , "failed" ),
137- equalTo (XContentMapValues .extractValue (localInfo , "_shards" , "total" ))
138- );
138+ Integer successfulShards = (Integer ) XContentMapValues .extractValue (localInfo , "_shards" , "successful" );
139+ Integer failedShards = (Integer ) XContentMapValues .extractValue (localInfo , "_shards" , "failed" );
140+ assertThat (successfulShards , greaterThan (0 ));
141+ assertThat (failedShards , greaterThan (0 ));
139142 List <Map <String , Object >> failures = (List <Map <String , Object >>) XContentMapValues .extractValue (localInfo , "failures" );
140143 assertThat (failures , hasSize (1 ));
141144 assertThat (
@@ -167,7 +170,11 @@ public void testFailureFromRemote() throws Exception {
167170 Set <String > okIds = populateIndices ();
168171 String query = """
169172 {
170- "query": "FROM *:ok-index,*:failing-index | LIMIT 100 | KEEP fail_me,v"
173+ "query": "FROM *:ok-index,*:failing-index | LIMIT 100 | KEEP fail_me,v",
174+ "pragma": {
175+ "max_concurrent_shards_per_node": 1
176+ },
177+ "accept_pragma_risks": true
171178 }
172179 """ ;
173180 // allow_partial_results = true
@@ -183,19 +190,18 @@ public void testFailureFromRemote() throws Exception {
183190 List <?> columns = (List <?>) results .get ("columns" );
184191 assertThat (columns , equalTo (List .of (Map .of ("name" , "fail_me" , "type" , "long" ), Map .of ("name" , "v" , "type" , "long" ))));
185192 List <?> values = (List <?>) results .get ("values" );
186- assertThat (values .size (), lessThanOrEqualTo (okIds .size ()));
193+ assertThat (values .size (), equalTo (okIds .size ()));
187194 Map <String , Object > remoteCluster = (Map <String , Object >) XContentMapValues .extractValue (
188195 results ,
189196 "_clusters" ,
190197 "details" ,
191198 "cluster_one"
192199 );
193200 assertNotNull (remoteCluster );
194- assertThat (XContentMapValues .extractValue (remoteCluster , "_shards" , "successful" ), equalTo (0 ));
195- assertThat (
196- XContentMapValues .extractValue (remoteCluster , "_shards" , "failed" ),
197- equalTo (XContentMapValues .extractValue (remoteCluster , "_shards" , "total" ))
198- );
201+ Integer successfulShards = (Integer ) XContentMapValues .extractValue (remoteCluster , "_shards" , "successful" );
202+ Integer failedShards = (Integer ) XContentMapValues .extractValue (remoteCluster , "_shards" , "failed" );
203+ assertThat (successfulShards , greaterThan (0 ));
204+ assertThat (failedShards , greaterThan (0 ));
199205 List <Map <String , Object >> failures = (List <Map <String , Object >>) XContentMapValues .extractValue (remoteCluster , "failures" );
200206 assertThat (failures , hasSize (1 ));
201207 assertThat (
@@ -207,6 +213,25 @@ public void testFailureFromRemote() throws Exception {
207213 }
208214 }
209215
216+ public void testAllShardsFailed () throws Exception {
217+ setupRemoteClusters ();
218+ populateIndices ();
219+ try {
220+ for (boolean allowPartialResults : List .of (Boolean .TRUE , Boolean .FALSE )) {
221+ for (String index : List .of ("failing*" , "*:failing*" , "*:failing*,failing*" )) {
222+ Request request = new Request ("POST" , "/_query" );
223+ request .setJsonEntity ("{\" query\" : \" FROM " + index + " | LIMIT 100\" }" );
224+ request .addParameter ("allow_partial_results" , Boolean .toString (allowPartialResults ));
225+ var error = expectThrows (ResponseException .class , () -> client ().performRequest (request ));
226+ Response resp = error .getResponse ();
227+ assertThat (EntityUtils .toString (resp .getEntity ()), containsString ("Accessing failing field" ));
228+ }
229+ }
230+ } finally {
231+ removeRemoteCluster ();
232+ }
233+ }
234+
210235 private void setupRemoteClusters () throws IOException {
211236 String settings = String .format (Locale .ROOT , """
212237 {
0 commit comments