# Will query in filter context be rewritten to scroll/scan way?

**URL:** <https://discuss.elastic.co/t/will-query-in-filter-context-be-rewritten-to-scroll-scan-way/45919>\
**Category:** Elasticsearch\
**Created:** [March 31, 2016, 10:45am UTC](https://discuss.elastic.co/t/will-query-in-filter-context-be-rewritten-to-scroll-scan-way/45919 "2016-03-31T10:45:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![makeyang](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@makeyang](https://discuss.elastic.co/u/makeyang)\
**Post date:** [March 31, 2016, 10:45am UTC](https://discuss.elastic.co/t/will-query-in-filter-context-be-rewritten-to-scroll-scan-way/45919/1 "2016-03-31T10:45:46Z")

</div>

let's say I did a term query in filter context, curretly dose ES have the ability to rewrite it to scroll/scan or query and fetch way?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [April 1, 2016, 11:22am UTC](https://discuss.elastic.co/t/will-query-in-filter-context-be-rewritten-to-scroll-scan-way/45919/2 "2016-04-01T11:22:48Z")

</div>

Hello, can you elaborate a bit more? Sorry but I don't really get your question.

Thanks  
Luca

---

<div class="post-metadata">

**Author:** ![makeyang](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@makeyang](https://discuss.elastic.co/u/makeyang)\
**Post date:** [April 5, 2016, 8:02am UTC](https://discuss.elastic.co/t/will-query-in-filter-context-be-rewritten-to-scroll-scan-way/45919/3 "2016-04-05T08:02:27Z")

</div>

when we do a search with query-then-fetch type, the actually way is get top docs on each shard and return hits to coordinator, the coordinator then merge and sort the results and drop the resut, then fetch the results.  
my question is this: if I construct a boolean filter(let's assume we use 1.7, actually the same thing with higher version), which acutally do not require sort way, then dose ES have the ability to rewrite this query to scroll/scan search type and don't do query-then-fetch mode but iterator throug shards?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [April 5, 2016, 8:57am UTC](https://discuss.elastic.co/t/will-query-in-filter-context-be-rewritten-to-scroll-scan-way/45919/4 "2016-04-05T08:57:27Z")

</div>

I am not sure what you mean by:

> [@makeyang](#):
>
> which acutally do not require sort way

The default sort if you don't specify any is by score, if that's what you meant. A normal search cannot become scroll/scan internally then. With recent changes made for 5.0 though, scan search type goes away and the same is achieved through sorting by `_doc`.

Hope this helps

---

<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:02pm UTC](https://discuss.elastic.co/t/will-query-in-filter-context-be-rewritten-to-scroll-scan-way/45919/5 "2017-07-05T23:02:21Z")

</div>


