Created
June 23, 2019 16:06
-
-
Save itaysk/0c49a6e5e582a0f19a66177c8ff7f796 to your computer and use it in GitHub Desktop.
Azure Search Export
This file contains 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 | |
# This script will export the json contents of an Azure Search instance into a JSON array. | |
# The script creates local files under the directory it is executed. The result is saved to a newly created local file. | |
# The script depends on `curl` and `jq` utilities. | |
# Arguments: $1 : azure search service name, $2: azure search index name, $3: azure search admin auth key. | |
set -e -o pipefail | |
serviceName="$1" | |
indexName="$2" | |
adminKey="$3" | |
apiVersion="2015-02-28" | |
link="https://${serviceName}.search.windows.net/indexes/${indexName}/docs?api-version=${apiVersion}&search=*" | |
while [ -n "$link" ]; | |
do | |
echo "getting ${link}" | |
curl "${link}" -s \ | |
-H "Accept: application/json, text/plain, */*" \ | |
-H "api-key: ${adminKey}" \ | |
> ./tmp | |
link=$(jq -r '.["@odata.nextLink"] // empty' ./tmp) | |
jq -r '.value[]' ./tmp >> ./agg | |
done | |
rm ./tmp | |
jq '[inputs]' ./agg > ./res | |
rm ./agg | |
echo 'done! result at ./res' |
Note to self: you may need to run
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null
when using WSL2
Legend, thanks! Worked like a charm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@itaysk Would you know how to do this in python ? I want to do this midway through my pipeline