報錯原因
我的Elasticsearch是"6.4.0"版本,當我創建字段時
{ "domain": { "type": "string", "index": "not_analyzed" } }
原因分析
查看官方文檔后發現是在新版本中已經移除該操作方式了
Elasticsearch從5.X
就引入了text
和keyword
,其中keyword
適用於不分詞字段,搜索時只能完全匹配,這時string
還保留着。
到了6.X
就徹底移除string
了。
另外,"index"
的值只能是boolean變量了。
解決方法
修改為
{ "domain":{ "type":"text", "index":"false" }, }
出現的第二個問題
1. 此時拋出了另外一個error
{ "type": "illegal_argument_exception", "reason": "Rejecting mapping update to [hn] as the final mapping would have more than 1 type: [poll, job, story]" }
2. 這個異常引發的原因同樣是版本問題
在Elasticsearch 6.0.0或更高版本中創建的索引可能只包含單個mapping type。在具有多種映射類型的5.x中創建的索引將繼續像以前一樣在Elasticsearch 6.x中運行。映射類型將在Elasticsearch 7.0.0中完全刪除。