I've got a created_at
field in my Elastic Search database and I'm trying to pull out data and sort it by that field. The field was stored with a mapping property with the date format, with the fielddata
key set to true, but I still get the error:
Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [created_at] in order to load field data by uninverting the inverted index. Note that this can use significant memory.
One suggestion is that I can add the word keyword
to my field to search it, but this seems to tell me that:
created_at is not defined
I'm using Javascript, and I know you can't just add the (dot) character, so I've wrapped it and it still isn't working. elastic.find
is just a function I've written to pull data, if I remove the sort
array, it works.
const results = await elastic.find('my table', {
query: {
range: {
created_at: {
gte: moment(from).format('YYYY-MM-DD HH:MM:SS')
}
}
},
sort: [{
[created_at.keyword]: 'asc' // seems to be undefined
}]
})
Why can't I access created_at.keyword
?