Created
November 17, 2015 15:02
-
-
Save burdandrei/cd3d9d8cd92ce4a8a1f5 to your computer and use it in GitHub Desktop.
Export all your data from CloudSearch and be free!
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
#!/usr/bin/env ruby | |
# | |
# Cloudsearch export script | |
# | |
# Required ENV Variables | |
# * AWS_ACCESS_KEY_ID | |
# * AWS_SECRET_ACCESS_KEY | |
# * CS_SEARCH_ENDPOINT | |
# * OUT_FILENAME | |
# | |
require 'aws-sdk' | |
search_instance = Aws::CloudSearchDomain::Client.new(endpoint: ENV['CS_SEARCH_ENDPOINT']) | |
cursor = 'initial' | |
bulk_size = 10000 # max CloudSearch bulk size | |
f = File.new(ENV['OUT_FILENAME'], 'w') | |
loop do | |
s = search_instance.search({ | |
query: "matchall", | |
query_parser: 'structured', | |
cursor: cursor, | |
size: bulk_size | |
}) | |
cursor = s.hits.cursor | |
s.hits.hit.each do |doc| | |
f.puts(doc.fields) | |
end | |
break if s.hits.hit.empty? | |
end | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment