# Facets sort issue (date)

**URL:** <https://discuss.elastic.co/t/facets-sort-issue-date/5303>\
**Category:** Elasticsearch\
**Created:** [September 2, 2011, 3:40pm UTC](https://discuss.elastic.co/t/facets-sort-issue-date/5303 "2011-09-02T15:40:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aditya\_kulkarni](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@aditya\_kulkarni](https://discuss.elastic.co/u/aditya_kulkarni)\
**Post date:** [September 2, 2011, 3:40pm UTC](https://discuss.elastic.co/t/facets-sort-issue-date/5303/1 "2011-09-02T15:40:58Z")

</div>

Hi,

Here is my sample Data along with mapping  
{

"MainPostingID": "123345" // mapping: string  
"date": "2011-09-01T17:10:42", // mapping : date  
"sender\_number": "324233393331333933333337333033", // mapping :  
string, index: not\_analyzed, as it can contain alphabates, +, 0-9  
"msg\_text": "%22Change+can%27t+be+given+to+you+everytime" // mapping :  
string  
}

Multiple such entries get generated for main posting. Now I run  
following facet query with date sort.  
Aim: create facets for Main posting by sender and get them sorted by  
date.

e.g.  
curl -XPOST '[http://127.0.0.1:9200/postings/message/\_search](http://127.0.0.1:9200/postings/message/_search)' -d '  
{  
"size": 0,  
"sort": [  
{  
"date": {  
"order": "asc"  
}  
}  
],  
"query": {  
"field": {  
"MainPostingID": "123345"  
}  
},  
"facets": {  
"myFacet": {  
"terms": {  
"fields": [  
"sender\_number"  
]  
}  
}  
}  
}'

Issue for which I need help!  
Facets are coming with no issues. Problem is with sorting as it sorts  
facets by sender\_number and not by date.

Thanks in advance!

Best Regards,  
Aditya

---

<div class="post-metadata">

**Author:** ![Jurgen\_kartnaller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jurgen_kartnaller/32/3086_2.png) [@Jurgen\_kartnaller](https://discuss.elastic.co/u/Jurgen_kartnaller)\
**Post date:** [September 4, 2011, 12:16pm UTC](https://discuss.elastic.co/t/facets-sort-issue-date/5303/2 "2011-09-04T12:16:05Z")

</div>

You can not sort a facet with the query sort.

The facet gets the unsorted and unfiltered query result.

See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

on  
how to sort the result of the terms facet.

Jürgen

On Fri, Sep 2, 2011 at 5:40 PM, Aditya [aditya.kulkarni@gmail.com](mailto:aditya.kulkarni@gmail.com) wrote:

> Hi,
> 
> Here is my sample Data along with mapping  
> {
> 
> "MainPostingID": "123345" // mapping: string  
> "date": "2011-09-01T17:10:42", // mapping : date  
> "sender\_number": "324233393331333933333337333033", // mapping :  
> string, index: not\_analyzed, as it can contain alphabates, +, 0-9  
> "msg\_text": "%22Change+can%27t+be+given+to+you+everytime" // mapping :  
> string  
> }
> 
> Multiple such entries get generated for main posting. Now I run  
> following facet query with date sort.  
> Aim: create facets for Main posting by sender and get them sorted by  
> date.
> 
> e.g.  
> curl -XPOST '[http://127.0.0.1:9200/postings/message/\_search](http://127.0.0.1:9200/postings/message/_search)' -d '  
> {  
> "size": 0,  
> "sort": [  
> {  
> "date": {  
> "order": "asc"  
> }  
> }  
> ],  
> "query": {  
> "field": {  
> "MainPostingID": "123345"  
> }  
> },  
> "facets": {  
> "myFacet": {  
> "terms": {  
> "fields": [  
> "sender\_number"  
> ]  
> }  
> }  
> }  
> }'
> 
> Issue for which I need help!  
> Facets are coming with no issues. Problem is with sorting as it sorts  
> facets by sender\_number and not by date.
> 
> Thanks in advance!
> 
> Best Regards,  
> Aditya

--  
[http://www.sfgdornbirn.at](http://www.sfgdornbirn.at)  
[http://www.mcb-bregenz.at](http://www.mcb-bregenz.at)

---

<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, 3:55am UTC](https://discuss.elastic.co/t/facets-sort-issue-date/5303/3 "2017-07-06T03:55:14Z")

</div>


