@@ -56,15 +56,7 @@ public boolean isIndexRemovable(String index) {
5656 JsonObject json = new Gson ().fromJson (body , JsonObject .class );
5757 if (json != null && json .has (index )) {
5858 JsonObject indexInfo = json .getAsJsonObject (index );
59- String state = null ;
60- if (indexInfo .has ("index.plugins.index_state_management.current_state" )) {
61- state = indexInfo .get ("index.plugins.index_state_management.current_state" ).getAsString ();
62- } else if (indexInfo .has ("index.opendistro.index_state_management.current_state" )) {
63- state = indexInfo .get ("index.opendistro.index_state_management.current_state" ).getAsString ();
64- } else if (indexInfo .has ("opendistro.index_state_management.current_state" )) {
65- state = indexInfo .get ("opendistro.index_state_management.current_state" ).getAsString ();
66- }
67-
59+ String state = this .getCurrentState (indexInfo )
6860 if (state != null ) {
6961 return Constants .STATE_DELETE .equals (state ) || Constants .STATE_SAFE_DELETE .equals (state );
7062 }
@@ -77,6 +69,28 @@ public boolean isIndexRemovable(String index) {
7769 }
7870 }
7971
72+
73+ private String getCurrentState (JsonObject indexInfo ) {
74+ if (indexInfo .has ("state" ) && indexInfo .get ("state" ).isJsonObject ()) {
75+ JsonObject stateObj = indexInfo .getAsJsonObject ("state" );
76+ if (stateObj .has ("name" )) {
77+ return stateObj .get ("name" ).getAsString ();
78+ }
79+ }
80+
81+ String [] legacyPaths = {
82+ "index.plugins.index_state_management.current_state" ,
83+ "index.opendistro.index_state_management.current_state" ,
84+ "opendistro.index_state_management.current_state"
85+ };
86+
87+ return Arrays .stream (legacyPaths )
88+ .filter (indexInfo ::has )
89+ .map (path -> indexInfo .get (path ).getAsString ())
90+ .findFirst ()
91+ .orElse (null );
92+ }
93+
8094 @ EventListener (IndexPatternsReadyEvent .class )
8195 public void init () throws Exception {
8296 final String ctx = CLASSNAME + ".init" ;
0 commit comments