1、報錯資訊:
Fielddata is disabled on text fields by default. Set fielddata=true on [
createTime
] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.
2、翻譯如下:
預設情況下在文本字段中禁用 Fielddata。在字段 [
createTime
] 上設定 fielddata=true,以便通過不反轉反轉索引将 fielddata 加載到記憶體中。注意,這可能會使用大量記憶體,或者使用關鍵字 [keyWord] 字段代替。
3、報錯原因:
ElasticSearch 5.x 版本之後将 String 類型去掉了,以 text 和 keyWord 代替。
官方解釋如下:https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html
4、如何解決:
PUT 你的index/_mapping/你的type/
{
"properties": {
"你的字段": {
"type": "text或keyWord",
"fielddata": true
}
}
}
修改報錯中提到的字段類型,修改為 text 或 keyWord。以 createTime 字段為例:
PUT 我的index/_mapping/我的type/
{
"properties": {
"createTime": {
"type": "text",
"fielddata": true
}
}
}