Skip to content

Instantly share code, notes, and snippets.

@andrewlorien
Forked from winzig/cloudsearch-clone-domain.sh
Last active October 17, 2023 00:41
Show Gist options
  • Save andrewlorien/59df6bd6682eb38feddd70559b9843de to your computer and use it in GitHub Desktop.
Save andrewlorien/59df6bd6682eb38feddd70559b9843de to your computer and use it in GitHub Desktop.
A bash script to help you clone an AWS CloudSearch domain including analysis schemes and index fields
#!/bin/bash
#
# Usage: cloudsearch-clone-domain <domain> <newdomain>
#
# After you run this script, you'll have a file named define-fields-<newdomain>.sh, which
# you can run to re-create all the fields from the cloned domain. If you haven't yet created
# the new CS domain, then run `aws cloudsearch create-domain --domain-name <newdomain>` before
# running the define-fields script that is produced by this script.
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 2 ] || die "Usage: cloudsearch-clone-domain <domain> <newdomain>"
aws cloudsearch describe-analysis-schemes --domain $1 | jq ".[][] | {\"DomainName\": \"$2\", \"AnalysisScheme\": .Options} | tostring" | sed 's/^/aws cloudsearch define-analysis-scheme --cli-input-json /' > define-fields-$2.sh
aws cloudsearch describe-index-fields --domain $1 | jq ".[][] | {\"DomainName\": \"$2\", \"IndexField\": .Options} | tostring" | sed 's/^/aws cloudsearch define-index-field --cli-input-json /' >> define-fields-$2.sh
chmod +x define-fields-$2.sh
echo Run these commands to create your new domain, and then define its fields:
echo aws cloudsearch create-domain --domain-name $2
echo ./define-fields-$2.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment