@@ -1020,36 +1020,39 @@ public <T> void initCustomResultIndexAndExecute(String resultIndexOrAlias, Execu
1020
1020
* creates flattened result index
1021
1021
* @param flattenedResultIndexAlias the flattened result index alias
1022
1022
* @param actionListener the action listener
1023
- * @throws IOException
1024
1023
*/
1025
- public void initFlattenedResultIndex (String flattenedResultIndexAlias , ActionListener <CreateIndexResponse > actionListener )
1026
- throws IOException {
1027
- String indexName = getCustomResultIndexPattern (flattenedResultIndexAlias );
1028
- logger .info ("Initializing flattened result index: {}" , indexName );
1024
+ public void initFlattenedResultIndex (String flattenedResultIndexAlias , ActionListener <CreateIndexResponse > actionListener ) {
1025
+ try {
1026
+ String indexName = getCustomResultIndexPattern (flattenedResultIndexAlias );
1027
+ logger .info ("Initializing flattened result index: {}" , indexName );
1029
1028
1030
- CreateIndexRequest request = new CreateIndexRequest (indexName )
1031
- .mapping (getFlattenedResultMappings (), XContentType .JSON )
1032
- .settings (settings );
1029
+ CreateIndexRequest request = new CreateIndexRequest (indexName )
1030
+ .mapping (getFlattenedResultMappings (), XContentType .JSON )
1031
+ .settings (settings );
1033
1032
1034
- if (flattenedResultIndexAlias != null ) {
1035
- request .alias (new Alias (flattenedResultIndexAlias ));
1036
- }
1033
+ if (flattenedResultIndexAlias != null ) {
1034
+ request .alias (new Alias (flattenedResultIndexAlias ));
1035
+ }
1037
1036
1038
- choosePrimaryShards (request , false );
1037
+ choosePrimaryShards (request , false );
1039
1038
1040
- adminClient .indices ().create (request , ActionListener .wrap (response -> {
1041
- if (response .isAcknowledged ()) {
1042
- logger .info ("Successfully created flattened result index: {} with alias: {}" , indexName , flattenedResultIndexAlias );
1043
- actionListener .onResponse (response );
1044
- } else {
1045
- String errorMsg = "Index creation not acknowledged for index: " + indexName ;
1046
- logger .error (errorMsg );
1047
- actionListener .onFailure (new IllegalStateException (errorMsg ));
1048
- }
1049
- }, exception -> {
1050
- logger .error ("Failed to create flattened result index: {}" , indexName , exception );
1051
- actionListener .onFailure (exception );
1052
- }));
1039
+ adminClient .indices ().create (request , ActionListener .wrap (response -> {
1040
+ if (response .isAcknowledged ()) {
1041
+ logger .info ("Successfully created flattened result index: {} with alias: {}" , indexName , flattenedResultIndexAlias );
1042
+ actionListener .onResponse (response );
1043
+ } else {
1044
+ String errorMsg = "Index creation not acknowledged for index: " + indexName ;
1045
+ logger .error (errorMsg );
1046
+ actionListener .onFailure (new IllegalStateException (errorMsg ));
1047
+ }
1048
+ }, exception -> {
1049
+ logger .error ("Failed to create flattened result index: {}" , indexName , exception );
1050
+ actionListener .onFailure (exception );
1051
+ }));
1052
+ } catch (IOException e ) {
1053
+ logger .error ("Error while building mappings for flattened result index: {}" , flattenedResultIndexAlias , e );
1054
+ actionListener .onFailure (e );
1055
+ }
1053
1056
}
1054
1057
1055
1058
public String getFlattenedResultIndexAlias (String indexOrAliasName , String configId ) {
0 commit comments