# How to improve search performance

**URL:** <https://discuss.elastic.co/t/how-to-improve-search-performance/133949>\
**Category:** Elasticsearch\
**Created:** [May 30, 2018, 10:34pm UTC](https://discuss.elastic.co/t/how-to-improve-search-performance/133949 "2018-05-30T22:34:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![khubacher](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@khubacher](https://discuss.elastic.co/u/khubacher)\
**Post date:** [May 30, 2018, 10:34pm UTC](https://discuss.elastic.co/t/how-to-improve-search-performance/133949/1 "2018-05-30T22:34:10Z")

</div>

I have 200m documents where half are marked (with a field) src = 1 and the other src = 2.

When searching, on multiple fields (usually 6-8), the search time differs dramatically if the src is included.  
I realize that all the other fields query text are relatively rare, versus the src which is 100m no matter which one is picked. If I leave src out of the query, search time is 2.5x faster. (650ms down to about 260ms)  
I've tried setting it up as a must, as a filtered query and even in the should query but in all cases the search time is impacted similarly.

Is there a way to enforce the src in some way that doesn't incur such a high penalty?

Thanks

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [June 1, 2018, 8:35am UTC](https://discuss.elastic.co/t/how-to-improve-search-performance/133949/2 "2018-06-01T08:35:30Z")

</div>

One thing you could do is split your documents into two separate indexes, based on the value of src, ie. put all documents with src=1 in in one index and all documents with src=2 in another index. Then, at query time you can query one index to get docs with src=1, the other index to get all docs with src=2, or both indexes to get all documents.

If that does not work for you then a question would be: how has the src field been mapped? If you mapped src as a numeric datatype (`integer` or `long`), then that datatype is not optimized for these kind of term queries. [Consider mapping the src field as a `keyword` field instead](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/tune-for-search-speed.html#_map_identifiers_as_literal_keyword_literal).

---

<div class="post-metadata">

**Author:** ![khubacher](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@khubacher](https://discuss.elastic.co/u/khubacher)\
**Post date:** [June 1, 2018, 1:14pm UTC](https://discuss.elastic.co/t/how-to-improve-search-performance/133949/3 "2018-06-01T13:14:29Z")

</div>

Thanks Abdon. One consideration is to split it into 2 indexes but was hoping to avoid it. And yes, the field is a keyword field.  
Since my post I've been experimenting with post filters on the source field and that actually looks like it might do the trick. If I test without source as a field (this is just a test to compare the performance where source is not included) versus as a post filter, the performance is about the same so it appears a post filter doesn't impact the performance.

---

<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:** [June 29, 2018, 1:14pm UTC](https://discuss.elastic.co/t/how-to-improve-search-performance/133949/4 "2018-06-29T13:14:37Z")

</div>

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