# Sort After Specifying Fields in QueryStringQuery

**URL:** <https://discuss.elastic.co/t/sort-after-specifying-fields-in-querystringquery/4545>\
**Category:** Elasticsearch\
**Created:** [June 3, 2011, 7:43pm UTC](https://discuss.elastic.co/t/sort-after-specifying-fields-in-querystringquery/4545 "2011-06-03T19:43:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [June 3, 2011, 7:43pm UTC](https://discuss.elastic.co/t/sort-after-specifying-fields-in-querystringquery/4545/1 "2011-06-03T19:43:20Z")

</div>

Hi,

Using QueryStringQuery, if I searched on "\_all:smith\*" and did a sort-  
by-name, without specifying fields to sort on using  
QueryStringQuery.field() , the sort would span across all 2000 results  
returned, paged in four 500 row pages. The pages were sorted correctly

- The first page: A to G second: G to P third: P to W fourth:  
everything else

Now that I search on "smith\*" and then specify 4 fields using  
QueryStringQuery.field() and one boosted field, I find that I get 4  
pages each sorted A-to-Z. So the first page starts with A and ends in  
Z, the second page starts with A and ends in Z, and the third.

Best Regards,

David

.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 3, 2011, 10:17pm UTC](https://discuss.elastic.co/t/sort-after-specifying-fields-in-querystringquery/4545/2 "2011-06-03T22:17:59Z")

</div>

Gist a curl recreation, will have a look. [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help).

On Friday, June 3, 2011 at 10:43 PM, davrob2 wrote:

> Hi,
> 
> Using QueryStringQuery, if I searched on "\_all:smith\*" and did a sort-  
> by-name, without specifying fields to sort on using  
> QueryStringQuery.field() , the sort would span across all 2000 results  
> returned, paged in four 500 row pages. The pages were sorted correctly
> 
> - The first page: A to G second: G to P third: P to W fourth:  
> everything else
> 
> Now that I search on "smith\*" and then specify 4 fields using  
> QueryStringQuery.field() and one boosted field, I find that I get 4  
> pages each sorted A-to-Z. So the first page starts with A and ends in  
> Z, the second page starts with A and ends in Z, and the third.
> 
> Best Regards,
> 
> David
> 
> .

---

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [June 4, 2011, 7:59pm UTC](https://discuss.elastic.co/t/sort-after-specifying-fields-in-querystringquery/4545/3 "2011-06-04T19:59:03Z")

</div>

Apologies, this was a client side issue. Server-side sorting flag had  
been turned off in the client.

On Jun 3, 11:17 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Gist a curl recreation, will have a look.[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help).
> 
> On Friday, June 3, 2011 at 10:43 PM, davrob2 wrote:
> 
> > Hi,
> 
> > Using QueryStringQuery, if I searched on "\_all:smith\*" and did a sort-  
> > by-name, without specifying fields to sort on using  
> > QueryStringQuery.field() , the sort would span across all 2000 results  
> > returned, paged in four 500 row pages. The pages were sorted correctly
> > 
> > - The first page: A to G second: G to P third: P to W fourth:  
> > everything else
> 
> > Now that I search on "smith\*" and then specify 4 fields using  
> > QueryStringQuery.field() and one boosted field, I find that I get 4  
> > pages each sorted A-to-Z. So the first page starts with A and ends in  
> > Z, the second page starts with A and ends in Z, and the third.
> 
> > Best Regards,
> 
> > David
> 
> > .

---

<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, 4:04am UTC](https://discuss.elastic.co/t/sort-after-specifying-fields-in-querystringquery/4545/4 "2017-07-06T04:04:33Z")

</div>


