OpenApiTypesense.Documents (OpenApiTypesense v1.0.4)
View SourceProvides API endpoints related to documents
Summary
Functions
Delete a document
Delete a bunch of documents
Delete an override associated with a collection
Export all documents in a collection
Retrieve a document
Retrieve a single search override
List all collection overrides
Import documents into a collection
Index a document
send multiple search requests in a single HTTP request
Search for documents in a collection
Update a document
Update documents with conditional query
Create or update an override to promote certain documents over others
Types
Functions
@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.
@spec delete_documents(collection_name :: String.t(), opts :: keyword()) :: {:ok, map()} | {: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.
@spec delete_search_override( collection_name :: String.t(), override_id :: String.t(), opts :: keyword() ) :: {:ok, OpenApiTypesense.SearchOverrideDeleteResponse.t()} | {:error, OpenApiTypesense.ApiResponse.t()}
Delete an override associated with a collection
@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 resultexclude_fields
: List of fields from the document to exclude in the search result
@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.
@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.
@spec get_search_overrides(collection_name :: String.t(), opts :: keyword()) :: {:ok, OpenApiTypesense.SearchOverridesResponse.t()} | {:error, OpenApiTypesense.ApiResponse.t()}
List all collection overrides
Options
limit
: Limit results in paginating on collection listing.offset
: Skip a certain number of results and start after that.
@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 msremote_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 performdirty_values
: Dealing with Dirty Data
@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 performdirty_values
: Dealing with Dirty Data
@spec multi_search( body :: OpenApiTypesense.MultiSearchSearchesParameter.t(), opts :: keyword() ) :: {:ok, OpenApiTypesense.MultiSearchResult.t()} | {:error, OpenApiTypesense.ApiResponse.t()}
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 50x-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.
@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
searchParameters
can be found here: https://typesense.org/docs/latest/api/search.html#search-parameters
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)
@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
@spec update_documents( collection_name :: String.t(), body :: map(), opts :: keyword() ) :: {:ok, map()} | {: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
@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()}
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.