I've recently been working with a searchable graphql model through Amplify. I've successfully:
- applied the
@searchable (and seen the creation of OpenSearch stack, and new graphql search queries)
- run the backfill script
I've checked in the OpenSearch console, and I can see the right number of documents in the index named after the model.
Using the new automatically generated search graphql constructs, I can retrieve all the data, ie.
let searchQuery = {
limit: limitNum,
filter: { version: { eq: 3 } }
};
let results = await API.graphql(graphqlOperation(searchSortableSemanticFeedbacks, searchQuery));
console.log('search results', results);
But when I apply a sort filter, I get 0 results, ie.
let searchQuery = {
limit: limitNum,
sort: [ { direction: 'desc', field: 'date' } ],
filter: { version: { eq: 3 } }
};
let results = await API.graphql(graphqlOperation(searchSortableSemanticFeedbacks, searchQuery));
console.log('search results', results);
I've tried with sort as an array, or as a solo object. In both cases, I get 0 results.
I've also tested and proved to myself that direction and field have good values - ie. if you provide a non-existent field or a garbage string for direction, you get an error (rather than 0 results).
I've also tested aggregate queries, and these seem to be working well, so it's something specific to sort that causes 0 results.
One thing I've noticed is that OpenSearch has mapped doc.date as field type date. I guess that's ok - the actual source values are strings in YYYY-MM format, eg. 2022-05 - so it seems like it has decided to convert these values to dates. (I can't tell if successfully or not, but I can't see it being much of a problem? If that's preventing the sorting, I'm not sure what to make of it.) (gotta be unrelated)
Can anybody suggest what I'm doing wrong?