# Sort by created\_at not working

**URL:** <https://discuss.elastic.co/t/sort-by-created-at-not-working/16949>\
**Category:** Elasticsearch\
**Created:** [April 11, 2014, 8:50am UTC](https://discuss.elastic.co/t/sort-by-created-at-not-working/16949 "2014-04-11T08:50:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Stabenfeldt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin_stabenfeldt/32/1360_2.png) [@Martin\_Stabenfeldt](https://discuss.elastic.co/u/Martin_Stabenfeldt)\
**Post date:** [April 11, 2014, 8:50am UTC](https://discuss.elastic.co/t/sort-by-created-at-not-working/16949/1 "2014-04-11T08:50:45Z")

</div>

Hi,

I'm trying to fetch all Ads that are active and sort them by created\_at,  
but the order is the same with and without the sort params. Same order when  
I flip order from asc to desc.

What am I doing wrong? 😑

GET \_search  
{  
"query": {  
"match\_all": {},  
"constant\_score" : {

```
    "filter" : {
        "term" : { "state" : "active"}
    }

}

```

},  
"sort": [  
{  
"created\_at": {  
"order": "asc"  
}  
}  
]  
}

Cheers,  
Martin

--  
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/1709156a-55fd-47bb-8a47-a8ce9fc3d5a0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1709156a-55fd-47bb-8a47-a8ce9fc3d5a0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Martin\_Stabenfeldt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin_stabenfeldt/32/1360_2.png) [@Martin\_Stabenfeldt](https://discuss.elastic.co/u/Martin_Stabenfeldt)\
**Post date:** [April 11, 2014, 8:57am UTC](https://discuss.elastic.co/t/sort-by-created-at-not-working/16949/2 "2014-04-11T08:57:57Z")

</div>

Got it working! 🙂

GET \_search  
{  
"query": {  
"match\_all": {}  
},  
"filter" : {  
"term" : { "state" : "active"}  
},

"sort": [  
{  
"created\_at": {  
"order": "desc"  
}  
}  
]

}

On Friday, April 11, 2014 10:50:45 AM UTC+2, Martin Stabenfeldt wrote:

> Hi,
> 
> I'm trying to fetch all Ads that are active and sort them by created\_at,  
> but the order is the same with and without the sort params. Same order when  
> I flip order from asc to desc.
> 
> What am I doing wrong? 😑
> 
> GET \_search  
> {  
> "query": {  
> "match\_all": {},  
> "constant\_score" : {
> 
> ```
> "filter" : {
> "term" : { "state" : "active"}
> }
> 
> }
> 
> ```
> 
> },  
> "sort": [  
> {  
> "created\_at": {  
> "order": "asc"  
> }  
> }  
> ]  
> }
> 
> Cheers,  
> Martin

--  
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/e0ae678b-bee6-4406-9c2c-fea27cd7999a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e0ae678b-bee6-4406-9c2c-fea27cd7999a%40googlegroups.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:36am UTC](https://discuss.elastic.co/t/sort-by-created-at-not-working/16949/3 "2017-07-06T01:36:34Z")

</div>


