Skip to content

Instantly share code, notes, and snippets.

@ankh2054
Last active November 11, 2023 08:06
Show Gist options
  • Save ankh2054/33a885e716b03c80807a2223a9da9307 to your computer and use it in GitHub Desktop.
Save ankh2054/33a885e716b03c80807a2223a9da9307 to your computer and use it in GitHub Desktop.
Delete alien worlds and farmer worlds from Hyperion.
from elasticsearch import Elasticsearch, NotFoundError
import time
# Specify which account you are deleting
gameTodelete = ["farmersworld", "alien.worlds", "m.federation"]
es = Elasticsearch(
['http://localhost:9200'],
http_auth=('elastic', 'password')
) # replace with your Elasticsearch instance
# Get all indices
all_indices = es.indices.get_alias(index="*")
# Filter indices
filtered_indices = [index for index in all_indices if index.startswith('wax-action-v1-') or index.startswith('wax-delta-v1-')]
# Iterate over each game
for game in gameTodelete:
# List to store indices with data
indices_with_data = []
# Search for data in each index
for index in filtered_indices:
try:
response = es.search(
index=index,
query={
"match": {
"act.account" if index.startswith('wax-action-v1-') else "code": game
}
}
)
if response['hits']['total']['value'] > 0:
indices_with_data.append(index)
except NotFoundError:
continue
print(f'Starting deletion for {game} on following indexes {indices_with_data}')
# Delete data from each index
for index in indices_with_data:
response = es.delete_by_query(
index=index,
body={
"query": {
"match": {
"act.account" if index.startswith('wax-action-v1-') else "code": game
}
}
},
params={'wait_for_completion': 'false'}
)
task_id = response['task']
print(f'{game}: Deleting {index}, task id: {task_id}')
# Wait for task to complete
while True:
response = es.tasks.get(task_id)
print(f"{game}: {task_id} for {index} has completed: {response['completed']}")
if response['completed']:
break
print('Sleeping for 60 seconds')
time.sleep(60) # wait for 1 second before checking again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment