Skip to content

Commit

Permalink
Multiple patterns in CreateIndexTemplateRequest (#2446)
Browse files Browse the repository at this point in the history
* Multiple patterns in CreateIndexTemplateRequest

* fix tests

* createIndexTemplate with one pattern
  • Loading branch information
DenisNovac committed Jun 9, 2021
1 parent 57432c5 commit 76e5416
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.sksamuel.elastic4s.requests.indexes.{CreateIndexTemplateRequest, Dele

trait IndexTemplateApi {
def deleteIndexTemplate(name: String): DeleteIndexTemplateRequest = DeleteIndexTemplateRequest(name)
def createIndexTemplate(name: String, pattern: String): CreateIndexTemplateRequest =
def createIndexTemplate(name: String, pattern: Seq[String]): CreateIndexTemplateRequest =
CreateIndexTemplateRequest(name, pattern)
def createIndexTemplate(name: String, pattern: String): CreateIndexTemplateRequest =
CreateIndexTemplateRequest(name, Seq(pattern))
def getIndexTemplate(name: String): GetIndexTemplateRequest = GetIndexTemplateRequest(name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateIndexTemplateRequestTest extends AnyFunSuite with ElasticDsl with Ma

val templateName = "test_template"

val templateDef = createIndexTemplate(templateName, "index_pattern")
val templateDef = createIndexTemplate(templateName, Seq("index_pattern"))
.analysis(Analysis(Nil, normalizers = List(lowerCaseNormalizer)))

val req = CreateIndexTemplateHandler.build(templateDef)
Expand All @@ -25,7 +25,7 @@ class CreateIndexTemplateRequestTest extends AnyFunSuite with ElasticDsl with Ma

val templateName = "test_template_without_analysis"

val templateDef = createIndexTemplate(templateName, "index_pattern").settings(Map("number_of_shards" -> 1))
val templateDef = createIndexTemplate(templateName, Seq("index_pattern")).settings(Map("number_of_shards" -> 1))

val expectedEntityContent = """"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.sksamuel.elastic4s.requests.mappings.MappingDefinition
import com.sksamuel.exts.OptionImplicits.RichOptionImplicits

case class CreateIndexTemplateRequest(name: String,
pattern: String,
pattern: Seq[String],
settings: Map[String, Any] = Map.empty,
mappings: Seq[MappingDefinition] = Nil,
@deprecated("use the new analysis package", "7.0.1")
Expand All @@ -17,7 +17,8 @@ case class CreateIndexTemplateRequest(name: String,
priority: Option[Int] = None,
aliases: Seq[TemplateAlias] = Nil) {
require(name.nonEmpty, "template name must not be null or empty")
require(pattern.nonEmpty, "pattern must not be null or empty")
require(pattern.nonEmpty, "pattern list must not be null or empty")
require(!pattern.exists(_.isEmpty), "patterns must not be null or empty")

@deprecated("use new analysis package", "7.2.0")
def analysis(first: AnalyzerDefinition, rest: AnalyzerDefinition*): CreateIndexTemplateRequest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object CreateIndexTemplateBodyFn {
def apply(create: CreateIndexTemplateRequest): XContentBuilder = {

val builder = XContentFactory.jsonBuilder()
builder.array("index_patterns", Array(create.pattern))
builder.array("index_patterns", create.pattern.toArray)
create.order.foreach(builder.field("order", _))
create.version.foreach(builder.field("version", _))
create.priority.foreach(builder.field("priority", _))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IndexTemplateHttpTest
"create template" in {

val result = client.execute {
CreateIndexTemplateRequest("brewery_template", "brew*").mappings(
CreateIndexTemplateRequest("brewery_template", Seq("brew*")).mappings(
properties(
textField("name").boost(123),
doubleField("year_founded").ignoreMalformed(true)
Expand Down

0 comments on commit 76e5416

Please sign in to comment.