python写数据进es中

1、自定义inde为:xxxx,data_to_insert也可以自定义函数
from elasticsearch import Elasticsearch
from datetime import datetime, timedelta


es = Elasticsearch(['http://es地址1:9200', 'es地址2:9200', 'es地址3:9200'])
current_date = datetime.now()
formatted_date = current_date.strftime("%Y.%m.%d")
current_time = datetime.now()
adjusted_time = (current_time - timedelta(hours=8)).isoformat()

subnet_name="数据1"
addresses_use="数据1"
addresses_idle="数据1"
addresses_Total="数据1"


# 要es写入的数据
data_to_insert = {"subnet_name": subnet_name, "addresses_use": addresses_use, "addresses_idle": addresses_idle,
"addresses_Total": addresses_Total, "timestamp":adjusted_time }
index_name = "xxxx" + formatted_date # 替换成你的索引名
response = es.index(index=index_name, body=data_to_insert)

print(response)

 

你可能感兴趣的:(python,elasticsearch,开发语言)