Created
October 13, 2022 20:18
-
-
Save sephraim/c8072698d31a15be2e92829d0468c5b3 to your computer and use it in GitHub Desktop.
[Ruby Elasticsearch client examples]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GET shards | |
num_shards_in_use = client.cluster.stats['indices']['shards']['total'] | |
# GET docs | |
response = client.search(index: 'index_name', q: '!2022-10-11 AND !2022-10-12 AND !2022-10-13', df: 'date', _source_includes: ['name', 'date']) | |
docs = response['hits']['hits'] | |
num_docs = response['hits']['total']['value'] | |
# GET indices | |
all_indices = client.indices.stats['indices'].map(&:first) | |
my_indices = client.indices.stats(index: "my_*")['indices'].map(&:first) | |
# DELETE docs | |
delete_response = client.delete_by_query(index: 'index_name', q: '!2022-10-11 AND !2022-10-12 AND !2022-10-13', df: 'date', body: {}) | |
num_deleted_docs = delete_response['deleted'] | |
# DELETE indices | |
client.indices.delete(index: 'index_name') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment