OpenApiTypesense.Documents (OpenApiTypesense v1.3.2)

View Source

Provides API endpoints related to documents

Summary

Types

delete_documents_200_json_resp()

(since 0.4.0)
@type delete_documents_200_json_resp() :: %{num_deleted: integer()}

update_documents_200_json_resp()

(since 0.4.0)
@type update_documents_200_json_resp() :: %{num_updated: integer()}

Functions

delete_document(collection_name, document_id, opts \\ [])

(since 0.4.0)
@spec delete_document(
  collection_name :: String.t(),
  document_id :: String.t(),
  opts :: keyword()
) ::
  {:ok, map()} | {:error, OpenApiTypesense.ApiResponse.t()}

Delete a document

Delete an individual document from a collection by using its ID.

Options

  • ignore_not_found: Ignore the error and treat the deletion as success.

delete_documents(collection_name, opts \\ [])

(since 0.4.0)
@spec delete_documents(collection_name :: String.t(), opts :: keyword()) ::
  {:ok, delete_documents_200_json_resp()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Delete a bunch of documents

Delete a bunch of documents that match a specific filter condition. Use the batch_size parameter to control the number of documents that should deleted at a time. A larger value will speed up deletions, but will impact performance of other operations running on the server.

Options

  • batch_size: Batch size parameter controls the number of documents that should be deleted at a time. A larger value will speed up deletions, but will impact performance of other operations running on the server.
  • filter_by: Filter results by a particular value(s) or logical expressions. multiple conditions with &&.
  • ignore_not_found: To ignore an error and treat the deletion as success.
  • truncate: When true, removes all documents from the collection while preserving the collection and its schema.

delete_search_override(collection_name, override_id, opts \\ [])

(since 0.4.0)
@spec delete_search_override(
  collection_name :: String.t(),
  override_id :: String.t(),
  opts :: keyword()
) ::
  {:ok, OpenApiTypesense.SearchOverrideDeleteResponse.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Warning on using Typesense v30.0 and above

v30.0 and above doesn't use this function delete_search_override/3. Try CurationSets module. See https://typesense.org/docs/30.0/api/#deprecations-behavior-changes

Delete an override associated with a collection

export_documents(collection_name, opts \\ [])

(since 0.4.0)
@spec export_documents(collection_name :: String.t(), opts :: keyword()) ::
  {:ok, String.t()} | {:error, OpenApiTypesense.ApiResponse.t()}

Export all documents in a collection

Export all documents in a collection in JSON lines format.

Options

  • filter_by: Filter conditions for refining your search results. Separate multiple conditions with &&.
  • include_fields: List of fields from the document to include in the search result
  • exclude_fields: List of fields from the document to exclude in the search result

get_document(collection_name, document_id, opts \\ [])

(since 0.4.0)
@spec get_document(
  collection_name :: String.t(),
  document_id :: String.t(),
  opts :: keyword()
) ::
  {:ok, map()} | {:error, OpenApiTypesense.ApiResponse.t()}

Retrieve a document

Fetch an individual document from a collection by using its ID.

Options

  • include_fields: List of fields that should be present in the returned document.
  • exclude_fields: List of fields that should not be present in the returned document.

get_search_override(collection_name, override_id, opts \\ [])

(since 0.4.0)
@spec get_search_override(
  collection_name :: String.t(),
  override_id :: String.t(),
  opts :: keyword()
) ::
  {:ok, OpenApiTypesense.SearchOverride.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Retrieve a single search override

Retrieve the details of a search override, given its id.

get_search_overrides(collection_name, opts \\ [])

(since 0.4.0)
@spec get_search_overrides(collection_name :: String.t(), opts :: keyword()) ::
  {:ok, OpenApiTypesense.SearchOverridesResponse.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Warning on using Typesense v30.0 and above

v30.0 and above doesn't use this function get_search_overrides/2. Try CurationSets module. See https://typesense.org/docs/30.0/api/#deprecations-behavior-changes

List all collection overrides

Options

  • limit: Limit results in paginating on collection listing.
  • offset: Skip a certain number of results and start after that.

import_documents(collection_name, body, opts \\ [])

(since 0.4.0)
@spec import_documents(
  collection_name :: String.t(),
  body :: String.t(),
  opts :: keyword()
) ::
  {:ok, String.t()} | {:error, OpenApiTypesense.ApiResponse.t()}

Import documents into a collection

The documents to be imported must be formatted in a newline delimited JSON structure. You can feed the output file from a Typesense export operation directly as import.

Options

  • batch_size: Batch size parameter controls the number of documents that should be imported at a time. A larger value will speed up imports, but will impact performance of other operations running on the server.
  • return_id: Returning the id of the imported documents. If you want the import response to return the ingested document's id in the response, you can use the return_id parameter.
  • remote_embedding_batch_size: Max size of each batch that will be sent to remote APIs while importing multiple documents at once. Using lower amount will lower timeout risk, but increase number of requests made. Default is 200.
  • remote_embedding_timeout_ms: How long to wait until an API call to a remote embedding service is considered a timeout during indexing. Default is 60_000 ms
  • remote_embedding_num_tries: The number of times to retry an API call to a remote embedding service on failure during indexing. Default is 2.
  • return_doc: Returns the entire document back in response.
  • action: Additional action to perform
  • dirty_values: Dealing with Dirty Data

Request Body

Content Types: application/octet-stream

The json array of documents or the JSONL file to import

index_document(collection_name, body, opts \\ [])

(since 0.4.0)
@spec index_document(collection_name :: String.t(), body :: map(), opts :: keyword()) ::
  {:ok, map()} | {:error, OpenApiTypesense.ApiResponse.t()}

Index a document

A document to be indexed in a given collection must conform to the schema of the collection.

Options

  • action: Additional action to perform
  • dirty_values: Dealing with Dirty Data

Request Body

Content Types: application/json

The document object to be indexed

multi_search(body, opts \\ [])

(since 0.4.0)

send multiple search requests in a single HTTP request

This is especially useful to avoid round-trip network latencies incurred otherwise if each of these requests are sent in separate HTTP requests. You can also use this feature to do a federated search across multiple collections in a single HTTP request.

Options

  • limit_multi_searches: Max number of search requests that can be sent in a multi-search request. Default 50
  • x-typesense-api-key: You can embed a separate search API key for each search within a multi_search request. This is useful when you want to apply different embedded filters for each collection in individual scoped API keys.

Request Body

Content Types: application/json

search_collection(collection_name, opts \\ [])

(since 0.4.0)
@spec search_collection(collection_name :: String.t(), opts :: keyword()) ::
  {:ok, OpenApiTypesense.SearchResult.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Search for documents in a collection

Search for documents in a collection that match the search criteria.

Options

Either one of:

  • search_collection(collectionName, params)
  • search_collection(%{api_key: xyz, host: ...}, collectionName, params)
  • search_collection(Connection.new(), collectionName, params)

Example

iex> schema = %{
...>   "name" => "houses",
...>   "fields" => [
...>     %{"name" => "house_type", "type" => "string"},
...>     %{"name" => "houses_id", "type" => "int32"},
...>     %{"name" => "description", "type" => "string"},
...>   ],
...>   "default_sorting_field" => "houses_id",
...> }
iex> OpenApiTypesense.Collections.create_collection(schema)
iex> params = [q: "duplex", query_by: "house_type"]
...> OpenApiTypesense.Documents.search_collection("houses", params)

update_document(collection_name, document_id, body, opts \\ [])

(since 0.4.0)
@spec update_document(
  collection_name :: String.t(),
  document_id :: String.t(),
  body :: map(),
  opts :: keyword()
) :: {:ok, map()} | {:error, OpenApiTypesense.ApiResponse.t()}

Update a document

Update an individual document from a collection by using its ID. The update can be partial.

Options

  • dirty_values: Dealing with Dirty Data

Request Body

Content Types: application/json

The document object with fields to be updated

update_documents(collection_name, body, opts \\ [])

(since 0.4.0)
@spec update_documents(
  collection_name :: String.t(),
  body :: map(),
  opts :: keyword()
) ::
  {:ok, update_documents_200_json_resp()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Update documents with conditional query

The filter_by query parameter is used to filter to specify a condition against which the documents are matched. The request body contains the fields that should be updated for any documents that match the filter condition. This endpoint is only available if the Typesense server is version 0.25.0.rc12 or later.

Options

  • filter_by: Filter results by a particular value(s) or logical expressions. multiple conditions with &&.
  • action: Additional action to perform

Request Body

Content Types: application/json

The document fields to be updated

upsert_search_override(collection_name, override_id, body, opts \\ [])

(since 0.4.0)
@spec upsert_search_override(
  collection_name :: String.t(),
  override_id :: String.t(),
  body :: OpenApiTypesense.SearchOverrideSchema.t(),
  opts :: keyword()
) ::
  {:ok, OpenApiTypesense.SearchOverride.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Warning on using Typesense v30.0 and above

v30.0 and above doesn't use this function upsert_search_override/4. Try CurationSets module. See https://typesense.org/docs/30.0/api/#deprecations-behavior-changes

Create or update an override to promote certain documents over others

Create or update an override to promote certain documents over others. Using overrides, you can include or exclude specific documents for a given query.

Request Body

Content Types: application/json

The search override object to be created/updated