# Elastic Search - JavaEsSpark read is slow

**URL:** <https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [October 17, 2016, 3:27am UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143 "2016-10-17T03:27:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sukumar](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@sukumar](https://discuss.elastic.co/u/sukumar)\
**Post date:** [October 17, 2016, 3:27am UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/1 "2016-10-17T03:27:39Z")

</div>

I am using spark 1.4.1 and trying to read from the elasticsearch , its taking 1600 ms but when I tried to retrieve the same query using SENSE ,its taking just 3 ms. Can anyone help me to improve the query performance ?

JavaPairRDD esResultPair = JavaEsSpark.esJsonRDD(ctx, "index/02",string);

---

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [October 17, 2016, 7:18am UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/2 "2016-10-17T07:18:04Z")

</div>

Why you are using Spark ?

Usually latency in "big data" stuff is 1 seconds / 1 minute, so I imagine this is quite normal and is not elasticsearch related (run job, schedule resources etc...).

---

<div class="post-metadata">

**Author:** ![james.baiera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james.baiera/32/10209_2.png) [@james.baiera](https://discuss.elastic.co/u/james.baiera)\
**Post date:** [October 17, 2016, 3:57pm UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/3 "2016-10-17T15:57:17Z")

</div>

> [@sukumar](#):
>
> am using spark 1.4.1 and trying to read from the elasticsearch , its taking 1600 ms but when I tried to retrieve the same query using SENSE ,its taking just 3 ms.

Could you elaborate on what you're trying to read? Also could you elaborate on the query you are running in Sense?

---

<div class="post-metadata">

**Author:** ![sukumar](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@sukumar](https://discuss.elastic.co/u/sukumar)\
**Post date:** [October 18, 2016, 12:15am UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/4 "2016-10-18T00:15:09Z")

</div>

I replaced JavaESspark with JestClient and its working now. One request is taking 1round 120 ms. Thanks.

---

<div class="post-metadata">

**Author:** ![sukumar](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@sukumar](https://discuss.elastic.co/u/sukumar)\
**Post date:** [October 18, 2016, 12:21am UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/5 "2016-10-18T00:21:21Z")

</div>

I am running job using spark 1.4.1 and tried to replace the existing job with spark and elastic search, writing to elastic search using spark JavaESSpark is really fast but read is not as expected. Please find the simple query I ran in spark and SENSE.

"query" : {  
"bool" : {  
"must" : [ {  
"match" : {  
"full\_name" : {  
"query" : "JACQUELINE"  
}  
}  
}, {  
"match" : {  
"full\_name" : {  
"query" : "COLWILL"  
}  
}  
}, {  
"bool" : {  
"should" : [ {  
"match" : {  
"acct" : {  
"query" : 0  
}  
}  
}, {  
"match" : {  
"ids" : {  
"query" : ""  
}  
}  
} ]  
}  
} ]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [October 18, 2016, 10:16am UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/6 "2016-10-18T10:16:50Z")

</div>

How did you replace like this ? I am very curious to see the code source and how you submit your Spark job.

---

<div class="post-metadata">

**Author:** ![james.baiera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/james.baiera/32/10209_2.png) [@james.baiera](https://discuss.elastic.co/u/james.baiera)\
**Post date:** [October 18, 2016, 3:49pm UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/7 "2016-10-18T15:49:35Z")

</div>

> [@sukumar](#):
>
> I am running job using spark 1.4.1 and tried to replace the existing job with spark and Elasticsearch, writing to Elasticsearch using spark JavaESSpark is really fast but read is not as expected. Please find the simple query I ran in spark and SENSE.

Your query looks very specific, and thus will probably only retrieve a handful of results. It's important to note the difference between Sense and Spark. Sense is a GUI Client for Elasticsearch queries. Sense will only return the top ten results that match your query. It takes advantage of Elasticsearch's search features to do this incredibly fast (on the order of milliseconds). Spark is meant for heavy duty data processing. When using EsSpark, it targets a different search type which streams all of the data out of Elasticsearch for analysis in Spark. This tends to be a heavier request mechanic (operating over the course of multiple seconds).

If you are using this same query in Spark for reading, Spark will end up wasting a lot of time standing up multiple tasks to read the data from Elasticsearch, only get a few records, and then go through a costly job teardown process. EsSpark is not meant to be a fast client for retrieving very few records. It is meant to be a connector for data processing at scale. This specific of a query would probably be served better if it were executed from a regular application client.

---

<div class="post-metadata">

**Author:** ![sukumar](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@sukumar](https://discuss.elastic.co/u/sukumar)\
**Post date:** [October 18, 2016, 6:29pm UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/8 "2016-10-18T18:29:15Z")

</div>

Thanks for the clarification. Let me try with the large query for the large data set.

---

<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:22pm UTC](https://discuss.elastic.co/t/elastic-search-javaesspark-read-is-slow/63143/9 "2017-07-06T13:22:51Z")

</div>


