According to documentation (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html#nested-inner-hits), inner hits returned can be sorted, and default sorting is score. I have a document with nested documents indexed in a defined order, and I would like to query the documents with inner hits returned in the indexed order. I realized however, that it is returned in revered order.
Here is one returned hit:
"hits": [
{
"_index": "myIndex",
"_type": "myType",
"_id": "AVcPID001OHiI-svKuW9",
"_score": 37.105354,
"_source": {},
"inner_hits": {
"innerObject": {
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "myIndex",
"_type": "myType",
"_id": "AVcPID001OHiI-svKuW9",
"_nested": {
"field": "innerObject",
"offset": 3
},
"_score": 1,
"_source": {
"id": 3123636
}
,
{
"_index": "myIndex",
"_type": "myType",
"_id": "AVcPID001OHiI-svKuW9",
"_nested": {
"field": "innerObject",
"offset": 2
},
"_score": 1,
"_source": {
"id": 4797314
}
}
,
{
"_index": "myIndex",
"_type": "myType",
"_id": "AVcPID001OHiI-svKuW9",
"_nested": {
"field": "innerObject",
"offset": 1
},
"_score": 1,
"_source": {
"id": 4538830
}
}
,
{
"_index": "myIndex",
"_type": "myType",
"_id": "AVcPID001OHiI-svKuW9",
"_nested": {
"field": "innerObject",
"offset": 0
},
"_score": 1,
"_source": {
"id": 5653177
}
}
]
}
}
}
}
]
So you can see the inner hits have the same score 1 (since my request was "match_all"), and i didn't define any sorting, just set the size 4. But the "offset" indicates 3 than 2 than 1 than 0, which is the reverse order of the nested documents.
How can I get my inner hits in the right order? I tried by the way to sort them by different fields (String, integer) and I always get them in the same order.
My elasticsearch version is 2.0.1