Meilisearch.Documents (meilisearch v0.20.0) View Source

Collection of functions used to manage documents.

MeiliSearch Documentation - Documents

Link to this section Summary

Functions

Add document(s) to given index.

Add document(s) to given index.

Delete one or more documents based on id in a given index.

Delete all documents in given index.

Get one document by id.

List documents in given index.

Link to this section Functions

Link to this function

add_or_replace(index_uid, docs, opts \\ [])

View Source

Specs

add_or_replace(String.t(), [any()], Keyword.t()) :: Meilisearch.HTTP.response()

Add document(s) to given index.

If an exisiting document (based on primary key) is given it will be replaced.

Examples

iex> Meilisearch.Documents.add_or_replace("meilisearch_test", %{
  "id" => 2,
  "tagline" => "You'll never go in the water again",
  "title" => "Jaws"
})
{:ok, %{"updateId" => 1}}

iex> Meilisearch.Documents.add_or_replace(
  "meilisearch_test",
  [
    %{
      "id" => 6,
      "tagline" => "Who ya gonna call?",
      "title" => "Ghostbusters"
    },
    %{
      "id" => 5,
      "tagline" => "Be Afraid. Be very afraid.",
      "title" => "The Fly"
    }
  ]
)
{:ok, %{"updateId" => 1}}
Link to this function

add_or_update(index_uid, docs, opts \\ [])

View Source

Specs

add_or_update(String.t(), [any()], Keyword.t()) ::
  {:ok, any()} | {:error, String.t()}

Add document(s) to given index.

If an exisiting document (based on primary key) is given it will be updated with provided values.

Examples

iex> Meilisearch.Documents.add_or_update("meilisearch_test", %{
  "id" => 2,
  "tagline" => "You'll never go in the water again",
  "title" => "Jaws"
})
{:ok, %{"updateId" => 1}}

iex> Meilisearch.Documents.add_or_update(
  "meilisearch_test",
  [
    %{
      "id" => 6,
      "tagline" => "Who ya gonna call?",
      "title" => "Ghostbusters"
    },
    %{
      "id" => 5,
      "tagline" => "Be Afraid. Be very afraid.",
      "title" => "The Fly"
    }
  ]
)
{:ok, %{"updateId" => 1}}
Link to this function

delete(index_uid, document_ids)

View Source

Specs

delete(String.t(), String.t() | [String.t()]) ::
  {:ok, any()} | {:error, String.t()}

Delete one or more documents based on id in a given index.

Example

iex> Meilisearch.Documents.delete("meilisearch_test", 1)
{:ok, %{"updateId" => 0}}

iex> Meilisearch.Documents.delete("meilisearch_test", [1,2,3,4])
{:ok, %{"updateId" => 0}}

Specs

delete_all(String.t()) :: {:ok, any()} | {:error, binary()}

Delete all documents in given index.

Example

iex> Meilisearch.Documents.delete_all("meilisearch_test")
{:ok, %{"updateId" => 0}}
Link to this function

get(index_uid, document_id)

View Source

Specs

Get one document by id.

Example

iex> Meilisearch.Documents.get("meilisearch_test", 1)
{:ok,
%{
  "id" => 1,
  "tagline" => "In space no one can hear you scream",
  "title" => "Alien"
}}
Link to this function

list(index_uid, opts \\ [])

View Source

Specs

List documents in given index.

Options

  • offset Number of documents to skip. Defaults to 0
  • limit Maximum number of documents returned. Defaults to 20

Examples

iex> Meilisearch.Documents.list("meilisearch_test")
{:ok,
  [
    %{
      "id" => 2,
      "tagline" => "You'll never go in the water again",
      "title" => "Jaws"
    },
    %{
      "id" => 1,
      "tagline" => "In space no one can hear you scream",
      "title" => "Alien"
    }
  ]
}

iex> Meilisearch.Documents.get("meilisearch_test", limit: 2, offset: 4)
{:ok,
  [
    %{
      "id" => 6,
      "tagline" => "Who ya gonna call?",
      "title" => "Ghostbusters"
    },
    %{
      "id" => 5,
      "tagline" => "Be Afraid. Be very afraid.",
      "title" => "The Fly"
    }
  ]
}