Scala 使用elastic4s创建索引设置
我有一些课:Scala 使用elastic4s创建索引设置,scala,
elasticsearch,elastic4s,query-analyzer,Scala,
elasticsearch,Elastic4s,Query Analyzer,我有一些课: class SomeClass(val client: ElasticClient, val config: Config, val configName: String)(implicit val ec: ExecutionContext) extends ElasticSearchRepositoryWrapper[AnotherClass]{ override def mapping: Option[MappingDefinition] = Some(
class SomeClass(val client: ElasticClient, val config: Config, val configName: String)(implicit val ec: ExecutionContext)
extends ElasticSearchRepositoryWrapper[AnotherClass]{
override def mapping: Option[MappingDefinition] = Some(
properties(
KeywordField("id"),
TextField("name").fielddata(true).analyzer("ngram_analyzer"),
KeywordField("lang"),
BasicField("order", "long"),
...
)
)
我正在使用此映射使用repository.createIndexIfNotExists()
创建索引。现在我必须在我的索引设置中创建
ngram\u analyzer
:
"settings": {
"index": {
"analysis": {
"analyzer": {
"ngram_analyzer": {
"filter": [
"lowercase"
],
"tokenizer": "my_tokenizer"
}
},
"tokenizer": {
"my_tokenizer": {
"token_chars": [
"letter",
"digit"
],
"min_gram": "3",
"type": "ngram",
"max_gram": "3"
}
}
}
}
我如何使用elastic4s来实现这一点?好的。
createIndexIfNotExists()
的许多函数都已弃用。因此,我使用了CreateIndexRequest
将分析器放置在以下位置:
CreateIndexRequest(repository.indexName, analysis = Option(ngramAnalyzer), mapping = repository.mapping)
.shards(repository.shards)
.replicas(repository.replicas)
我初始化了我的分析器,如下所示:
val ngramAnalyzer = Analysis(
List(CustomAnalyzer(
name = "ngram_analyzer",
tokenizer = "ngram",
charFilters = Nil,
tokenFilters = List("lowercase")
))
)