Have still not found a solution but I found this thread that discusses the sorting, but I am unable to get it to work.
Following the directions from there here's some more detail on what I'm trying to do.
- I put a nested mapping for the collection type:
PUT /index/collection/_mappings
{
"properties": {
"items": {
"type": "nested"
}
}
}
- I index some documents/things:
POST /index/thing/_bulk
{ "index":{ "_id": 1 } }
{ "title":"One thing"}
{ "index":{ "_id": 2 } }
{ "title":"Second thing"}
{ "index":{ "_id": 3 } }
{ "title":"Three things"}
{ "index":{ "_id": 4 } }
{ "title":"And so fourth"}
{ "index":{ "_id": 5 } }
{ "title":"Five things"}
- I index the collection, which has three items in the following order:
PUT /index/collection/1
{
"items": [
{"id": 1, "time_added": "2017-08-07T09:07:15.000Z", "condition": "fair"},
{"id": 3, "time_added": "2019-08-07T09:07:15.000Z", "condition": "good"},
{"id": 4, "time_added": "2016-08-07T09:07:15.000Z", "condition": "poor"}
]
}
- I run a search with a terms lookup, filtering the
documents
that are in thecollection
GET "index/thing/_search"
{
"query" : {
"terms" : {
"_id" : {
"index" : "index",
"type" : "collection",
"id" : 1,
"path" : "items.id"
}
}
},
"sort": [
{ "items.id" : {"order" : "desc"}}
]
}
The order I expect is 1,3,4
(which is the order in the collection) but i get them in 4,1,3
(and in fact changing the order from desc
to asc
does not change the order). Am I missing something?
c.c. @polyfractal as you had an answer on the linked thread (I hope tagging like this is acceptable, quite a n00b to this forum).