Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic ElasticSearch mapping using Elastic4s

I have a document that I want to index on elasticSearch, this document contains some dynamic keys that I can not know in advance, like "spanish" or "french" in the following example

"contents": {
    "title": {
        "spanish": "Hola amigos",
        "french" : "Bonjour les amis"
    }
}

I'm using the elastic4s DSL in order to make my mapping (Via the createIndex DSL), but I can not find how to create, with this library, a dynamic mapping based on the "match" option ( like suggested here), in order to specify a different analyzer for each language stored under the path contents.title.

Any track please ? :-)

like image 730
ylos Avatar asked Nov 10 '22 09:11

ylos


1 Answers

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?

like image 75
sksamuel Avatar answered Nov 14 '22 21:11

sksamuel