# Unable to save documents by timestamp - only one document is saved and updated everytime

**URL:** <https://discuss.elastic.co/t/unable-to-save-documents-by-timestamp-only-one-document-is-saved-and-updated-everytime/104597>\
**Category:** Elasticsearch\
**Created:** [October 19, 2017, 4:35pm UTC](https://discuss.elastic.co/t/unable-to-save-documents-by-timestamp-only-one-document-is-saved-and-updated-everytime/104597 "2017-10-19T16:35:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitinware](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nitinware/32/23201_2.png) [@nitinware](https://discuss.elastic.co/u/nitinware)\
**Post date:** [October 19, 2017, 4:35pm UTC](https://discuss.elastic.co/t/unable-to-save-documents-by-timestamp-only-one-document-is-saved-and-updated-everytime/104597/1 "2017-10-19T16:35:50Z")

</div>

I want to save documents in an Index by timestamp.  
I am saving documents every second, so I want to see a document being created every second.  
But when I save the document by passing new timestamp value, a new document is not created but the same existing document is updated.  
So instead of seeing documents being saved per second, I see the same document getting update every second.  
Below is the mapping information about my index.

> {  
> "iotdevice": {  
> "aliases": {},  
> "mappings": {  
> "sensordata": {  
> "properties": {  
> "nodeID": {  
> "type": "text",  
> "fields": {  
> "keyword": {  
> "type": "keyword",  
> "ignore\_above": 256  
> }  
> }  
> },  
> "sensorData": {  
> "type": "float"  
> },  
> "sensorID": {  
> "type": "text",  
> "fields": {  
> "keyword": {  
> "type": "keyword",  
> "ignore\_above": 256  
> }  
> }  
> },  
> "sensorName": {  
> "type": "text",  
> "fields": {  
> "keyword": {  
> "type": "keyword",  
> "ignore\_above": 256  
> }  
> }  
> },  
> "sensorState": {  
> "type": "long"  
> },  
> "sensorType": {  
> "type": "long"  
> },  
> "siteIP": {  
> "type": "text",  
> "fields": {  
> "keyword": {  
> "type": "keyword",  
> "ignore\_above": 256  
> }  
> }  
> },  
> "timestamp": {  
> "type": "date",  
> "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch\_millis"  
> }  
> }  
> }  
> },  
> "settings": {  
> "index": {  
> "creation\_date": "1508352509436",  
> "number\_of\_shards": "5",  
> "number\_of\_replicas": "1",  
> "uuid": "ZxcszX-LTzatqYCQV3z4QA",  
> "version": {  
> "created": "5030299"  
> },  
> "provided\_name": "iotdevice"  
> }  
> }  
> }  
> }

I am saving the document every second by using the bulk insert operation.

But after saving 100's of documents per second, I am seeing only 1 record with the most recent timestamp/

> [https://search-sensordata-hima7jdvzx6rkn6tpprlqlyp4e.us-east-1.es.amazonaws.com/iotdevice/\_search/?size=1000&pretty=1](https://search-sensordata-hima7jdvzx6rkn6tpprlqlyp4e.us-east-1.es.amazonaws.com/iotdevice/_search/?size=1000&pretty=1)  
> Response -\>  
> {  
> "took": 1,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 1,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "iotdevice",  
> "\_type": "sensordata",  
> "\_id": "ID002",  
> "\_score": 1,  
> "\_source": {  
> "sensorID": "ID002",  
> "sensorName": "Sensor\_SFO",  
> "sensorState": 1,  
> "timestamp": "2017-10-19 16:16:44"  
> }  
> }  
> }  
> ]  
> }  
> }

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [October 19, 2017, 6:22pm UTC](https://discuss.elastic.co/t/unable-to-save-documents-by-timestamp-only-one-document-is-saved-and-updated-everytime/104597/2 "2017-10-19T18:22:44Z")

</div>

You appear to have set \_id (the document id) to be the same as sensorID. That means you will only ever have one document per sensor per index. If you are writing one document per second per sensor then do not set the document id, just let es generate it.

---

<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:** [November 16, 2017, 6:23pm UTC](https://discuss.elastic.co/t/unable-to-save-documents-by-timestamp-only-one-document-is-saved-and-updated-everytime/104597/3 "2017-11-16T18:23:08Z")

</div>

Closed on November 16, 2017, 6:23pm UTC

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