From 45de95da48d26c6fc1a59464479e2c2df6256ee7 Mon Sep 17 00:00:00 2001 From: To-om Date: Fri, 2 Feb 2018 09:30:39 +0100 Subject: [PATCH] #47 Add settings in index creation --- app/org/elastic4play/database/DBIndex.scala | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/org/elastic4play/database/DBIndex.scala b/app/org/elastic4play/database/DBIndex.scala index 84aa65e..8d649c0 100644 --- a/app/org/elastic4play/database/DBIndex.scala +++ b/app/org/elastic4play/database/DBIndex.scala @@ -16,6 +16,7 @@ class DBIndex( db: DBConfiguration, nbShards: Int, nbReplicas: Int, + settings: Map[String, Any], implicit val ec: ExecutionContext) { @Inject def this( @@ -25,6 +26,13 @@ class DBIndex( db, configuration.getOptional[Int]("search.nbshards").getOrElse(5), configuration.getOptional[Int]("search.nbreplicas").getOrElse(1), + configuration.getOptional[Configuration]("search.settings") + .fold(Map.empty[String, Any]) { settings ⇒ + settings + .entrySet + .toMap + .mapValues(_.unwrapped) + }, ec) private[DBIndex] lazy val logger = Logger(getClass) @@ -55,10 +63,13 @@ class DBIndex( .toSeq db .execute { - CreateIndexDefinition(db.indexName) + val createIndexDefinition = CreateIndexDefinition(db.indexName) .mappings(modelsMapping) .shards(nbShards) .replicas(nbReplicas) + settings.foldLeft(createIndexDefinition) { + case (cid, (key, value)) ⇒ cid.indexSetting(key, value) + } } .map { _ ⇒ () } }