springboot3集成elasticsearch8时,Completion类型一直添加不成功,这是为啥?

我的实体类:

@CompletionField(maxInputLength = 200)
private Completion titleSuggestion;

保存的方法

UrlIndex urlIndex = elasticsearchOperations.save(url);

通过devtools查询是不是Completion类型:

GET /xxx/_mapping

发现是text类型

"titleSuggestion": {
  "properties": {
    "input": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    }
  }
},

这是为什么?

阅读 2.5k
1 个回答

解决了,原来要提前声明设置,如下:

PUT xxx
{
  "mappings": {
    "properties": {
      "titleSuggestion": {
        "type": "completion",
        "analyzer": "ik_smart"
      }
    }
  }
}

加好之后,再执行命令就可以看到了:

GET /xxx/_mapping

执行结果成功了!

"titleSuggestion": {
  "type": "completion",
  "analyzer": "ik_smart",
  "preserve_separators": true,
  "preserve_position_increments": true,
  "max_input_length": 50
},
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题