简介
- es在创建索引文档时,会将所有的字段json序列化,保存为_source字段
用途
- 重做索引
- 修改mapping和分析器
- 高亮提醒
- 便于调试
保留还是不保留
- 取决于什么类型的数据,日志类型的索引基本不用保存
- 为了避免过多占用磁盘空间,可以开启文件压缩
样例
PUT tweets
{
"mappings": {
"_source": {
"enabled": false
}
}
}
DELETE logs
PUT logs
{
"mappings": {
"_source": {
"includes": [
"*.count",
"meta.description",
"meta.other.*"
],
"excludes": [
"meta.*"
]
}
}
}
PUT logs/_doc/1
{
"requests": {
"count": 10,
"foo": "bar"
},
"meta": {
"name": "Some metric",
"description": "Some metric description",
"other": {
"foo": "one",
"baz": "two"
}
}
}
GET logs/_search
{
"query": {
"match": {
"meta.other.foo": "one"
}
}
}
使用说明
- source的开启可以针对索引,也可以针对字段
- excludes的优先级高于includes
网友评论