Created
April 29, 2024 21:19
-
-
Save artem-hatchenko/4aef0121c361ec38ddd7e3afd6f29fa2 to your computer and use it in GitHub Desktop.
opensearch_data_generator.sh
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
#!/bin/bash | |
# OpenSearch parameters | |
HOST="https://your-opensearch-url" | |
INDEX="app" | |
# Function to generate random data | |
generate_random_data() { | |
echo "{ \"timestamp\": \"$(date -Is)\", \"value\": $RANDOM }" | |
} | |
# Submitting data to OpenSearch | |
send_data_to_opensearch() { | |
local bulk_data="" | |
local num_docs=1000 # Increase this value to increase the amount of data | |
for ((i=1; i<=$num_docs; i++)); do | |
bulk_data+="{\"index\":{\"_index\":\"$INDEX\"}}\n$(generate_random_data)\n" | |
done | |
echo -e "$bulk_data" | curl -s -X POST -H "Content-Type: application/json" \ | |
--data-binary @- \ | |
"$HOST/_bulk" > /dev/null | |
} | |
# Number of iterations to send data | |
ITERATIONS=10 | |
# Loop to send data | |
for ((j=1; j<=$ITERATIONS; j++)); do | |
send_data_to_opensearch | |
echo "Iteration $j completed." | |
done | |
echo "Data generation is complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment