2626import java .util .stream .StreamSupport ;
2727import org .apache .logging .log4j .LogManager ;
2828import org .apache .logging .log4j .Logger ;
29+ import org .opensearch .action .admin .indices .alias .get .GetAliasesRequest ;
30+ import org .opensearch .action .admin .indices .alias .get .GetAliasesResponse ;
2931import org .opensearch .action .admin .indices .mapping .get .GetFieldMappingsRequest ;
3032import org .opensearch .action .admin .indices .mapping .get .GetFieldMappingsResponse ;
3133import org .opensearch .action .search .ClearScrollResponse ;
@@ -164,7 +166,11 @@ private void populateResultSetFromDefaultCursor(DefaultCursor cursor) {
164166 private void loadFromEsState (Query query ) {
165167 String indexName = fetchIndexName (query );
166168 String [] fieldNames = fetchFieldsAsArray (query );
167-
169+ GetAliasesResponse getAliasesResponse =
170+ client .admin ().indices ().getAliases (new GetAliasesRequest (indexName )).actionGet ();
171+ if (getAliasesResponse != null && !getAliasesResponse .getAliases ().isEmpty ()) {
172+ indexName = getAliasesResponse .getAliases ().keySet ().iterator ().next ();
173+ }
168174 // Reset boolean in the case of JOIN query where multiple calls to loadFromEsState() are made
169175 selectAll = isSimpleQuerySelectAll (query ) || isJoinQuerySelectAll (query , fieldNames );
170176
@@ -181,6 +187,7 @@ private void loadFromEsState(Query query) {
181187 throw new IllegalArgumentException (
182188 String .format ("Index type %s does not exist" , query .getFrom ()));
183189 }
190+ LOG .info ("Response Mapping: {}" , response .mappings ());
184191 Map <String , FieldMappingMetadata > typeMappings = mappings .get (indexName );
185192
186193 this .indexName = this .indexName == null ? indexName : (this .indexName + "|" + indexName );
0 commit comments