Searching Documents

Search is the primary operation of Elasticsearch. The client supports all kinds of searches supported by the Elasticsearch REST API. There are two different ways to search.

Response

The JSON response returned from Elasticsearch is parsed to a Lua table and returned directly. It consists of some metadata(took, timed_out, etc.) and a hits table. hits.total contains the total number of matches. hits.hits is a lua array and each entry represents one matching document.

{
  ["took"] = 3.0,
  ["timed_out"] = false,
  ["_shards"] = {
    ["failed"] = 0.0,
    ["total"] = 5.0,
    ["successful"] = 5.0
  },
  ["hits"] = {
    ["total"] = 1.0,
    ["max_score"] = 7.7399282,
    ["hits"] = {
      ["1"] = {
        ["_index"] = "my_index",
        ["_type"] = "my_type",
        ["_id"] = "my_id",
        ["_score"] = 7.7399282,
        ["_source"] = {
          ["my_key"] = "my_param"
        }
      }
    }
  }
}