I'm storing data in my local Node JS Elastic Search database, now I've inserted records and one of the fields is a created_at field, which I've stored with new Date(), however, upon retrieval of the data, it seems that these are Strings, and thus my query doesn't seem to return any results.
My data looks like:
{
"_index": "my_table",
"_type": "_doc",
"_id": "V1mouXcBt3ZsPNCwd3A1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"properties": {
"created_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"updated_at": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
},
"data": {
"name": "performance_overview",
"friendly_name": "Performance Overview",
"data": {
"cached": "9:39:21am",
"from": "02/19/2021 00:00:00",
"to": "02/19/2021 23:59:59",
"success": true,
"message": "message",
"sessions": "265",
"leads": "123",
"conversion_rate": "46.42"
},
"created_at": "2021-02-19 09:02:16",
"updated_at": "2021-02-19 09:02:16"
}
}
}
I'm using Moment JS, and have formatted the dates, and attempted what I believe is accurate for field mappings, although I'm new to Elastic Search and this seems to not return any results either.
const from = moment(from).startOf('day')
const results = await elastic.find('my_table', {
query: {
range: {
created_at: {
gte: moment(from).format('YYYY-MM-DD HH:MM:SS'),
}
}
}
})
elastic.find is a custom function that I've written which looks like the following and is exported from another JS file:
const find = async (table, data) => {
try {
const found = await client.search({
index: table,
body: data
}, {
ignore: [404],
maxRetries: 3
})
return found.body
} catch (err) {
return err
}
}