# Performance of Spatial Query

**URL:** <https://discuss.elastic.co/t/performance-of-spatial-query/15933>\
**Category:** Elasticsearch\
**Created:** [February 20, 2014, 8:23pm UTC](https://discuss.elastic.co/t/performance-of-spatial-query/15933 "2014-02-20T20:23:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahna\_mahna](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@mahna\_mahna](https://discuss.elastic.co/u/mahna_mahna)\
**Post date:** [February 20, 2014, 8:23pm UTC](https://discuss.elastic.co/t/performance-of-spatial-query/15933/1 "2014-02-20T20:23:40Z")

</div>

I am doing some proof of concepts for using ES 0.90.7 to do some indexing of spatial data that is currently being stored in PostGIS. I have created a 6 node cluster with 16G RAM and 16 cpus on each node, with a 2 shard index and have indexed 45M records in ES from PostGIS. My mapping is as follows (other details left out for brevity):

"mappings" : {  
"well\_heads" : {  
"properties" : {  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : "true",  
"geohash" : "true",  
"geohash\_prefix" : "true",  
"geohash\_precision" : 10  
}  
}  
}  
}

We do a lot queries like 'give me all wellheads that are within 1km of a school' and have created a simple ES query to answer this question:

{  
"query" : {  
"filtered" : {  
"query" : {  
"match-all" : {}  
},  
"filter" : {  
"geo\_distance" : {  
"distance\_type" : "plane",  
"distance" : "1km",  
"well\_heads.location" : [76.987, 38.987]  
}  
}  
}  
}  
}

This returned in about 30 seconds which I was expecting to be much faster. I began experimenting with a geohash\_cell filter that returned in about 20mS (cold) for a similar number of hits (~ 22k). I combined the geohash\_cell with a \_geo\_distance sort that executed in 19s which made me think that the processing time may be due to the calculation of distances. Is this correct or am I missing something obvious? Even when I went to a location where there was a single hit, the time was the same. This made me think that perhaps ES is doing an unbounded query against all the data.

I would love to have ES outperform PG. FWIW, the PG server is on a single machine that is 1/2 as beefy as the ES cluster and it returns in 365mS cold. I've played with different shard sizes, replicas, etc.

Thanks in advance.

Regards,  
Eric

---

<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 6, 2017, 1:48am UTC](https://discuss.elastic.co/t/performance-of-spatial-query/15933/2 "2017-07-06T01:48:31Z")

</div>


