Skip to content

Commit

Permalink
Feat: add support for date format in runtime mappings (#2897)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkfabs authored Aug 11, 2023
1 parent fa7b110 commit b9d39ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ object SearchBodyBuilderFn {
request.runtimeMappings.foreach { mapping =>
builder.startObject(mapping.field)
builder.field("type", mapping.`type`)

// format is only allowed with a type of date
mapping.format.foreach(builder.field("format", _))
mapping.script.foreach {
script => builder.rawField("script", ScriptBuilderFn(script))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package com.sksamuel.elastic4s.requests.searches

import com.sksamuel.elastic4s.requests.script.Script

case class RuntimeMapping(field: String, `type`: String, script: Option[Script] = None, fields: Seq[RuntimeMapping.Field] = Seq.empty)
case class RuntimeMapping(field: String, `type`: String, format: Option[String] = None, script: Option[Script] = None, fields: Seq[RuntimeMapping.Field] = Seq.empty)

object RuntimeMapping {
def apply(field: String, `type`: String, script: Script): RuntimeMapping =
RuntimeMapping(field, `type`, Some(script))
RuntimeMapping(field, `type`, None, Some(script))

def apply(field: String, `type`: String, script: Script, fields: Seq[Field]): RuntimeMapping =
RuntimeMapping(field, `type`, Some(script), fields)
RuntimeMapping(field, `type`, None, Some(script), fields)

def apply(field: String, `type`: String, scriptSource: String): RuntimeMapping =
RuntimeMapping(field, `type`, Some(Script(scriptSource)))
RuntimeMapping(field, `type`, None, Some(Script(scriptSource)))

def apply(field: String, `type`: String, scriptSource: String, fields: Seq[Field]): RuntimeMapping =
RuntimeMapping(field, `type`, Some(Script(scriptSource)), fields)
RuntimeMapping(field, `type`, None, Some(Script(scriptSource)), fields)

final case class Field(name: String, `type`: String)
}

0 comments on commit b9d39ab

Please sign in to comment.