View Source ElasticsearchEx.Api.Document (Elasticsearch_ex v0.6.2)
Provides the APIs for the single document operations.
Summary
Functions
Adds a JSON document to the specified data stream or index and makes it searchable.
Removes a JSON document from the specified index.
Checks if the specified JSON document from an index exists.
Retrieves the specified JSON document from an index.
Retrieves the specified JSON source from an index.
Adds a JSON document to the specified data stream or index and makes it searchable. If the target is an index and the document already exists, the request updates the document and increments its version.
Checks if the specified JSON source from an index exists.
Updates a document using the specified script.
Functions
@spec create( map(), keyword() ) :: ElasticsearchEx.response()
Adds a JSON document to the specified data stream or index and makes it searchable.
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.Document.create(
...> %{
...> "@timestamp": "2099-11-15T13:12:00",
...> message: "GET /search HTTP/1.1 200 1070000",
...> user: %{id: "kimchy"}
...> },
...> index: "my-index-000001",
...> id: "W0tpsmIBdwcYyG50zbta"
...> )
{:ok,
%{
"_id" => "W0tpsmIBdwcYyG50zbta",
"_index" => "my-index-000001",
"_primary_term" => 1,
"_seq_no" => 0,
"_shards" => %{"failed" => 0, "successful" => 2, "total" => 2},
"_version" => 1,
"result" => "created"
}}
@spec delete(keyword()) :: ElasticsearchEx.response()
Removes a JSON document from the specified index.
Query parameters
Refer to the official documentation for a detailed list of the parameters.
Examples
iex> ElasticsearchEx.Api.Document.delete(index: "my-index-000001", id: "0")
{:ok,
%{
"_id" => "0",
"_index" => "my-index-000001",
"_primary_term" => 3,
"_seq_no" => 6,
"_shards" => %{"failed" => 0, "successful" => 1, "total" => 2},
"_version" => 2,
"result" => "deleted"
}}
iex> ElasticsearchEx.Api.Document.delete(index: "my-index-000001", id: "1")
{:error,
%ElasticsearchEx.Error{
reason: "Document with ID: `1` not found",
root_cause: nil,
status: 404,
type: "not_found",
...
}}
Checks if the specified JSON document from an index exists.
Query parameters
Refer to the official documentation for a detailed list of the parameters.
Examples
iex> ElasticsearchEx.Api.Document.document_exists?(index: "my-index-000001", id: "0")
true
@spec get_document(keyword()) :: ElasticsearchEx.response()
Retrieves the specified JSON document from an index.
Query parameters
Refer to the official documentation for a detailed list of the parameters.
Examples
iex> ElasticsearchEx.Api.Document.get_document(index: "my-index-000001", id: "0")
{:ok,
%{
"_id" => "0",
"_index" => "my-index-000001",
"_primary_term" => 1,
"_seq_no" => 0,
"_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"}
},
"_version" => 1,
"found" => true
}}
@spec get_source(keyword()) :: ElasticsearchEx.response()
Retrieves the specified JSON source from an index.
Query parameters
Refer to the official documentation for a detailed list of the parameters.
Examples
iex> ElasticsearchEx.Api.Document.get_source(index: "my-index-000001", id: "0")
{:ok,
%{
"@timestamp" => "2099-11-15T14:12:12",
"http" => %{
"request" => %{"method" => "get"},
"response" => %{"bytes" => 1_070_000, "status_code" => 200},
"version" => "1.1"
},
"message" => "GET /search HTTP/1.1 200 1070000",
"source" => %{"ip" => "127.0.0.1"},
"user" => %{"id" => "kimchy"}
}}
@spec index( map(), keyword() ) :: ElasticsearchEx.response()
Adds a JSON document to the specified data stream or index and makes it searchable. If the target is an index and the document already exists, the request updates the document and increments its version.
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
Without a specific document ID:
iex> ElasticsearchEx.Api.Document.index(
...> %{
...> "@timestamp": "2099-11-15T13:12:00",
...> message: "GET /search HTTP/1.1 200 1070000",
...> user: %{id: "kimchy"}
...> },
...> index: "my-index-000001"
...> )
{:ok,
%{
"_id" => "W0tpsmIBdwcYyG50zbta",
"_index" => "my-index-000001",
"_primary_term" => 1,
"_seq_no" => 0,
"_shards" => %{"failed" => 0, "successful" => 2, "total" => 2},
"_version" => 1,
"result" => "created"
}}
With a specific document ID:
iex> ElasticsearchEx.Api.Document.index(
...> %{
...> "@timestamp": "2099-11-15T13:12:00",
...> message: "GET /search HTTP/1.1 200 1070000",
...> user: %{id: "kimchy"}
...> },
...> index: "my-index-000001",
...> id: "W0tpsmIBdwcYyG50zbta"
...> )
{:ok,
%{
"_id" => "W0tpsmIBdwcYyG50zbta",
"_index" => "my-index-000001",
"_primary_term" => 1,
"_seq_no" => 0,
"_shards" => %{"failed" => 0, "successful" => 2, "total" => 2},
"_version" => 1,
"result" => "created"
}}
Checks if the specified JSON source from an index exists.
Query parameters
Refer to the official documentation for a detailed list of the parameters.
Examples
iex> ElasticsearchEx.Api.Document.source_exists?(index: "my-index-000001", id: "0")
true
@spec update( map(), keyword() ) :: ElasticsearchEx.response()
Updates a document using the specified script.
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.Document.update(
...> %{
...> script: %{
...> source: "ctx._source.message = params.message",
...> lang: "painless",
...> params: %{message: "Bye World"}
...> }
...> },
...> index: "my-index-000001",
...> id: "0"
...> )
{:ok,
%{
"_id" => "0",
"_index" => "my-index-000001",
"_primary_term" => 1,
"_seq_no" => 1,
"_version" => 2,
"_shards" => %{"failed" => 0, "successful" => 1, "total" => 1},
"result" => "updated"
}}