To read a documents:
res = es.get(index='rules-test',
doc_type='_doc',
id='cJG_UnEB1e0J32pjx0pG')
To update a documents:
doc = {
"doc": { # < - - cannot use other than "doc"
"new_or_existing_field": {
"sub_field": {
"other_name" : "cadang1",
"other_class": "cadang2"
}
}
}
}
es.update(index='rules-test',
doc_type='_doc',
id='cJG_UnEB1e0J32pjx0pG',
body=doc)
To filter result:
query = {
"query": {
"bool": {
"must": [
{ "term": {
"feed.keyword": args.feed
}
},
{ "term": {
"version.keyword": args.version
}
}
]
}
},
"aggs": {
"uniq_f_name": {
"terms": {
"field": "file_name.keyword",
"size": 200
}
}
},
"size": 0
}
result = es.search(index=args.es_index, body= query)
# print(json.dumps(query), "\n", result)
for bucket in result['aggregations']['uniq_f_name']['buckets']:
print( bucket)
To count:
- add 'size=0' parameter when call search() method
res = client.search(index = "indexname", doc_type = "doc_type", body = q, size=0)
# if res['hits']['total']['value'] is greater than 10K, means total record is larger, and you need to use scroll to retrieve all the documents.
- add 'size=0' parameter when call search() method
res = client.search(index = "indexname", doc_type = "doc_type", body = q, size=0)
# if res['hits']['total']['value'] is greater than 10K, means total record is larger, and you need to use scroll to retrieve all the documents.
To use scroll:
result = es.search(index="indexname", body= query, scroll = '1m')
while result['hits']['hits'] > 0:
result = es.scroll(scroll_id= scroll_id, scroll = '1m')
print(result['hits']['hits'])
No comments:
Post a Comment
Terima kasih