I Want to insert A random String inside of a JSON in a Bash script I'm using to send _bulk od documents in the API of Elasticsearch:
SECONDS=0;
for i in {0..1000}
do
echo "Number: $i \n"
curl --location --request POST 'localhost:9000/_bulk' \
--header 'Content-Type: application/json' \
--data-raw '{"index": {"_index": "yotam-les", "_type": "_doc", "_id": "A975463f711"}}
{"Amount": "3", "Quantity": "2", "Id": "A975463f711", "Client_Store_sk": "1109"}
{"index": {"_index": "yotam-les", "_type": "_doc", "_id": "975463943"}}
{"Amount": "7", "Quantity": "2", "Id": "975463943", "Client_Store_sk": "1109"}
'
done
echo "\n took " $SECONDS "seconds"
exit 0
For example, in this bash script, I want to do something like
"_id": "<RANDOMLY_GENERATED_STRING>"
where "_id": "A975463f711" this part is. and of course, I wish that each iteration would randomly generate the ID itself.
in order to create a random string I know I can do this:
chars=abcd1234ABCD
echo -n "${chars:RANDOM%${#chars}:1}"
but how do Inject it inside the JSON?
to be more clear my problem is when I try to do this:
"_id": "${chars:RANDOM%${#chars}:1}"
because of the --data-raw '...' - it can only contain a raw string
Thanks for your help.
Aucun commentaire:
Enregistrer un commentaire