# Geo Bounding Box/Polygon Queries getting slow in ES 6.2 than ES 2.3

**URL:** <https://discuss.elastic.co/t/geo-bounding-box-polygon-queries-getting-slow-in-es-6-2-than-es-2-3/132481>\
**Category:** Elasticsearch\
**Created:** [May 18, 2018, 11:39am UTC](https://discuss.elastic.co/t/geo-bounding-box-polygon-queries-getting-slow-in-es-6-2-than-es-2-3/132481 "2018-05-18T11:39:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![reetam.nath](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@reetam.nath](https://discuss.elastic.co/u/reetam.nath)\
**Post date:** [May 18, 2018, 11:39am UTC](https://discuss.elastic.co/t/geo-bounding-box-polygon-queries-getting-slow-in-es-6-2-than-es-2-3/132481/1 "2018-05-18T11:39:27Z")

</div>

Hi,  
I am doing a migration from Elasticsearch 2.3 to elasticesearch 6.2. The index migration was done successfully but i am facing a performance issue after the migration in Bounding box/polygon queries when used with terms query.  
Bellow are my findings:

Elasticsearch instance Info:  
{  
"capture\_index\_2" : {  
"settings" : {  
"index" : {  
"number\_of\_shards" : "5",  
"blocks" : {  
"write" : "false"  
},  
"provided\_name" : "capture\_index\_2",  
"max\_result\_window" : "50000",  
"creation\_date" : "1526027809998",  
"number\_of\_replicas" : "1",  
"uuid" : "Rlj8kwCoTReI6vfhjH9YeQ",  
"version" : {  
"created" : "6020299"  
}  
}  
}  
}  
}

Document Count : 240445029  
Size in bytes : 53.59 GB

My Query :  
{  
"query": {  
"bool": {  
"filter": [  
{  
"bool": {  
"must": [  
{  
"geo\_bounding\_box": {  
"alignedlocation": {  
"bottom\_left": {  
"lat": 32.77086742341999,  
"lon": -96.79832736358046  
},  
"top\_right": {  
"lat": 32.7731293740476,  
"lon": -96.77691577468067  
}  
}  
}  
},  
{  
"terms": {  
"vehicleType": [  
0,  
1  
]  
}  
},  
{  
"terms": {  
"dataformat": [  
0,  
1  
]  
}  
}  
],  
"should": [  
{  
"range": {  
"expirationdate": {  
"gt": "1526668200000"  
}  
}  
},  
{  
"range": {  
"datatypes": {  
"gte": "0",  
"lt": "2"  
}  
}  
},  
{  
"range": {  
"datatypes": {  
"gt": "4"  
}  
}  
}  
],  
"minimum\_should\_match": 1  
}  
}  
]  
}  
},  
"from": 0,  
"size": 1000,  
"sort": [  
{  
"starttime": {  
"order": "desc"  
}  
},  
{  
"uuid": {  
"order": "desc"  
}  
},  
{  
"eventid": {  
"order": "asc"  
}  
}  
]  
}

and in ES 2.3 this query takes 39 ms where in ES 6.2 it takes 370 ms and one interesting fact is if i remove the termsQueries from the ES 6.2 query the time reduce to 22 ms.

Requesting for assistance.

---

<div class="post-metadata">

**Author:** ![JKhondhu](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@JKhondhu](https://discuss.elastic.co/u/JKhondhu)\
**Post date:** [May 18, 2018, 11:48am UTC](https://discuss.elastic.co/t/geo-bounding-box-polygon-queries-getting-slow-in-es-6-2-than-es-2-3/132481/2 "2018-05-18T11:48:28Z")

</div>

If you run the same query (minus the removal of there termsQuery) with `"profile": true,` we can see the breakdown of such.

ref: [https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-profile.html#\_usage\_3](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-profile.html#_usage_3)

---

<div class="post-metadata">

**Author:** ![reetam.nath](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@reetam.nath](https://discuss.elastic.co/u/reetam.nath)\
**Post date:** [May 21, 2018, 9:43am UTC](https://discuss.elastic.co/t/geo-bounding-box-polygon-queries-getting-slow-in-es-6-2-than-es-2-3/132481/3 "2018-05-21T09:43:28Z")

</div>

Hi @JKhondhu,

Sorry for the late reply.. I ran the queries with "profile": true, and i attached the files bellow

1. [ES-6.2-with-terms query](https://gist.githubusercontent.com/reetam-nath/2fec2ba0470449689d9a57376f77cf33/raw/b6654ccfd6450008ef31b10545401740e92de477/ES-6.2-Profile.txt)
2. [ES-6.2-without-term-query](https://gist.githubusercontent.com/reetam-nath/f8573de7e0dd792d7c77230133c96b89/raw/991023d65bacf5ecd4aa3ee825b5ea1dd12151d4/ES-6.2-Profile-Without-terms.txt)
3. [ES-2.3](https://gist.githubusercontent.com/reetam-nath/acf09fd5c5262da4fc226b4606a12bb0/raw/1c40af1074455d1a21e7060691745f35c65e1ba8/ES-2.3-Profile.txt)

Please let me know if anything else required.

---

<div class="post-metadata">

**Author:** ![reetam.nath](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@reetam.nath](https://discuss.elastic.co/u/reetam.nath)\
**Post date:** [May 25, 2018, 12:50pm UTC](https://discuss.elastic.co/t/geo-bounding-box-polygon-queries-getting-slow-in-es-6-2-than-es-2-3/132481/4 "2018-05-25T12:50:54Z")

</div>

So i fix my Problem.  
Actually the fields on which terms queries were perform are actually of type integer .  
So according to the [Elasticsearch 6.2 documentation](https://www.elastic.co/guide/en/elasticsearch/reference/master/tune-for-search-speed.html#_mappings) numeric fields are optimized for range queries not for term queries. So converting the fields to keyword type solve my performance issue.  
I believe in case of Elastic search 2.3 this is not the case.

---

<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:** [June 22, 2018, 12:51pm UTC](https://discuss.elastic.co/t/geo-bounding-box-polygon-queries-getting-slow-in-es-6-2-than-es-2-3/132481/5 "2018-06-22T12:51:04Z")

</div>

Closed on June 22, 2018, 12:51pm UTC

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