# Geo\_polygon query in ES5.6 is slow?

**URL:** <https://discuss.elastic.co/t/geo-polygon-query-in-es5-6-is-slow/103289>\
**Category:** Elasticsearch\
**Created:** [October 10, 2017, 4:06am UTC](https://discuss.elastic.co/t/geo-polygon-query-in-es5-6-is-slow/103289 "2017-10-10T04:06:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacki3lene](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jacki3lene/32/22913_2.png) [@jacki3lene](https://discuss.elastic.co/u/jacki3lene)\
**Post date:** [October 10, 2017, 4:06am UTC](https://discuss.elastic.co/t/geo-polygon-query-in-es5-6-is-slow/103289/1 "2017-10-10T04:06:38Z")

</div>

Hello!

We are in the process of migrating our cluster from ES 1.5.2 to ES 5.6.2. We are running some performance tests on both of the clusters and it looks like geo\_polygon query is slow in ES 5.6.2. Both have the same index settings, 5 shards and 1 replica:

ES1.5 results:  
Thread Stats Avg Stdev Max +/- Stdev  
Latency 1.64s 544.52ms 4.82s 70.05%  
Req/Sec 3.99 3.97 30.00 72.31%  
Latency Distribution  
50% 1.56s  
75% 1.95s  
90% 2.38s  
99% 3.22s  
25911 requests in 15.00m, 138.78MB read  
Requests/sec: 28.79  
Transfer/sec: 157.89KB

ES5.6 results:  
Thread Stats Avg Stdev Max +/- Stdev  
Latency 3.71s 1.71s 10.49s 71.56%  
Req/Sec 2.65 3.73 30.00 86.56%  
Latency Distribution  
50% 3.39s  
75% 4.63s  
90% 6.05s  
99% 9.09s  
11628 requests in 15.00m, 68.58MB read  
Requests/sec: 12.92  
Transfer/sec: 78.03KB

The performance script reads from a file that has the queries specific to its version:

ES1.5 query sample:  
{  
"size": 3000,  
"filter": {  
"geo\_polygon": {  
"property.location": {  
"points": [  
{  
"lat": -33.91248,  
"lon": 151.15363  
},  
{  
"lat": -33.91248,  
"lon": 151.19965  
},  
{  
"lat": -33.94949,  
"lon": 151.19965  
},  
{  
"lat": -33.94949,  
"lon": 151.15363  
},  
{  
"lat": -33.91248,  
"lon": 151.15363  
}  
]  
}  
}  
},  
"fields": [  
"id",  
"ota\_hotel\_code",  
"provider\_code"  
]  
}

ES5.6 query sample:  
{  
"size": 3000,  
"query": {  
"bool": {  
"must": {  
"match\_all": {}  
},  
"filter": {  
"geo\_polygon": {  
"location": {  
"points": [  
{  
"lat": -33.91248,  
"lon": 151.15363  
},  
{  
"lat": -33.91248,  
"lon": 151.19965  
},  
{  
"lat": -33.94949,  
"lon": 151.19965  
},  
{  
"lat": -33.94949,  
"lon": 151.15363  
},  
{  
"lat": -33.91248,  
"lon": 151.15363  
}  
]  
}  
}  
}  
}  
},  
"\_source": {  
"includes": [  
"id",  
"ota\_hotel\_code",  
"provider\_code"  
]  
}  
}

We have tried rerunning the performance script a couple of times and ES1.5 has a much more consistent result of 23req/s whereas ES5.6 some times fluctuates between 12req/s to 23req/s.

We are not sure whether our query in 5.6 is correct or maybe we are missing some configuration.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 10, 2017, 5:56am UTC](https://discuss.elastic.co/t/geo-polygon-query-in-es5-6-is-slow/103289/2 "2017-10-10T05:56:20Z")

</div>

Some thoughts here:

- The query is not exactly the same. 1.5 uses a top level filter which should have been rewritten as a post\_filter instead of a bool query with a filter clause.
- Could you try by not setting the size parameter to see if it actually comes from the geo part or the fetch phase?

---

<div class="post-metadata">

**Author:** ![jacki3lene](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jacki3lene/32/22913_2.png) [@jacki3lene](https://discuss.elastic.co/u/jacki3lene)\
**Post date:** [October 11, 2017, 12:07am UTC](https://discuss.elastic.co/t/geo-polygon-query-in-es5-6-is-slow/103289/3 "2017-10-11T00:07:54Z")

</div>

Thanks for your response!

I tried rerunning the query using constant score filter:

{  
"size": 3000,  
"query": {  
"constant\_score": {  
"filter": {  
"geo\_polygon": {  
"location": {  
"points": [  
{  
"lat": -33.91248,  
"lon": 151.15363  
},  
{  
"lat": -33.91248,  
"lon": 151.19965  
},  
{  
"lat": -33.94949,  
"lon": 151.19965  
},  
{  
"lat": -33.94949,  
"lon": 151.15363  
},  
{  
"lat": -33.91248,  
"lon": 151.15363  
}  
]  
}  
}  
}  
}  
},  
"\_source": {  
"includes": [  
"id",  
"ota\_hotel\_code",  
"provider\_code"  
]  
}  
}

And the results was pretty much the same at around 13req/s.

I took your suggestion and removed the size param and that made the difference, it's way more faster at 160.19 req/s for ES5 and 151.23 req/s for ES1.5.

However, we need to specify a huge size for this query to get all the possible docs within the polygon.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 3, 2017, 7:55am UTC](https://discuss.elastic.co/t/geo-polygon-query-in-es5-6-is-slow/103289/4 "2017-11-03T07:55:15Z")

</div>

I’m not sure if there is any optimization in this case.  
I’m surprised that reading \_source is super different between 1.x and 5.x though.

@jpountz do you have an idea?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 3, 2017, 11:19am UTC](https://discuss.elastic.co/t/geo-polygon-query-in-es5-6-is-slow/103289/5 "2017-11-03T11:19:10Z")

</div>

Does it make a difference if you keep size:3000 but disable source filtering and always get the whole source?

---

<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:** [December 1, 2017, 11:19am UTC](https://discuss.elastic.co/t/geo-polygon-query-in-es5-6-is-slow/103289/6 "2017-12-01T11:19:14Z")

</div>

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