Skip to content

Commit e1c9654

Browse files
committed
update AliasApi
1 parent 08971cb commit e1c9654

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

core/src/main/scala/app/softnetwork/elastic/client/AliasApi.scala

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,25 +298,28 @@ trait AliasApi extends ElasticClientHelpers { _: IndicesApi =>
298298
case ElasticFailure(error) =>
299299
logger.error(s"❌ Failed to parse aliases JSON for index '$index': ${error.message}")
300300
return ElasticFailure(error)
301-
case ElasticSuccess(indexObj) =>
302-
if (indexObj == null) {
301+
case ElasticSuccess(rootObj) =>
302+
if (!rootObj.has(index)) {
303303
logger.warn(s"Index '$index' not found in response")
304+
return ElasticResult.success(Set.empty[String])
305+
}
306+
307+
val indexObj = rootObj.getAsJsonObject(index)
308+
if (indexObj == null) {
309+
logger.warn(s"Index '$index' is null in response")
310+
return ElasticResult.success(Set.empty[String])
311+
}
312+
313+
val aliasesObj = indexObj.getAsJsonObject("aliases")
314+
if (aliasesObj == null || aliasesObj.size() == 0) {
315+
logger.debug(s"No aliases found for index '$index'")
304316
ElasticResult.success(Set.empty[String])
305317
} else {
306-
val aliasesObj =
307-
indexObj
308-
.getAsJsonObject(index)
309-
.getAsJsonObject("aliases")
310-
if (aliasesObj == null || aliasesObj.size() == 0) {
311-
logger.debug(s"No aliases found for index '$index'")
312-
ElasticResult.success(Set.empty[String])
313-
} else {
314-
val aliases = aliasesObj.entrySet().asScala.map(a => a.getKey).toSet
315-
logger.debug(
316-
s"Found ${aliases.size} alias(es) for index '$index': ${aliases.mkString(", ")}"
317-
)
318-
ElasticResult.success(aliases)
319-
}
318+
val aliases = aliasesObj.entrySet().asScala.map(_.getKey).toSet
319+
logger.debug(
320+
s"Found ${aliases.size} alias(es) for index '$index': ${aliases.mkString(", ")}"
321+
)
322+
ElasticResult.success(aliases)
320323
}
321324
}
322325
} match {

0 commit comments

Comments
 (0)