Dynamic ElasticSearch mapping using Elastic4s Dynamic ElasticSearch mapping using Elastic4s elasticsearch elasticsearch

Dynamic ElasticSearch mapping using Elastic4s


You can't do what you want in the elastic4s Scala API at the moment. But you can create a dynamic template in the Java API and use the Scala API for the rest of your calls.

The dynamic template can be set to use a regex and apply a mapping. But since you will really know your countries in advance (there's only ~200) why not just spend the time and make a mapping?


This is how the elastic4s documentation says to do it : (https://github.com/sksamuel/elastic4s/blob/master/guide/index.md)

val settings = ImmutableSettings.settingsBuilder().put("cluster.name","blah")val client = ElasticClient.remote("ip.address",portNum)client.execute { index into "indexname/indexType" doc StringSource(jsonDoc.toString)}

where StringSource extends DocumentSourceIf you able to marshall your input into JSON, this is the best way to do it.