# 为什么我开启了doc value的binary field会花费这么多磁盘空间？或者还有别的更好的办法？

**URL:** <https://discuss.elastic.co/t/doc-value-binary-field/236615>\
**Category:** 中文提问与讨论\
**Created:** [June 11, 2020, 4:23am UTC](https://discuss.elastic.co/t/doc-value-binary-field/236615 "2020-06-11T04:23:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nooneuse](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nooneuse](https://discuss.elastic.co/u/nooneuse)\
**Post date:** [June 11, 2020, 4:23am UTC](https://discuss.elastic.co/t/doc-value-binary-field/236615/1 "2020-06-11T04:23:18Z")

</div>

你好，  
（我的elasticsearch版本是6.8.0）  
我有很多DataSketches序列化数据存储在索引中的一个binary字段中。我需要反序列化它们，然后将它们组合在一起以获得它们的总估算值。因此，我写了一个DataSketches的聚合插件供Elasticsearch组合并计算它们，效果还行，但是我发现binary字段占用了很大的磁盘空间。  
我必须为binary field打开doc\_value，因为我需要聚合那些字段。但是它似乎占用了过多的磁盘空间，比如说，我关掉[\_source]以后它占用的磁盘空间为10GB。不过我将相同的数据放入了druid（一个开源OLAP引擎，也可以完成这项工作）中，发现不包含源数据的情况下这些数据仅花费50MB就可以存储。而且，如果我关闭此字段的doc value，在elasticsearch里存储占用为200MB，这才是可以接受的。  
我现在有点不明白为什么doc value需要这么多空间，而且我不想放弃我的思路（使用elasticsearch处理DataSketches对象），因为我发现使用我的聚合插件的Elasticsearch做这个事情比druid好像性能更好些。  
我觉得，es中binary的doc value是按照lucene的sorted docvalue来存的，（请参阅：[Index of /\_\_root/docs.lucene.apache.org/core/7\_7\_0/core/org/apache/lucene/codecs/lucene70](https://lucene.apache.org/core/7_7_0/core/org/apache/lucene/codecs/lucene70/) Lucene70DocValuesFormat.html），用于排序，聚合或者执行脚本。然后lucene的sorted是：

> "a mapping of ordinals to deduplicated terms is written as Prefix-compressed Binary, along with the per-document ordinals written using one of the numeric strategies above".

然而我的DataSketches序列化数据，显而易见基数极大，去重然后编码什么的没有意义。  
我该如何减少binary field type的磁盘空间成本？还是我可以使用其他数据类型或来替代binary type，或者我换一种方法？请帮助我，并给我一些建议，非常感谢。

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 28, 2020, 6:09am UTC](https://discuss.elastic.co/t/doc-value-binary-field/236615/3 "2020-07-28T06:09:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
