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() |