# Does adding field collapsing improve the query latency

**URL:** <https://discuss.elastic.co/t/does-adding-field-collapsing-improve-the-query-latency/276426>\
**Category:** Elasticsearch\
**Created:** [June 18, 2021, 11:56pm UTC](https://discuss.elastic.co/t/does-adding-field-collapsing-improve-the-query-latency/276426 "2021-06-18T23:56:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhavik92](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavik92/32/50344_2.png) [@Bhavik92](https://discuss.elastic.co/u/Bhavik92)\
**Post date:** [June 18, 2021, 11:56pm UTC](https://discuss.elastic.co/t/does-adding-field-collapsing-improve-the-query-latency/276426/1 "2021-06-18T23:56:40Z")

</div>

In elastic-search, I am using `phrase_prefix` queries for my use case. Surprisingly, the query returns **results much faster** when adding `collapse` clause based on a field. This feels counter-intuitive to me since collapse should be doing additional processing on the results. Would anybody know the reasoning behind this / is the performance improvement due to collapse a known fact.

Sample query:  
`{ "timeout": "50ms", "size": 15, "query": { "multi_match": { "query": "random-text", "type": "phrase_prefix", "fields": ["valueNames.shingle^40", "valueNames.exact^120",] } }, "collapse": { "field": "keyName" } }`

When I remove the collapse from `keyName`, the query returns results in twice as much time (and sometimes even worse.)

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 21, 2021, 8:46am UTC](https://discuss.elastic.co/t/does-adding-field-collapsing-improve-the-query-latency/276426/2 "2021-06-21T08:46:55Z")

</div>

Have you tried to use the [search profiler in Kibana](https://www.elastic.co/guide/en/kibana/7.13/xpack-profiler.html)? This allows you to see where your query time is spent.

---

<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 19, 2021, 8:47am UTC](https://discuss.elastic.co/t/does-adding-field-collapsing-improve-the-query-latency/276426/3 "2021-07-19T08:47:24Z")

</div>

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