# Query is slow!

**URL:** https://discuss.elastic.co/t/query-is-slow/34894
**Category:** Elasticsearch
**Created:** [November 18, 2015, 8:10am UTC](https://discuss.elastic.co/t/query-is-slow/34894 "2015-11-18T08:10:28Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![yuxiaobing](https://avatars.discourse-cdn.com/v4/letter/y/e56c9b/32.png) [@yuxiaobing](https://discuss.elastic.co/u/yuxiaobing)
#### Post date: [November 18, 2015, 8:10am UTC](https://discuss.elastic.co/t/query-is-slow/34894/1 "2015-11-18T08:10:29Z")

</div>

My query hits too many results,and I just need any ten terms,but elasticsearch will sort all the hited terms by relevancy.  
Is there a method I can forbidden this feature?

---

<div class="post-metadata">

### Author: ![aacb9](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@aacb9](https://discuss.elastic.co/u/aacb9)
#### Post date: [November 18, 2015, 8:31am UTC](https://discuss.elastic.co/t/query-is-slow/34894/2 "2015-11-18T08:31:42Z")

</div>

Look into using filter instead of query? You might want something like [https://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-terms-filter.html](https://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-terms-filter.html)

---

<div class="post-metadata">

### Author: ![yuxiaobing](https://avatars.discourse-cdn.com/v4/letter/y/e56c9b/32.png) [@yuxiaobing](https://discuss.elastic.co/u/yuxiaobing)
#### Post date: [November 18, 2015, 8:55am UTC](https://discuss.elastic.co/t/query-is-slow/34894/3 "2015-11-18T08:55:35Z")

</div>

Thank you for your answer.I think the sort process is after the query and the filter, I want forbidden it.

---

<div class="post-metadata">

### Author: ![aacb9](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@aacb9](https://discuss.elastic.co/u/aacb9)
#### Post date: [November 18, 2015, 8:56am UTC](https://discuss.elastic.co/t/query-is-slow/34894/4 "2015-11-18T08:56:22Z")

</div>

Filter is not sorted by relevance, query is.

---

<div class="post-metadata">

### Author: ![yuxiaobing](https://avatars.discourse-cdn.com/v4/letter/y/e56c9b/32.png) [@yuxiaobing](https://discuss.elastic.co/u/yuxiaobing)
#### Post date: [November 18, 2015, 9:25am UTC](https://discuss.elastic.co/t/query-is-slow/34894/5 "2015-11-18T09:25:59Z")

</div>

the sort process is after query and filters before return results.that is query&filter -\> sort -\> return results.

---

<div class="post-metadata">

### Author: ![aacb9](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@aacb9](https://discuss.elastic.co/u/aacb9)
#### Post date: [November 18, 2015, 9:29am UTC](https://discuss.elastic.co/t/query-is-slow/34894/6 "2015-11-18T09:29:00Z")

</div>

Please have you tried a filter? Filter does not score relevance. Are you running vs an analyzed or non analyzed field?

[https://www.elastic.co/guide/en/elasticsearch/guide/current/\_queries\_and\_filters.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/_queries_and_filters.html)

---

<div class="post-metadata">

### Author: ![yuxiaobing](https://avatars.discourse-cdn.com/v4/letter/y/e56c9b/32.png) [@yuxiaobing](https://discuss.elastic.co/u/yuxiaobing)
#### Post date: [November 18, 2015, 9:35am UTC](https://discuss.elastic.co/t/query-is-slow/34894/7 "2015-11-18T09:35:29Z")

</div>

I had tried it on analyzed field,but slowly too.the more docs the query&filter htis, the slower the query&filter.But I only want ten docs it hits,so I think the time is constant.

---

<div class="post-metadata">

### Author: ![aacb9](https://avatars.discourse-cdn.com/v4/letter/a/a698b9/32.png) [@aacb9](https://discuss.elastic.co/u/aacb9)
#### Post date: [November 18, 2015, 9:39am UTC](https://discuss.elastic.co/t/query-is-slow/34894/8 "2015-11-18T09:39:55Z")

</div>

It depends on what you're trying to do. Are you basically trying to do a search for basically key=value?

e.g. request.verb: "HEAD"?

Then you can maybe use a non-analyzed field and a term filter. If you're trying to do some search against an analyzed field your options for speeding up query may be more limited besides throwing more resource at the search.

If you could paste your exact query (or some general form) would be a lot more helpful.

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [November 18, 2015, 8:12pm UTC](https://discuss.elastic.co/t/query-is-slow/34894/9 "2015-11-18T20:12:02Z")

</div>

Wrapping the query in a constant score query will provide a uniform score,  
but you will have no control over what elements will appear in the top 10.  
It is not like a RDBMS where the rows are returned by their place in the  
index.

[https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-constant-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-constant-score-query.html)

Ivan

---

<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 5, 2017, 11:37pm UTC](https://discuss.elastic.co/t/query-is-slow/34894/10 "2017-07-05T23:37:29Z")

</div>


