doc_value是什么
绝大多数的fields在默认情况下是indexed,因此字段数据是可被搜索的。倒排索引中按照一定顺序存放着terms供搜索,当命中搜索时,返回包含term的document。
terms 中包含很多term
Doc_values 本质上是一个序列化的 列式存储,这个结构非常适用于聚合(aggregations)、排序(Sorting)、脚本(scripts access to field)等操作。而且,这种存储方式也非常便于压缩,特别是数字类型。这样可以减少磁盘空间并且提高访问速度。
Doc values 为on-disk 数据结构,在document索引时被创建。Doc values 存放的values和 _source这个meta-Fields是一致的。支持除了analyzed string 以外的所有类型。
doc_value特性
doc_value 默认情况下是enable的。
column-oriented(列式存储) 存放field,以便sort(排序)、aggregate(聚合)、access the field from a script(脚本)
disable doc_value:
PUT /lib3
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 0
},
"mappings": {
"user": {
"properties": {
"name": {
"type": "text"
},
"address": {
"type": "text"
},
"age": {
"type": "integer",
"doc_value": false
},
"interests": {
"type": "text"
},
"birthday": {
"type": "date"
}
}
}
}
}
DocValue其实是Lucene在构建倒排索引时,会额外建立一个有序的正排索引(基于document => field value的映射列表)。
{“birthday”:“1985-11-11”,age:23}
{“birthday”:“1989-11-11”,age:29}
document | age | birthday |
---|---|---|
doc1 | 23 | 1985-11-11 |
doc2 | 29 | 1989-11-11 |
注意:默认对不分词的字段时开启的,对分词自读那无效(需要把fielddata设置为true)
disable doc_value会怎样
消极影响:sort、aggregate、access the field from script将会无法使用
积极影响:节省磁盘空间