@@ -28,6 +28,8 @@ public class PaginationIT extends SQLIntegTestCase {
2828 public void init () throws IOException {
2929 loadIndex (Index .CALCS );
3030 loadIndex (Index .ONLINE );
31+ loadIndex (Index .DOG );
32+ loadIndex (Index .DOGS2 );
3133 }
3234
3335 @ Test
@@ -251,6 +253,44 @@ public void testAlias() throws Exception {
251253 assertEquals (aliasFilteredResponse .getInt ("size" ), 4 );
252254 }
253255
256+ @ Test
257+ public void testAliasResultConsistency () throws Exception {
258+ String aliasName = "alias_dog_consistency" ;
259+
260+ // Create an alias that maps to both DOG and DOGS2 indices
261+ String createAliasQuery =
262+ String .format (
263+ "{ \" actions\" : [ "
264+ + "{ \" add\" : { \" index\" : \" %s\" , \" alias\" : \" %s\" } }, "
265+ + "{ \" add\" : { \" index\" : \" %s\" , \" alias\" : \" %s\" } } "
266+ + "] }" ,
267+ Index .DOG .getName (), aliasName , Index .DOGS2 .getName (), aliasName );
268+ Request createAliasRequest = new Request ("POST" , "/_aliases" );
269+ createAliasRequest .setJsonEntity (createAliasQuery );
270+ JSONObject aliasResponse = new JSONObject (executeRequest (createAliasRequest ));
271+ assertTrue (aliasResponse .getBoolean ("acknowledged" ));
272+
273+ // Query both indices directly (same indices the alias points to)
274+ String directQuery = String .format ("SELECT * FROM %s, %s" , Index .DOG .getName (), Index .DOGS2 .getName ());
275+ JSONObject directResponse = new JSONObject (executeFetchQuery (directQuery , 10 , "jdbc" ));
276+
277+ // Query using alias (which points to the same two indices)
278+ String aliasQuery = String .format ("SELECT * FROM %s" , aliasName );
279+ JSONObject aliasQueryResponse = new JSONObject (executeFetchQuery (aliasQuery , 10 , "jdbc" ));
280+
281+ assertEquals (directResponse .getInt ("size" ), aliasQueryResponse .getInt ("size" ));
282+
283+ // Clean up alias
284+ String deleteAliasQuery =
285+ String .format (
286+ "{ \" actions\" : [ { \" remove\" : { \" index\" : \" %s\" , \" alias\" : \" %s\" } }, {"
287+ + " \" remove\" : { \" index\" : \" %s\" , \" alias\" : \" %s\" } } ] }" ,
288+ Index .DOG .getName (), aliasName , Index .DOGS2 .getName (), aliasName );
289+ Request deleteAliasRequest = new Request ("POST" , "/_aliases" );
290+ deleteAliasRequest .setJsonEntity (deleteAliasQuery );
291+ executeRequest (deleteAliasRequest );
292+ }
293+
254294 private String executeFetchQuery (String query , int fetchSize , String requestType , String filter )
255295 throws IOException {
256296 String endpoint = "/_plugins/_sql?format=" + requestType ;
0 commit comments