Skip to content

Instantly share code, notes, and snippets.

@gswallow
Created October 8, 2013 13:57
Show Gist options
  • Save gswallow/6885100 to your computer and use it in GitHub Desktop.
Save gswallow/6885100 to your computer and use it in GitHub Desktop.
# Passing along a search query with string interpolation from a role doesn't work.
# Try setting it here, instead.
env = "chef_environment:#{node.chef_environment}"
if node['elasticsearch'].has_key?('discovery')
role = "role:#{node['elasticsearch']['discovery']['role']}" unless node['elasticsearch']['discovery']['role'].nil?
end
if node['elasticsearch'].has_key?('cluster')
cluster = "elasticsearch_cluster_name:#{node['elasticsearch']['cluster']['name']}" unless node['elasticsearch']['cluster']['name'].nil?
end
mark = [role, cluster].compact.join(" OR ")
raise "You need to set node['elasticsearch']['discovery']['role'] or node['elasticsearch']['cluster']['name'] before you can continue." if mark.nil?
query = "#{env} AND (#{mark})"
node.set['elasticsearch']['discovery']['search_query'] = query
include_recipe "elasticsearch::search_discovery"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment