explainedit

client.explain([params, [callback]])

Provides details about a specific document’s score in relation to a specific query. It will also tell you if the document matches the specified query.

Check the API Conventions and the elasticsearch docs for more information pertaining to this method.

See how a document is scored against a simple query.

const response = await client.explain({
  // the document to test
  index: 'myindex',
  type: 'mytype',
  id: '1',

  // the query to score it against
  q: 'field:value'
});

See how a document is scored against a query written in the Query DSL.

const response = await client.explain({
  index: 'myindex',
  type: 'mytype',
  id: '1',
  body: {
    query: {
      match: { title: 'test' }
    }
  }
});

Params

analyzeWildcard

Boolean — Specify whether wildcards and prefix queries in the query string query should be analyzed (default: false)

analyzer

String — The analyzer for the query string query

[defaultOperator=OR]

String — The default operator for query string query (AND or OR)

Options
  • "AND"
  • "OR"

df

String — The default field for query string query (default: _all)

storedFields

String, String[], Boolean — A comma-separated list of stored fields to return in the response

lenient

Boolean — Specify whether format-based query failures (such as providing text to a numeric field) should be ignored

parent

String — The ID of the parent document

preference

String — Specify the node or shard the operation should be performed on (default: random)

q

String — Query in the Lucene query string syntax

routing

String — Specific routing value

_source

String, String[], Boolean — True or false to return the _source field or not, or a list of fields to return

_sourceExcludes

String, String[], Boolean — A list of fields to exclude from the returned _source field

_sourceIncludes

String, String[], Boolean — A list of fields to extract and return from the _source field

id

String — The document ID

index

String — The name of the index

type

String — The type of the document

body

Object, JSON — An optional request body, as either JSON or a JSON serializable object. See the elasticsearch docs for details about what can be specified here.

back to top