Method: Elasticsearch::API::Actions#explain

Defined in:
lib/elasticsearch/api/actions/explain.rb

#explain(arguments = {}) ⇒ Object

Explain a document match result. Get information about why a specific document matches, or doesn’t match, a query. It computes a score explanation for a query and a specific document.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    The document identifier. (Required)

  • :index (String)

    Index names that are used to limit the request. Only a single index name can be provided to this parameter. (Required)

  • :analyzer (String)

    The analyzer to use for the query string. This parameter can be used only when the q query string parameter is specified.

  • :analyze_wildcard (Boolean)

    If true, wildcard and prefix queries are analyzed. This parameter can be used only when the q query string parameter is specified.

  • :default_operator (String)

    The default operator for query string query: and or or. This parameter can be used only when the q query string parameter is specified. Server default: or.

  • :df (String)

    The field to use as default where no field prefix is given in the query string. This parameter can be used only when the q query string parameter is specified.

  • :lenient (Boolean)

    If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored. This parameter can be used only when the q query string parameter is specified.

  • :preference (String)

    The node or shard the operation should be performed on. It is random by default.

  • :routing (String, Array<String>)

    A custom value used to route operations to a specific shard.

  • :_source (Boolean, String, Array<String>)

    True or false to return the _source field or not or a list of fields to return.

  • :_source_excludes (String, Array<String>)

    A comma-separated list of source fields to exclude from the response. You can also use this parameter to exclude fields from the subset specified in _source_includes query parameter. If the _source parameter is false, this parameter is ignored.

  • :_source_includes (String, Array<String>)

    A comma-separated list of source fields to include in the response. If this parameter is specified, only these source fields are returned. You can exclude fields from this subset using the _source_excludes query parameter. If the _source parameter is false, this parameter is ignored.

  • :stored_fields (String, Array<String>)

    A comma-separated list of stored fields to return in the response.

  • :q (String)

    The query in the Lucene query string syntax.

  • :error_trace (Boolean)

    When set to true Elasticsearch will include the full stack trace of errors when they occur.

  • :filter_path (String, Array<String>)

    Comma-separated list of filters in dot notation which reduce the response returned by Elasticsearch.

  • :human (Boolean)

    When set to true will return statistics in a format suitable for humans. For example ‘“exists_time”: “1h”` for humans and `“exists_time_in_millis”: 3600000` for computers. When disabled the human readable values will be omitted. This makes sense for responses being consumed only by machines.

  • :pretty (Boolean)

    If set to true the returned JSON will be “pretty-formatted”. Only use this option for debugging only.

  • :headers (Hash)

    Custom HTTP headers

  • :body (Hash)

    request body

Raises:

  • (ArgumentError)

See Also:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/elasticsearch/api/actions/explain.rb', line 70

def explain(arguments = {})
  request_opts = { endpoint: arguments[:endpoint] || 'explain' }

  defined_params = [:index, :id].each_with_object({}) do |variable, set_variables|
    set_variables[variable] = arguments[variable] if arguments.key?(variable)
  end
  request_opts[:defined_params] = defined_params unless defined_params.empty?

  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  arguments = arguments.clone
  headers = arguments.delete(:headers) || {}

  body = arguments.delete(:body)

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  method = if body
             Elasticsearch::API::HTTP_POST
           else
             Elasticsearch::API::HTTP_GET
           end

  path   = "#{Utils.listify(_index)}/_explain/#{Utils.listify(_id)}"
  params = Utils.process_params(arguments)

  Elasticsearch::API::Response.new(
    perform_request(method, path, params, body, headers, request_opts)
  )
end