View Source ElasticsearchEx.Api.Search.Core (Elasticsearch_ex v0.2.0)

Search APIs are used to search and aggregate data stored in Elasticsearch indices and data streams. For an overview and related tutorials, see The search API.

Most search APIs support multi-target syntax, with the exception of the explain API.

Summary

Types

Represents the body expected by the search API.

The possible individual options accepted by the search function.

The possible options accepted by the search function.

Functions

Returns search hits that match the query defined in the request.

Types

@type search_body() :: map()

Represents the body expected by the search API.

@type search_opt() :: {:index, atom() | binary()}

The possible individual options accepted by the search function.

@type search_opts() :: [search_opt() | {:http_opts, keyword()} | {atom(), any()}]

The possible options accepted by the search function.

Functions

Link to this function

search(query, opts \\ [])

View Source
@spec search(search_body(), search_opts()) :: ElasticsearchEx.Client.response()

Returns search hits that match the query defined in the request.

It expects the first argument to be a valid Elasticsearch query represented by an Elixir Map.

Query parameters

Refer to the official documentation for a detailed list of the parameters.

Request body

Refer to the official documentation for a detailed list of the body values.

Examples

iex> ElasticsearchEx.Api.Search.Core.search(%{query: %{term: %{"user.id": "kimchy"}}},
...>   from: 40,
...>   size: 20
...> )
{:ok,
 %{
   "_shards" => %{
     "failed" => 0,
     "skipped" => 0,
     "successful" => 1,
     "total" => 1
   },
   "hits" => %{
     "hits" => [
       %{
         "_id" => "0",
         "_index" => "my-index-000001",
         "_score" => 1.3862942,
         "_source" => %{
           "@timestamp" => "2099-11-15T14:12:12",
           "http" => %{
             "request" => %{"method" => "get"},
             "response" => %{"bytes" => 1070000, "status_code" => 200},
             "version" => "1.1"
           },
           "message" => "GET /search HTTP/1.1 200 1070000",
           "source" => %{"ip" => "127.0.0.1"},
           "user" => %{"id" => "kimchy"}
         }
       },
       ...
     ],
     "max_score" => 1.3862942,
     "total" => %{"relation" => "eq", "value" => 20}
   },
   "timed_out" => false,
   "took" => 5
 }}