# Sorting when "fields": \[...\] in query

**URL:** <https://discuss.elastic.co/t/sorting-when-fields-in-query/18264>\
**Category:** Elasticsearch\
**Created:** [June 23, 2014, 2:10pm UTC](https://discuss.elastic.co/t/sorting-when-fields-in-query/18264 "2014-06-23T14:10:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zdenek\_Pizl](https://avatars.discourse-cdn.com/v4/letter/z/b19c9b/32.png) [@Zdenek\_Pizl](https://discuss.elastic.co/u/Zdenek_Pizl)\
**Post date:** [June 23, 2014, 2:10pm UTC](https://discuss.elastic.co/t/sorting-when-fields-in-query/18264/1 "2014-06-23T14:10:59Z")

</div>

Hallo,

is there any trick how to force ElsticSearch to sort results when using  
"fields" option withn a query.

This query:

"curl -XPOST [http://localhost:9200/stored-node/\_search?pretty=1](http://localhost:9200/stored-node/_search?pretty=1)  
-d'{"from":0, "size": 5, "fields": ["host", "prefix", "displayname"],  
"query": { "regexp": { "host": ".\*" }}, "sort": [{ "\_id": { "order": "asc"}  
}]}}'"

does not return sorted item, meanwhile the same query WITHOUT "fields" part  
returns correctly sorted data. But as i need only few info from every  
record not the whole bunch of data, I'd like to use "fields" to limit  
amount of data returned.

How to achieve sorted result when using the query above?

Thank you very much, regards .zp.

--

Zdenek Pizl  
[zdenek.pizl@gmail.com](mailto:zdenek.pizl@gmail.com)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAETP4L909PqLL6hh\_F%3D\_KTriJZ7catcd0P6TBcWrn5rXisEVQQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAETP4L909PqLL6hh_F%3D_KTriJZ7catcd0P6TBcWrn5rXisEVQQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:20am UTC](https://discuss.elastic.co/t/sorting-when-fields-in-query/18264/2 "2017-07-06T01:20:34Z")

</div>


