# RAM usage and numeric fields with a limited amount of values and a lot of documents (KD Tree ?)

**URL:** <https://discuss.elastic.co/t/ram-usage-and-numeric-fields-with-a-limited-amount-of-values-and-a-lot-of-documents-kd-tree/159344>\
**Category:** Elasticsearch\
**Created:** [December 4, 2018, 11:18am UTC](https://discuss.elastic.co/t/ram-usage-and-numeric-fields-with-a-limited-amount-of-values-and-a-lot-of-documents-kd-tree/159344 "2018-12-04T11:18:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeMic](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@LeMic](https://discuss.elastic.co/u/LeMic)\
**Post date:** [December 4, 2018, 11:18am UTC](https://discuss.elastic.co/t/ram-usage-and-numeric-fields-with-a-limited-amount-of-values-and-a-lot-of-documents-kd-tree/159344/1 "2018-12-04T11:18:07Z")

</div>

Hi,

I want to understand why a field indexed as a keyword consume a constant amount of memory (RAM) while the same field indexed as a numeric datatype consumes memory in proportion to the number of documents in the index.

I know keywords are indexed in RAM by Finite state transducers (FST) and numeric fields by KD Tree (BKDReader) as showed by `GET /_segments?verbose=true&pretty` (RAM tree)

For example, if I try to index TCP ports values (numeric integers from 0 to 65535), the KDTree keep growing while the FST remains constant (65536 docs with each value, 1M docs, 10M docs...)

Is there a better way to index numeric fields with a limited amount of different values and a lot of documents while keeping the ability to sort them or querying a range ? (for identifiers I can use keywords but it's not relevant for all numbers).

Elasticsearch version : 5.5.0

---

<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:** [January 1, 2019, 11:18am UTC](https://discuss.elastic.co/t/ram-usage-and-numeric-fields-with-a-limited-amount-of-values-and-a-lot-of-documents-kd-tree/159344/2 "2019-01-01T11:18:14Z")

</div>

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