diff --git a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/cat/CatHandlers.scala b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/cat/CatHandlers.scala index 830f63126..0a7bf8da1 100644 --- a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/cat/CatHandlers.scala +++ b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/cat/CatHandlers.scala @@ -111,8 +111,14 @@ trait CatHandlers { } implicit object CatAliasesHandler extends Handler[CatAliases, Seq[CatAliasResponse]] { - override def build(request: CatAliases): ElasticRequest = - ElasticRequest("GET", "/_cat/aliases", Map("v" -> "", "format" -> "json")) + override def build(request: CatAliases): ElasticRequest = { + val endPoint = request.pattern match { + case Some(pattern) => s"/_cat/aliases/$pattern" + case _ => "/_cat/aliases" + } + + ElasticRequest("GET", endPoint, Map("v" -> "", "format" -> "json")) + } } implicit object CatIndexesHandler extends Handler[CatIndexes, Seq[CatIndicesResponse]] { diff --git a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/cat/CatsApi.scala b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/cat/CatsApi.scala index 88b2d3fc4..964c9c409 100644 --- a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/cat/CatsApi.scala +++ b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/cat/CatsApi.scala @@ -6,7 +6,9 @@ import com.sksamuel.exts.OptionImplicits._ trait CatsApi { - def catAliases(): CatAliases = CatAliases() + def catAliases(): CatAliases = CatAliases(None) + def catAliases(pattern: String): CatAliases = CatAliases(pattern.some) + def catAllocation(): CatAllocation = CatAllocation() def catCount(): CatCount = CatCount() @@ -38,6 +40,6 @@ case class CatNodes() case class CatHealth() case class CatThreadPool() case class CatAllocation() -case class CatAliases() +case class CatAliases(pattern: Option[String]) case class CatMaster() case class CatIndexes(health: Option[HealthStatus], indexPattern: Option[String]) diff --git a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/cat/CatAliasTest.scala b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/cat/CatAliasTest.scala index f9ca2bf9c..2e4fc0bdf 100644 --- a/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/cat/CatAliasTest.scala +++ b/elastic4s-tests/src/test/scala/com/sksamuel/elastic4s/cat/CatAliasTest.scala @@ -14,7 +14,8 @@ class CatAliasTest extends AnyFlatSpec with Matchers with DockerTests { client.execute { aliases( addAlias("ally1", "catalias"), - addAlias("ally2", "catalias") + addAlias("ally2", "catalias"), + addAlias("ally22", "catalias") ) }.await @@ -25,4 +26,13 @@ class CatAliasTest extends AnyFlatSpec with Matchers with DockerTests { result.result.map(_.alias).toSet.contains("ally1") shouldBe true result.result.map(_.alias).toSet.contains("ally2") shouldBe true } + + it should "return aliases matching a pattern" in { + val result = client.execute { + catAliases("ally2*") + }.await + result.result.map(_.alias).toSet.contains("ally1") shouldBe false + result.result.map(_.alias).toSet.contains("ally2") shouldBe true + result.result.map(_.alias).toSet.contains("ally22") shouldBe true + } }