@@ -251,6 +251,34 @@ public void testAlias() throws Exception {
251251 assertEquals (aliasFilteredResponse .getInt ("size" ), 4 );
252252 }
253253
254+ @ Test
255+ public void testAliasResultConsistency () throws Exception {
256+ String indexName = Index .ONLINE .getName ();
257+ String aliasName = "alias_ONLINE_consistency" ;
258+
259+ // Create an alias
260+ String createAliasQuery =
261+ String .format (
262+ "{ \" actions\" : [ { \" add\" : { \" index\" : \" %s\" , \" alias\" : \" %s\" } } ] }" ,
263+ indexName , aliasName );
264+ Request createAliasRequest = new Request ("POST" , "/_aliases" );
265+ createAliasRequest .setJsonEntity (createAliasQuery );
266+ JSONObject aliasResponse = new JSONObject (executeRequest (createAliasRequest ));
267+ assertTrue (aliasResponse .getBoolean ("acknowledged" ));
268+
269+ // Query using direct index
270+ String directQuery = String .format ("SELECT * FROM %s" , TEST_INDEX_ONLINE );
271+ JSONObject directResponse = new JSONObject (executeFetchQuery (directQuery , 10 , "jdbc" ));
272+
273+ // Query using alias
274+ String aliasQuery = String .format ("SELECT * FROM %s" , aliasName );
275+ JSONObject aliasQueryResponse = new JSONObject (executeFetchQuery (aliasQuery , 10 , "jdbc" ));
276+
277+ assertEquals (directResponse .getInt ("size" ), aliasQueryResponse .getInt ("size" ));
278+ assertTrue (
279+ directResponse .getJSONArray ("schema" ).similar (aliasQueryResponse .getJSONArray ("schema" )));
280+ }
281+
254282 private String executeFetchQuery (String query , int fetchSize , String requestType , String filter )
255283 throws IOException {
256284 String endpoint = "/_plugins/_sql?format=" + requestType ;
0 commit comments