# Not able to sort keyvalue in \_source result

**URL:** <https://discuss.elastic.co/t/not-able-to-sort-keyvalue-in-source-result/143675>\
**Category:** Elasticsearch\
**Created:** [August 9, 2018, 10:37am UTC](https://discuss.elastic.co/t/not-able-to-sort-keyvalue-in-source-result/143675 "2018-08-09T10:37:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dipen\_Patel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dipen_patel/32/92025_2.png) [@Dipen\_Patel](https://discuss.elastic.co/u/Dipen_Patel)\
**Post date:** [August 9, 2018, 10:37am UTC](https://discuss.elastic.co/t/not-able-to-sort-keyvalue-in-source-result/143675/1 "2018-08-09T10:37:10Z")

</div>

Hello,

I have json file looks like below and i Imported in to elasticsearch via bulk api,  
{ "index": { "\_id": 1 }}  
{ "guid": "132789","age":"30","title":"helloif graphic design art san franciscofurthermore theyredifferent" }  
{ "index": { "\_id": 2 }}  
{ "guid": "134323","age":"21","title":"associate" }  
{ "index": { "\_id": 3 }}  
{ "guid": "135254","age":"24","title":"associate degreeassociate" }  
{ "index": { "\_id": 4 }}  
{ "guid": "138085","age":"34","title":"associate degreeassociate" }.....etc...

and now search by below post url and getting below result....

url: https//localhost:9200/esearch/my\_index/\_search?pretty  
post body :-  
{ "query": { "match": { "title": { "query": "live backlog 7th bachelors 6th ",  
"minimum\_should\_match": "10%"}}}}  
result :-  
{  
"took": 0,  
"timed\_out": false,  
"\_shards": {  
"total": 1,  
"successful": 1,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 30,  
"max\_score": 9.349399,  
"hits": [{  
"\_index": "user\_reco\_with\_last\_login",  
"\_type": "json",  
"\_id": "1414",  
"\_score": 9.349399,  
"\_source": {  
"guid": "252774",  
"last\_login": "21",  
"title": "backlog in 6 sem"  
}  
},  
{  
"\_index": "user\_reco\_with\_last\_login",  
"\_type": "json",  
"\_id": "7",  
"\_score": 4.0327053,  
"\_source": {  
"guid": "131550",  
"age": "25",  
"title": "bachelors from usa"  
}  
}  
]  
}  
}

now i want result in descending order of age keyword in \_source ....

I tried with adding sort in post body but it is not works....  
anybody please help me...

thanks  
dipen

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [August 23, 2018, 9:03pm UTC](https://discuss.elastic.co/t/not-able-to-sort-keyvalue-in-source-result/143675/2 "2018-08-23T21:03:07Z")

</div>

What type is of your `age` field?  
Did you provide mapping for this field as `keyword`?

In this case, you can request sorting on this, like:

```auto
{
    "sort" : ["age"],
    "query" : {
       ....

```

If your field is unmapped, there is an [option](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_ignoring_unmapped_fields) to ignore unmapped fields.

---

<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:** [September 20, 2018, 9:03pm UTC](https://discuss.elastic.co/t/not-able-to-sort-keyvalue-in-source-result/143675/3 "2018-09-20T21:03:15Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
