使用ElasticSearch的默認配置會使我們在索引不存在於mapping中的字段時,會自動創建
我們可以設置關閉動態創建mapping
執行如下操作:
PUT /索引名/索引類型/_mapping { "dynamic":false }
更嚴格一點可以設置不在mapping中的字段的數據不能寫入ES
{ "dynamic":"strict" }
這樣我們之后寫入非手動創建的其他字段數據時會得到如下錯誤:
mapping set to strict, dynamic introduction of [hatae] within [data] is not allowed