Iulian
Iulian

Reputation: 1536

Create index from raw JSON using elastic4s

I need to create an index that has some context completion suggester mappings as in (https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html). As I see in https://github.com/sksamuel/elastic4s/issues/452 this doesn't seem to be supported by the DSL.

So, it would be nice to create an index from a raw JSON string (similar to raw queries). Is it possible to achieve this?

Upvotes: 3

Views: 1263

Answers (1)

Bruno dos Santos
Bruno dos Santos

Reputation: 1361

Considering that you have the JSON mapping in a variable rawMapping like this:

val rawMapping =
    """{
          "service": {
                  "properties": {
                      "name": {
                          "type" : "string"
                      },
                      "tag": {
                          "type" : "string"
                      },
                      "suggest_field": {
                          "type": "completion",
                          "context": {
                              "color": {
                                  "type": "category",
                                  "path": "color_field",
                                  "default": ["red", "green", "blue"]
                              },
                              "location": {
                                  "type": "geo",
                                  "precision": "5m",
                                  "neighbors": true,
                                  "default": "u33"
                              }
                      }
                  }
              }
              }
          }"""

You can create the index using the raw mapping like this:

client.execute {
    create index "services" source rawMapping
}

Upvotes: 3

Related Questions