# Performance issue for search query is taking taking around 5 to 6 secs

**URL:** <https://discuss.elastic.co/t/performance-issue-for-search-query-is-taking-taking-around-5-to-6-secs/15483>\
**Category:** Elasticsearch\
**Created:** [January 29, 2014, 8:55pm UTC](https://discuss.elastic.co/t/performance-issue-for-search-query-is-taking-taking-around-5-to-6-secs/15483 "2014-01-29T20:55:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kondapallinaresh](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@kondapallinaresh](https://discuss.elastic.co/u/kondapallinaresh)\
**Post date:** [January 29, 2014, 8:55pm UTC](https://discuss.elastic.co/t/performance-issue-for-search-query-is-taking-taking-around-5-to-6-secs/15483/1 "2014-01-29T20:55:41Z")

</div>

Hi All,

```
 we had created the index of 130 million data with 5 shards and four 

```

nodes.we had written the query with query string passing around 100 search  
values with space separate and passing the results to another query.total  
it is taking around 5 to 6 secs to complete get the results for two  
queres.Is there any performance improvent suggestion.Below is the query i  
am running

qb =  
QueryBuilders.queryString(QotConstants.SERIAL\_NUMBER+"("+serialNumbers+")");

SearchResponse response =  
elasticClient.prepareSearch("index").setQuery(qb)

.setSearchType(SearchType.QUERY\_THEN\_FETCH).addField(QotConstants.INSTANCE\_ID).setFrom(0)  
.setSize(20000)  
.execute()  
.actionGet();  
results = response.getHits().hits();  
String instanceQueryString = "";  
int i=0;  
for (SearchHit hit : results) {  
instanceQueryString =instanceQueryString+"  
"+hit.getFields().get(QotConstants.INSTANCE\_ID).getValue();

}  
List\<Map\<String,Object\>\> hits = new ArrayList\<Map\<String,Object\>\>();  
if(!instanceQueryString.equals("")){  
response = elasticClient.prepareSearch("index")

.setQuery(QueryBuilders.queryString("PARENT\_INSTANCE\_ID:("+instanceQueryString.trim()+")"))  
.setSearchType(SearchType.QUERY\_THEN\_FETCH)  
.setFrom(0).setSize(200)  
.execute()  
.actionGet();

results = response.getHits().hits();  
for (SearchHit hit : results) {  
hits.add(hit.getSource());  
}  
}

Thanks for you help in advance

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1ad89fe6-f4ad-429f-9fa8-45b6607b93ac%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1ad89fe6-f4ad-429f-9fa8-45b6607b93ac%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [January 29, 2014, 9:29pm UTC](https://discuss.elastic.co/t/performance-issue-for-search-query-is-taking-taking-around-5-to-6-secs/15483/2 "2014-01-29T21:29:31Z")

</div>

It sounds like you don't really need scoring so you might want to use  
filters instead of the query\_string query. Perhaps you can try the terms  
filter instead. Maybe something like this:

```
  String[] terms = { "sn1", "sn2" };
  QueryBuilder q = 

```

QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),  
FilterBuilders.termsFilter("sn", terms));

Here is more info on why filters are better speedwise:

> **[All About Elasticsearch Filter BitSets
	  	 | Elastic](https://www.elastic.co/blog/all-about-elasticsearch-filter-bitsets)**
>
> WARNING: This article contains outdated information. We no longer recommend taking its advice. When building queries in Elasticsearch, you’ll often find yourself composing sets of filters. Say you nee...

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5c9e92e8-0404-4be2-b62b-f1daca44ddaf%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5c9e92e8-0404-4be2-b62b-f1daca44ddaf%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![kondapallinaresh](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@kondapallinaresh](https://discuss.elastic.co/u/kondapallinaresh)\
**Post date:** [January 30, 2014, 12:45am UTC](https://discuss.elastic.co/t/performance-issue-for-search-query-is-taking-taking-around-5-to-6-secs/15483/3 "2014-01-30T00:45:07Z")

</div>

Thanks Binh.

I had tried with using the Term Filter .I am seeing little performance  
improvement but not as expected (expected 1sec)

Any pointers.

Thanks

On Wednesday, January 29, 2014 1:29:31 PM UTC-8, Binh Ly wrote:

> It sounds like you don't really need scoring so you might want to use  
> filters instead of the query\_string query. Perhaps you can try the terms  
> filter instead. Maybe something like this:
> 
> ```
> String[] terms = { "sn1", "sn2" };
> QueryBuilder q = 
> 
> ```
> 
> QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),  
> FilterBuilders.termsFilter("sn", terms));
> 
> Here is more info on why filters are better speedwise:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d9088182-282e-492b-a6b6-8c49204014a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d9088182-282e-492b-a6b6-8c49204014a3%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:54am UTC](https://discuss.elastic.co/t/performance-issue-for-search-query-is-taking-taking-around-5-to-6-secs/15483/4 "2017-07-06T01:54:04Z")

</div>


