from datetime import datetime from elasticsearch6 import Elasticsearch es = Elasticsearch({"172.16.100.186": "9200"}) doc = {'id': 2, 'name': "乙"} ID = 2 INDEX = "wuren" DOC_TYPE = "cn" # res = es.delete(index=INDEX, doc_type=DOC_TYPE, id=ID) es.create(index=INDEX, doc_type=DOC_TYPE, id=ID, body=doc) # res = es.delete(index=INDEX, doc_type=DOC_TYPE, id=2) res = es.get(index=INDEX, doc_type=DOC_TYPE, id=ID) print(res) # res = es.get(index=InterruptedError, id=1, doc_type=DOC_TYPE) # print(res['_source'])
"Path to git repo. Commits used as data to load into Elasticsearch. (Default: None" ) args = parser.parse_args() # instantiate es client, connects to localhost:9200 by default es = Elasticsearch(args.host) # we load the repo and all commits load_repo(es, path=args.path) # run the bulk operations success, _ = bulk(es, UPDATES, index='git') print('Performed %d actions' % success) # we can now make docs visible for searching es.indices.refresh(index='git') # now we can retrieve the documents initial_commit = es.get(index='git', doc_type='doc', id='20fbba1230cabbc0f4644f917c6c2be52b8a63e8') print('%s: %s' % (initial_commit['_id'], initial_commit['_source']['committed_date'])) # refresh to make the documents available for search es.indices.refresh(index='git') # and now we can count the documents print(es.count(index='git')['count'], 'documents in index')