Elastic4s ngram映射

Elastic4s ngram mapping

我必须使用 elastic4s 创建像这样的 ElasticSearch 映射:

  "mappings": {
    "properties": {
      "id": {
        "type": "keyword"
      },
      "name": {
       "type": "text",
       "analyzer": "ngram_analyzer",
       "fielddata": true
      },
      "lang": {
        "type": "keyword"
      },
      "order": {
        "type": "long"
      },
      "active": {
        "type": "boolean"
      }
      "description": {
        "type": "text"
      }
    }
  }

我能做到

def mapping: Option[MappingDefinition] =
    Some(
      properties(
        KeywordField("id"),
        KeywordField("lang"),
        BasicField("order", "long"),
        BasicField("active", "boolean"),
        TextField("description")
      )
    )

ID、语言、订单、活动和描述。
但是,我怎样才能为 name 做这样的映射呢?问题是里面的 analyzerfielddata

你应该使用这个:

TextField("name").fielddata(true).analyzer("ngram_analyzer")

您还需要确保在索引设置中正确创建 ngram_analyzer