1234567891011121314151617181920212223242526272829 |
- """
- Example script to index elasticsearch documents.
- """
- import argparse
- import json
- from elasticsearch import Elasticsearch
- from elasticsearch.helpers import bulk
- def load_dataset(path):
- with open(path) as f:
- return [json.loads(line) for line in f]
- def main(args):
- host = '192.168.20.69:30920'
- es = Elasticsearch([host])
- # 往es索引写数据,docs是一个json集合数据集
- docs = load_dataset(args.data)
- bulk(es, docs, index=args.index_name, chunk_size=1000, request_timeout=120)
- if __name__ == '__main__':
- parser = argparse.ArgumentParser(description='Indexing elasticsearch documents.')
- parser.add_argument('--data', default='documents.jsonl', help='Elasticsearch documents.')
- parser.add_argument('--index_name', default='fault_meter', help='Elasticsearch index name.')
- args = parser.parse_args()
- main(args)
|