# \*Reducing\* geoshape tree\_levels doubles query time (1.7)

**URL:** <https://discuss.elastic.co/t/reducing-geoshape-tree-levels-doubles-query-time-1-7/40175>\
**Category:** Elasticsearch\
**Created:** [January 26, 2016, 11:08pm UTC](https://discuss.elastic.co/t/reducing-geoshape-tree-levels-doubles-query-time-1-7/40175 "2016-01-26T23:08:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Baker](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@Richard\_Baker](https://discuss.elastic.co/u/Richard_Baker)\
**Post date:** [January 26, 2016, 11:08pm UTC](https://discuss.elastic.co/t/reducing-geoshape-tree-levels-doubles-query-time-1-7/40175/1 "2016-01-26T23:08:55Z")

</div>

Hi There,

This is a first post, so please bear with me!

I'm running a 3 replica cluster with client node on ES 1.7 on 8 core/60Gb machines. I have an index containing various analysed fields and a nested geoshape. The stored geoshapes are generally "circles" of up to 400000 metres (~250 miles) radius.

Previously the index was mapped with the default geoshape precision/tree\_levels setting (50 metres) which I believe equates to a tree\_levels value of 12.

The index contains nearly 4 million documents (roughly 48 million due to nesting) and memory usage was around 30Gb.

Performance was good, average query between 100 - 200ms, but I was looking to reduce the memory usage.

I reindexed the data into another index with the mapping geoshape precision value of 500m (equating to tree\_levels 7). The data is identical, but query times are now double at 400 - 900 ms. Memory usage of this index has halved however!

I would have thought a lower tree\_levels value would have improved query times as there are fewer geohash terms in the prefix tree. The "performance considerations" section in the documentation cautions the use of high tree\_levels values, however i'm seeing quite a degradation in query performance with lower values.

I can't find any similar issues by searching. Any experience or wisdom would be greatly appreciated.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![nknize](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@nknize](https://discuss.elastic.co/u/nknize)\
**Post date:** [January 27, 2016, 3:10pm UTC](https://discuss.elastic.co/t/reducing-geoshape-tree-levels-doubles-query-time-1-7/40175/2 "2016-01-27T15:10:49Z")

</div>

Hi @Richard_Baker

Can you post the geo\_shape mapping and an example query that's causing the issue?

---

<div class="post-metadata">

**Author:** ![Richard\_Baker](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@Richard\_Baker](https://discuss.elastic.co/u/Richard_Baker)\
**Post date:** [January 27, 2016, 7:54pm UTC](https://discuss.elastic.co/t/reducing-geoshape-tree-levels-doubles-query-time-1-7/40175/3 "2016-01-27T19:54:12Z")

</div>

Thanks @nknzine

Here's the mapping: [https://gist.github.com/rjbaker/7752003e7d4990618dd2#file-users-1-2-json-L67-L68](https://gist.github.com/rjbaker/7752003e7d4990618dd2#file-users-1-2-json-L67-L68)

An example query looks like this: [https://gist.github.com/rjbaker/9a9666d17ac9a55ac5b7](https://gist.github.com/rjbaker/9a9666d17ac9a55ac5b7)

This has been running in production quite happily and with acceptable performance for quite some time using the default geoshape precision.

I was attempting to reduce memory usage by reducing the precision setting/tree\_levels. This has worked but this query is now unacceptably slow. Data was reindexed on the same cluster.

Many thanks.

---

<div class="post-metadata">

**Author:** ![Richard\_Baker](https://avatars.discourse-cdn.com/v4/letter/r/a87d85/32.png) [@Richard\_Baker](https://discuss.elastic.co/u/Richard_Baker)\
**Post date:** [January 29, 2016, 11:47am UTC](https://discuss.elastic.co/t/reducing-geoshape-tree-levels-doubles-query-time-1-7/40175/4 "2016-01-29T11:47:13Z")

</div>

Further to this, I have increased `tree_levels` to 10. This has increased memory usage by ~6GB but improved query speed considerably.

Everything I have read seems to imply that a lower tree levels value will improve query speed and reduce memory usage, at the expense of geospatial search accuracy. However, in practice I have found the opposite.

---

<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 5, 2017, 11:20pm UTC](https://discuss.elastic.co/t/reducing-geoshape-tree-levels-doubles-query-time-1-7/40175/5 "2017-07-05T23:20:23Z")

</div>


