I am having trouble setting the date
type specially for nested objects in elasticsearch withe nodejs. The data
field in my example holds the time in epoch in seconds. I am using the create.indices
endpoint along with the bulk
endpoint sod that I can set my own _id
value. I am not even getting the prompt in Kibana that usually asks me to select which fields are type date
.
The issue I am having is that the date time is always being set to number
or long
when I try to check the data in Kibana. I am following the docs but cant figure out what I am doing wrong..
How can I create the indices so that the date type is set properly?
const { Client } = require('@elastic/elasticsearch');
const client = new Client({ node: 'http://localhost:9200' });
client.indices
.create(
{
index: 'test',
body: {
mappings: {
properties: {
hello: { type: 'text' },
some: { data: { type: 'date' } }
}
}
}
},
{ ignore: [400] }
)
.then(() => {
let data = [{ hello: 'world', some: { data: 1579895431 } }];
let body = data.flatMap((doc) => [
{ index: { _index: 'test', _id: '123id' } },
doc
]);
console.log(body);
client
.bulk({ refresh: true, body })
.then((res) => {
console.log(res);
})
.catch((error) => console.log(error));
})
.catch(console.log);