Skip to content

Commit

Permalink
#47 Add settings in index creation
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Feb 2, 2018
1 parent eec33f6 commit 45de95d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/org/elastic4play/database/DBIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class DBIndex(
db: DBConfiguration,
nbShards: Int,
nbReplicas: Int,
settings: Map[String, Any],
implicit val ec: ExecutionContext) {

@Inject def this(
Expand All @@ -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)
Expand Down Expand Up @@ -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 { _ () }
}
Expand Down

0 comments on commit 45de95d

Please sign in to comment.