Skip to content

Instantly share code, notes, and snippets.

@hideokamoto
Created December 20, 2015 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hideokamoto/acf434562e0ce8d5562b to your computer and use it in GitHub Desktop.
Save hideokamoto/acf434562e0ce8d5562b to your computer and use it in GitHub Desktop.
#!/bin/sh
wp_url="http://YOUR-SITE.DOMAIN/wp-json/wp/v2/posts"
es_url="https://search-YOUR-DOMAIN-XXXXXX.ap-northeast-1.es.amazonaws.com/wp/posts/"
filename="sample.json"
wget -O ${filename} ${wp_url}
posts=$(cat ${filename} | jq ".[].id")
count=0
for post in ${posts}; do
echo ${es_url}${post}
cat ${filename} | jq ".[${count}]" > "${count}.json"
curl -XPUT ${es_url}${post} -d "@${count}.json"
rm -f "${count}.json"
count=$((count + 1))
done
rm -f ${filename}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment