Skip to content

Instantly share code, notes, and snippets.

@skanderm
Created February 1, 2013 02:26
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 skanderm/907c9571caa0e87bad27 to your computer and use it in GitHub Desktop.
Save skanderm/907c9571caa0e87bad27 to your computer and use it in GitHub Desktop.
# nested
if team_params[:role_id].present? || team_params[:weight_class_id].present?
nested path: 'role_requirements' do
query do
boolean do
must { term :weight_class_id, team_params[:weight_class_id]} if team_params[:weight_class_id].present?
must { term :role_id, team_params[:role_id] } if team_params[:role_id].present?
must { term :need, true } if team_params[:role_id].present? || team_params[:weight_class_id].present?
end
end
end
end
# Filtered
filtered do
boolean do
must { term :weight_class_id, team_params[:weight_class_id]} if team_params[:weight_class_id].present?
must { term :role_id, team_params[:role_id] } if team_params[:role_id].present?
must { term :need, true } if team_params[:role_id].present? || team_params[:weight_class_id].present?
end
end
# Filters:
if team_params[:weight_class_id].present? ^ team_params[:role_id].present?
filter :and, { term: {"role_requirements.weight_class_id" => team_params[:weight_class_id]}, term: {"role_requirements.need" => true} } if team_params[:weight_class_id].present?
filter :and, { term: {"role_requirements.role_id" => team_params[:role_id]}, term: {"role_requirements.need" => true} } if team_params[:role_id].present?
elsif team_params[:weight_class_id].present? && team_params[:role_id].present?
filter :and, { term: {"role_requirements.role_id" => team_params[:role_id]}, term: {"role_requirements.need" => true}, term: {"role_requirements.weight_class_id" => team_params[:weight_class_id]}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment