温馨提示:本文翻译自stackoverflow.com,查看原文请点击:scala - creating settings of index using elastic4s

scala - 使用elastic4s创建索引设置

发布于 2020-03-27 16:15:50

我有一些课:

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_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做到这一点?

查看更多

提问者
Murat Kenesbayev
被浏览
71
Murat Kenesbayev 2020-01-31 17:12

好。的许多功能已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")
    ))
  )

发布
问题

分享
好友

手机
浏览

扫码手机浏览