# Keep older data in kibana when using a python script to upload data

**URL:** <https://discuss.elastic.co/t/keep-older-data-in-kibana-when-using-a-python-script-to-upload-data/278408>\
**Category:** Kibana\
**Created:** [July 12, 2021, 10:14am UTC](https://discuss.elastic.co/t/keep-older-data-in-kibana-when-using-a-python-script-to-upload-data/278408 "2021-07-12T10:14:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrienb02](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrienb02/32/77345_2.png) [@Adrienb02](https://discuss.elastic.co/u/Adrienb02)\
**Post date:** [July 12, 2021, 10:14am UTC](https://discuss.elastic.co/t/keep-older-data-in-kibana-when-using-a-python-script-to-upload-data/278408/1 "2021-07-12T10:14:12Z")

</div>

Hello there !

Sorry if my question seems stupid, it is my first time touching ELK and also JSON files, I'm doing an internship related to those topics and I need a bit of help.

So I have a python script that open a json file with various information and then send it to elasticsearch. From there, I can connect directly with my navigator with localhost:5601, manage the index and add the data on a dashboard.

Here is my code, uploading the information :

```auto
import requests
import json

res = requests.get('http://localhost:9200')

file = open("data_cores.json", "r")
line=file.readline()
tab = []

#read the line in the json file 
#and delete the comma at the end, then ad it in tab
while line:
    tab += [line]
    line = file.readline()
i=0
while i<5:
    tab[i] = tab[i][:-2]
    i=i+1

#I changed the name of my variables 
item1 = tab[0]
item2= tab[1]
item3= tab[2]
item4= tab[3]

from elasticsearch import Elasticsearch
es = Elasticsearch(
    ['localhost'],
    port=9200
)

res = es.index(index="indexproject", id=1, body=item1)
res = es.index(index="indexproject", id=2, body=item2)
res = es.index(index="indexproject", id=3, body=item3)
res = es.index(index="indexproject", id=4, body=item4)

```

and the structure of my json file :

```auto
{"name": "item 1", "cores": 0, "date" : },
{"name": "item 2", "cores": 44},
{"name": "item 3", "cores": 726},
{"name": "Item 4", "cores": 9}

```

The problem is, I want that everytime I run the python script, the data is uploaded in elasticsearch and the dashboard is updated but with a "time mark" somewhere, in such a way that it doesn't erase the older data and I can change the date on the dashboard to see previous days.  
I'm pretty sure that I have to change something in the structure of the documents I send to elasticsearch but I'm totally lost.

Thank you in advance.

EDIT : I have add a date on my json document, Kibana can read the date, no problem. But when I launch again the script, the new data still erase the older ones, even if the date is not the same

---

<div class="post-metadata">

**Author:** ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)\
**Post date:** [July 12, 2021, 8:01pm UTC](https://discuss.elastic.co/t/keep-older-data-in-kibana-when-using-a-python-script-to-upload-data/278408/2 "2021-07-12T20:01:54Z")

</div>

If the `id` value already exists, it will overwrite the elasticsearch document. There's a few options here - if there's a unique id that you can use, that will work. If there's no need to edit these afterwords, not specifying an id will cause elasticsearch to generate one for you.

---

<div class="post-metadata">

**Author:** ![Adrienb02](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adrienb02/32/77345_2.png) [@Adrienb02](https://discuss.elastic.co/u/Adrienb02)\
**Post date:** [July 13, 2021, 8:06am UTC](https://discuss.elastic.co/t/keep-older-data-in-kibana-when-using-a-python-script-to-upload-data/278408/3 "2021-07-13T08:06:40Z")

</div>

Thank you very much, it's working now ! 😁 I just deleted the "id=XX" in the es.index and it's all good !

---

<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:** [August 10, 2021, 8:06am UTC](https://discuss.elastic.co/t/keep-older-data-in-kibana-when-using-a-python-script-to-upload-data/278408/4 "2021-08-10T08:06:58Z")

</div>

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