Skip to content

Instantly share code, notes, and snippets.

@sephraim
Created October 13, 2022 20:18
Show Gist options
  • Save sephraim/c8072698d31a15be2e92829d0468c5b3 to your computer and use it in GitHub Desktop.
Save sephraim/c8072698d31a15be2e92829d0468c5b3 to your computer and use it in GitHub Desktop.
[Ruby Elasticsearch client examples]
# 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