Created
May 2, 2019 18:36
-
-
Save bobvanluijt/c7835096d9db4d9af8f048148e033824 to your computer and use it in GitHub Desktop.
Remove all concepts from Weaviate
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
## | |
# This script removes all things and action (i.e., concepts) from a Weaviate. | |
# | |
# Make sure to set the WEAVIATE_URL | |
## | |
import requests | |
from datetime import datetime | |
WEAVIATE_URL = "localhost" | |
HEADERS = {'Content-type': 'application/json'} | |
MAX_COUNTER = 25 # config set for max results from Weaviate | |
# A simple logger | |
def log(i): | |
now = datetime.fromtimestamp(datetime.timestamp(datetime.now())) | |
print(now, "| " + i) | |
# delete a concept | |
def conceptDelete(conceptType): | |
counter = 0 | |
# Get all concepts | |
req = requests.get(url="http://" + WEAVIATE_URL + ":8080/weaviate/v1/" + conceptType, headers=HEADERS) | |
result = req.json() | |
# loop and delete | |
for concept in result[conceptType]: | |
# delete the concept | |
req = requests.delete(url="http://" + WEAVIATE_URL + ":8080/weaviate/v1/" + conceptType + "/" + concept["id"]) | |
# validate if valid | |
if req.status_code != 204: | |
log("ERROR: SOMETHING IS WRONG, can't delete") | |
exit(1) | |
else: | |
counter = counter + 1 | |
log(concept["id"] + " delete success") | |
# if total is 25 restart | |
if counter == MAX_COUNTER: | |
counter = 0 | |
conceptDelete(conceptType) | |
# Remove all Things | |
conceptDelete("things") | |
conceptDelete("actions") | |
# done | |
log("DONE") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment