lib/elasticsearch/api/actions/search.rb in elasticsearch-api-0.4.0 vs lib/elasticsearch/api/actions/search.rb in elasticsearch-api-0.4.1
- old
+ new
@@ -84,10 +84,14 @@
# dfs_query_then_fetch, dfs_query_and_fetch, count, scan)
# @option arguments [Number] :size Number of hits to return (default: 10)
# @option arguments [List] :sort A comma-separated list of <field>:<direction> pairs
# @option arguments [String] :source The URL-encoded request definition using the Query DSL
# (instead of using request body)
+ # @option arguments [String] :_source Specify whether the _source field should be returned,
+ # or a list of fields to return
+ # @option arguments [String] :_source_exclude A list of fields to exclude from the returned _source field
+ # @option arguments [String] :_source_include A list of fields to extract and return from the _source field
# @option arguments [List] :stats Specific 'tag' of the request for logging and statistical purposes
# @option arguments [String] :suggest_field Specify which field to use for suggestions
# @option arguments [String] :suggest_mode Specify suggest mode (options: missing, popular, always)
# @option arguments [Number] :suggest_size How many suggestions to return in response
# @option arguments [Text] :suggest_text The source text for which the suggestions should be returned
@@ -100,41 +104,44 @@
# @see http://www.elasticsearch.org/guide/reference/api/search/request-body/
#
def search(arguments={})
arguments[:index] = '_all' if ! arguments[:index] && arguments[:type]
+ valid_params = [
+ :analyzer,
+ :analyze_wildcard,
+ :default_operator,
+ :df,
+ :explain,
+ :fields,
+ :from,
+ :ignore_indices,
+ :indices_boost,
+ :lenient,
+ :lowercase_expanded_terms,
+ :preference,
+ :q,
+ :routing,
+ :scroll,
+ :search_type,
+ :size,
+ :sort,
+ :source,
+ :_source,
+ :_source_include,
+ :_source_exclude,
+ :stats,
+ :suggest_field,
+ :suggest_mode,
+ :suggest_size,
+ :suggest_text,
+ :timeout,
+ :version ]
+
method = 'GET'
path = Utils.__pathify( Utils.__listify(arguments[:index]), Utils.__listify(arguments[:type]), '_search' )
- params = arguments.select do |k,v|
- [ :analyzer,
- :analyze_wildcard,
- :default_operator,
- :df,
- :explain,
- :fields,
- :from,
- :ignore_indices,
- :indices_boost,
- :lenient,
- :lowercase_expanded_terms,
- :preference,
- :q,
- :routing,
- :scroll,
- :search_type,
- :size,
- :sort,
- :source,
- :stats,
- :suggest_field,
- :suggest_mode,
- :suggest_size,
- :suggest_text,
- :timeout,
- :version ].include?(k)
- end
- # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour
- params = Hash[params] unless params.is_a?(Hash)
+
+ params = Utils.__validate_and_extract_params arguments, valid_params
body = arguments[:body]
params[:fields] = Utils.__listify(params[:fields]) if params[:fields]
perform_request(method, path, params, body).body