# GET API performance

**URL:** <https://discuss.elastic.co/t/get-api-performance/150738>\
**Category:** Elasticsearch\
**Created:** [October 2, 2018, 4:40pm UTC](https://discuss.elastic.co/t/get-api-performance/150738 "2018-10-02T16:40:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)\
**Post date:** [October 2, 2018, 4:40pm UTC](https://discuss.elastic.co/t/get-api-performance/150738/1 "2018-10-02T16:40:19Z")

</div>

I was assuming that we could use elasticsearch as a sort of document store for high performance reads when accessing documents by id in addition to the amazing search engine.

However, I am finding that when accessing a single random document by id out of our cluster, it tends to take about 50ms. Our documents are fairly complex with a number of nested documents. 50ms is derived from profiling the async call to Elasticsearch from within the C# Nest client. For comparison, we are typically searching our entire index in that same amount of time with our smallest single field searches typically taking about 2-3ms which is viewable by profiling the same method.

Is this expected behavior or should I expect results comparable to redis when accessing by id (2ms)? We are currently running 5.5.

---

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [October 2, 2018, 7:44pm UTC](https://discuss.elastic.co/t/get-api-performance/150738/2 "2018-10-02T19:44:46Z")

</div>

Don't expect to be compared with redis (redis should be even faster than 2ms).  
But doing a GET is a simple TERM query, so should be faster than that (at about single digit ms). Maybe your data is too big for in-memory caching ? What about repeated calls to the same `_id` ?

---

<div class="post-metadata">

**Author:** ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)\
**Post date:** [October 2, 2018, 8:58pm UTC](https://discuss.elastic.co/t/get-api-performance/150738/3 "2018-10-02T20:58:01Z")

</div>

@ddorian43 Repeated calls do result in faster results but we obviously must have enough churn for our average in production to be that high. We have two 3GB shards and about 16GB of system memory with 6GB JVMs. There are 350K top level documents composed of 15M total documents with nested included. It makes sense that if it has to read from disk, even though they are very fast SSDs, it's going to experience some latency. I just wasn't expecting _that_ much.

I am very interested to learn that a GET to /index/type/id is actually a term query under the hood.

You are right that redis can be sub-millisecond, I was looking at data marshaling as well.

Thanks for the reply!

---

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [October 2, 2018, 9:31pm UTC](https://discuss.elastic.co/t/get-api-performance/150738/4 "2018-10-02T21:31:42Z")

</div>

Note that GET also searches the log, but it still should be in-memory in your case. But you have to see where your bottleneck is.

---

<div class="post-metadata">

**Author:** ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)\
**Post date:** [October 3, 2018, 1:34am UTC](https://discuss.elastic.co/t/get-api-performance/150738/5 "2018-10-03T01:34:20Z")

</div>

@ddorian43 Since have millions of other queries running, wouldn't those also be fighting for the cache? If GETing a document is simply a term query, then I'd think it's simply a matter of cache churn on lesser used IDs.

I've profiled queries, but not the GET API. I switched to a basic ids query and the profile has about 99% of the time spent on _next\_doc_.

Also, today I learned that issuing a GET with {"profile":true} as the payload actually overwrites that ID with that payload.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 3, 2018, 5:48am UTC](https://discuss.elastic.co/t/get-api-performance/150738/6 "2018-10-03T05:48:32Z")

</div>

Elasticsearch does not keep all data in memory, so will read from disk, although this may naturally be cached in the file system cache. The document source is stored compressed on disk, so there is also the additional overhead of decompressing the document before it can be returned.

---

<div class="post-metadata">

**Author:** ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)\
**Post date:** [October 3, 2018, 11:47am UTC](https://discuss.elastic.co/t/get-api-performance/150738/7 "2018-10-03T11:47:24Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> Elasticsearch does not keep all data in memory, so will read from disk, although this may naturally be cached in the file system cache. The document source is stored compressed on disk, so there is also the additional overhead of decompressing the document before it can be returned.

I guess I could try disabling compression as well. Is there anything I could do to get these "under the hood id queries" to remain in memory or even eagerly load the docs in memory assuming memory was not an issue? I'd like to avoid duplicating my docs in redis.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 3, 2018, 11:55am UTC](https://discuss.elastic.co/t/get-api-performance/150738/8 "2018-10-03T11:55:40Z")

</div>

I do not think it is possible to disable compression, just choose the level.

---

<div class="post-metadata">

**Author:** ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)\
**Post date:** [October 3, 2018, 12:00pm UTC](https://discuss.elastic.co/t/get-api-performance/150738/9 "2018-10-03T12:00:49Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> I do not think it is possible to disable compression, just choose the level.

Well that makes that easy!

---

<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:** [October 31, 2018, 12:01pm UTC](https://discuss.elastic.co/t/get-api-performance/150738/10 "2018-10-31T12:01:00Z")

</div>

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