背景
ES 的磁盘占用是比较高的,因为做了一系列的查询优化
空间使用
- 显示原始信息,有
"_source": {"enabled": true}
- 建立索引,有
"index": "not_analyzed"
- 索引使用了
doc_value
,有"doc_values": true
_all
字段:把所有其它字段中的值,以空格为分隔符组成一个大字符串,然后被分析和索引,但是不存储,即能被查询,但不能被取回显示
经过这些默认的查询优化,会造成存储空间的冗余。
优化方案
去掉或者压缩_source
去掉_source
关闭 _source
{ "yourtype":{ "_source":{ "enabled":false }, "properties": { ... } } }
存储指定字段到 _source
{ "yourtype":{ "_source":{ "includes":["field1","field2"] }, "properties": { ... } } }
{ "yourtype":{ "_source":{ "excludes":["field1","field2"] }, "properties": { ... } } }
压缩_source
index.codec:best_compression
,
compress:true
去掉索引
启用索引
{ "test": { "_source": { "enabled": false }, "properties": { "title": { "type": "string", "index": "not_analyzed", "store": "true" }, "content": { "type": "string" } } } }
禁用索引
默认 store 即为 false,为禁用索引状态.
去掉 doc_value
禁用_all 字段
方法一,完全禁用:
在模板中设置
{ "mappings": { "type_1": { "properties": {...} }, "type_2": { "_all": { "enabled": false }, "properties": {...} } } }
- type_1 中的_all 字段是 enabled
- type_2 中的_all 字段是 disabled
方法二,排除无用字段
PUT my_index { "mappings": { "my_type": { "properties": { "title": { "type": "string" } "content": { "type": "string" }, "date": { "type": "date", "include_in_all": false }, "memo": { "type": "string", "index": "no", "store": true } } } }
也适用于 nested 字段
{ "mappings": { "my_type": { "include_in_all": false, "properties": { "title": { "type": "string" }, "author": { "include_in_all": true, "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" } } }, "editor": { "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string", "include_in_all": true } } } } } } }
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于