# How to improve my GeoPoint ElasticSearch Index for better response time?

**URL:** <https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [July 15, 2020, 6:31pm UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353 "2020-07-15T18:31:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zoomash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zoomash/32/66505_2.png) [@zoomash](https://discuss.elastic.co/u/zoomash)\
**Post date:** [July 15, 2020, 6:31pm UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/1 "2020-07-15T18:31:18Z")

</div>

Below is my Index (tz\_geo) and mapping details:

**Index setting:**

```auto
{
  "index.blocks.read_only_allow_delete": "false",
  "index.priority": "1",
  "index.query.default_field": [
    "*"
  ],
  "index.write.wait_for_active_shards": "1",
  "index.refresh_interval": "30s",
  "index.number_of_replicas": "7"
}

```

**Mapping:**

```auto
{
  "mapping": {
    "properties": {     
      "geo": {
        "type": "geo_point"
      },
      "gnameid": {
        "type": "long",
        "index": false
      },
      "iso": {
        "type": "keyword",
        "index": false
      },
      "locid": {
        "type": "long",
        "index": false
      },      
      "tz": {
        "type": "keyword",
        "index": false
      }
    }
  }
}

```

**ElasticSearch details:**

```auto
{
  "name" : "node-1",
  "cluster_name" : "test-cluster",
  "cluster_uuid" : "ET-Gwb-iR4mCmzZUppuOKw",
  "version" : {
    "number" : "7.2.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "508c38a",
    "build_date" : "2019-06-20T15:54:18.811730Z",
    "build_snapshot" : false,
    "lucene_version" : "8.0.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

```

**Number of nodes in cluster:** 11

**Index data size:** 9.6 GB

**Total documents in Index:** 12025944

**My Geo Search using C# ElasticSearch NEST**

```auto
var result = await ES_Client.SearchAsync<ES_TZGeo>(s => s
                   .Index("tz_geo")                   
                   .Query(query => query.Bool(b => b.Filter(filter => filter
                   .GeoDistance(geo => geo
                       .Field(f => f.geo)
                       .Distance("500km").Location(lat, lon)
                       .DistanceType(GeoDistanceType.Arc)

                   )

                   )

                   )

                )
                   .Sort(sort => sort
                       .GeoDistance(g => g
                           .Field(f => f.geo)
                           .Order(SortOrder.Ascending)
                           .Unit(DistanceUnit.Kilometers)
                           .Points(new GeoLocation(lat, lon))
                           .DistanceType(GeoDistanceType.Arc)))
                           .Size(1)
                   );

```

The above search will find the nearest document based on lat,lon provided.

We are seeing that sometimes the response is more than 1 sec for the above query. Is there any recommendation on how to improve on this search either in terms of NEST or maybe change the replicas, etc?

Thank you for your time.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [July 16, 2020, 5:18am UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/2 "2020-07-16T05:18:59Z")

</div>

The performance of this query should improve if you change the units for `sorting` to be meters instead of kilometers.

---

<div class="post-metadata">

**Author:** ![zoomash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zoomash/32/66505_2.png) [@zoomash](https://discuss.elastic.co/u/zoomash)\
**Post date:** [July 16, 2020, 5:41am UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/3 "2020-07-16T05:41:05Z")

</div>

> [@zoomash](#):
>
> `.Distance("500km").Location(lat, lon)`

Will I also need to change the Query part and send the distance as meter instead of km or is it just for sorting?

Thanks for your reply.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [July 16, 2020, 5:46am UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/4 "2020-07-16T05:46:12Z")

</div>

just sorting

---

<div class="post-metadata">

**Author:** ![zoomash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zoomash/32/66505_2.png) [@zoomash](https://discuss.elastic.co/u/zoomash)\
**Post date:** [July 16, 2020, 5:58am UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/5 "2020-07-16T05:58:48Z")

</div>

Thank you for your answer. Really appreciate it.

May I know what is the reasoning behind this? Is there anywhere I could read more about this?

Also, if you have time, will changing the replica shard to higher values help improve the search?

Thank you.

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [July 16, 2020, 6:07am UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/6 "2020-07-16T06:07:32Z")

</div>

The reason is a limitation in an efficient lucene algorithm to perform sorting as it only works when distance units are in meters:

> <https://github.com/elastic/elasticsearch/blob/954afd94fe859209522a6d63fcb15dd9ef6c9df2/server/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java#L499>

If units are different than meters, we use a naive approach where we calculate the distance of all points in the index which is less efficient.

Increase the number of replicas should not improve the performance of the query but it will help if you have many concurrent requests. How many shards do you have in the index?

---

<div class="post-metadata">

**Author:** ![zoomash](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zoomash/32/66505_2.png) [@zoomash](https://discuss.elastic.co/u/zoomash)\
**Post date:** [July 16, 2020, 8:18am UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/7 "2020-07-16T08:18:47Z")

</div>

For this index it is set with 1 primary and 7 replica for a 11 node cluster.

Any suggestions to improve this?

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [July 16, 2020, 8:29am UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/8 "2020-07-16T08:29:50Z")

</div>

I expect this topology to work on a high concurrency environment. For the size of the index I think having one primary is fine.

You might win a bit of performance having one more primary but I am hesitant to recommend that. I think the only way to know for sure if it helps your case is by testing with a realistic workload.

by the way, did it help the advise above? Could you share the numbers?

---

<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:** [August 13, 2020, 8:30am UTC](https://discuss.elastic.co/t/how-to-improve-my-geopoint-elasticsearch-index-for-better-response-time/241353/9 "2020-08-13T08:30:03Z")

</div>

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