Not able to sort keyvalue in _source result

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

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:

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

If your field is unmapped, there is an option to ignore unmapped fields.

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