From b9d39ab8029044e8fd0568c66fac9f800542072f Mon Sep 17 00:00:00 2001 From: Fabien Carrion Date: Fri, 11 Aug 2023 17:04:48 +0200 Subject: [PATCH] Feat: add support for date format in runtime mappings (#2897) --- .../requests/searches/SearchBodyBuilderFn.scala | 3 +++ .../elastic4s/requests/searches/RuntimeMapping.scala | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/searches/SearchBodyBuilderFn.scala b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/searches/SearchBodyBuilderFn.scala index 545b1aef6..799743e54 100644 --- a/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/searches/SearchBodyBuilderFn.scala +++ b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/searches/SearchBodyBuilderFn.scala @@ -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)) } diff --git a/elastic4s-domain/src/main/scala/com/sksamuel/elastic4s/requests/searches/RuntimeMapping.scala b/elastic4s-domain/src/main/scala/com/sksamuel/elastic4s/requests/searches/RuntimeMapping.scala index 8a7863028..387eb2ad9 100644 --- a/elastic4s-domain/src/main/scala/com/sksamuel/elastic4s/requests/searches/RuntimeMapping.scala +++ b/elastic4s-domain/src/main/scala/com/sksamuel/elastic4s/requests/searches/RuntimeMapping.scala @@ -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) }