# How can I set the date type with create.indices in elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-can-i-set-the-date-type-with-create-indices-in-elasticsearch/216505>\
**Category:** Elasticsearch\
**Created:** [January 25, 2020, 2:41am UTC](https://discuss.elastic.co/t/how-can-i-set-the-date-type-with-create-indices-in-elasticsearch/216505 "2020-01-25T02:41:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![securisec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/securisec/32/61412_2.png) [@securisec](https://discuss.elastic.co/u/securisec)\
**Post date:** [January 25, 2020, 2:41am UTC](https://discuss.elastic.co/t/how-can-i-set-the-date-type-with-create-indices-in-elasticsearch/216505/1 "2020-01-25T02:41:55Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/bulk_examples.html) but cant figure out what I am doing wrong..

How can I create the indices so that the date type is set properly?

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 22, 2020, 2:42am UTC](https://discuss.elastic.co/t/how-can-i-set-the-date-type-with-create-indices-in-elasticsearch/216505/2 "2020-02-22T02:42:06Z")

</div>

Closed on February 22, 2020, 2:42am UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
