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 37 38 39 40 41 42 43
| from elasticsearch import Elasticsearch
es = Elasticsearch(url, http_auth=(username, password))
index = "index-name"
es.indices.exists(index)
es.indices.create(index=index, ignore=[400, 404])
data = { "lang": "zh", "content": "content" } es.index(index=index, body=data, refresh=True)
body = { "query":{ "term":{ "lang": "lang" } } } msgs = es.search(index=index, body=body)
body = { "script": { "source": "ctx._source.content = params.content", "params": {"content": "update content"}, } } es.update(index=index, id=doc['_id'], body=body, refresh=True, retry_on_conflict=1)
es.delete(index=index, id=doc['_id'])
es.indices.delete(index=index, ignore=[400, 404])
|