-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add semantic text field type (#3141)
* Add semantic text field type * Remove comment
- Loading branch information
Showing
4 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
elastic4s-domain/src/main/scala/com/sksamuel/elastic4s/fields/SemanticTextField.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.sksamuel.elastic4s.fields | ||
|
||
object SemanticTextField { | ||
val `type`: String = "semantic_text" | ||
} | ||
case class SemanticTextField(override val name: String, inferenceId: String) extends ElasticField { | ||
override def `type`: String = SemanticTextField.`type` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...rs/src/main/scala/com/sksamuel/elastic4s/handlers/fields/SemanticTextFieldBuilderFn.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.sksamuel.elastic4s.handlers.fields | ||
|
||
import com.sksamuel.elastic4s.fields.SemanticTextField | ||
import com.sksamuel.elastic4s.json.{XContentBuilder, XContentFactory} | ||
|
||
object SemanticTextFieldBuilderFn { | ||
def toField(name: String, values: Map[String, Any]): SemanticTextField = SemanticTextField( | ||
name, | ||
values.get("inference_id").map(_.asInstanceOf[String]).get | ||
) | ||
|
||
def build(field: SemanticTextField): XContentBuilder = { | ||
val builder = XContentFactory.jsonBuilder() | ||
builder.field("type", field.`type`) | ||
builder.field("inference_id", field.inferenceId) | ||
builder.endObject() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters