3

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?

1 Answer 1

3

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

you need the rawmapping string starts with "mappings" : { ... }. The API is now createIndex("services") source rawMapping

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.