Python: 更新ElasticSearch中的数据

python Logo
image-3320

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from elasticsearch import Elasticsearch

'''

pip install elasticsearch==7.9.1


'''





elasticsearch_client = Elasticsearch("http://192.168.0.1:9200")

es_index = "es_index"


def main():
    update_es_index_data()


# 批量更新数据.
def update_es_index_data():
    all_es_id = ["iWEfdsa6z359R9xI2", "mGEqiY89656zaRrxJC", "mWEqiYEBCO2z6zRrxJC"]
    for es_id in all_es_id:
        update_body = {
            "doc": {
                "mileage": 1000.95,
                "speed": 0.0
            }
        }
        elasticsearch_client.update(index=es_index, id=es_id, body=update_body)
    print("更新位置数据,更新成功!")

if __name__ == '__main__':
    main()

发表评论

您的电子邮箱地址不会被公开。

*

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据