OpenApiTypesense.Collections (OpenApiTypesense v0.6.5)

View Source

Provides API endpoints related to collections

Summary

Functions

create_collection(body)

@spec create_collection(map()) ::
  {:ok, OpenApiTypesense.CollectionResponse.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Create a new collection

When a collection is created, we give it a name and describe the fields that will be indexed from the documents added to the collection.

Options

  • src_name: Clone an existing collection's schema (documents are not copied), overrides and synonyms. The actual documents in the collection are not copied, so this is primarily useful for creating new collections from an existing reference template.

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)

create_collection(body, opts)

Either one of:

  • create_collection(schema, opts)
  • create_collection(%{api_key: xyz, host: ...}, schema)
  • create_collection(Connection.new(), schema)

create_collection(conn, body, opts)

Either one of:

  • create_collection(%{api_key: 123, host: ...}, schema, opts)
  • create_collection(Connection.new(), schema, opts)

delete_alias(aliasName)

@spec delete_alias(String.t()) ::
  {:ok, OpenApiTypesense.CollectionAlias.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Delete an alias

delete_alias(aliasName, opts)

Either one of:

  • delete_alias(aliasName, opts)
  • delete_alias(%{api_key: 123, host: ...}, aliasName)
  • delete_alias(Connection.new(), aliasName)

delete_alias(conn, aliasName, opts)

Either one of:

  • delete_alias(%{api_key: 123, host: ...}, aliasName, opts)
  • delete_alias(Connection.new(), aliasName, opts)

delete_collection(collectionName)

@spec delete_collection(String.t()) ::
  {:ok, OpenApiTypesense.CollectionResponse.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Delete a collection

Permanently drops a collection. This action cannot be undone. For large collections, this might have an impact on read latencies.

delete_collection(collectionName, opts)

Either one of:

  • delete_collection(collectionName, opts)
  • delete_collection(%{api_key: 123, host: ...}, collectionName)
  • delete_collection(Connection.new(), collectionName)

delete_collection(conn, collectionName, opts)

Either one of:

  • delete_collection(%{api_key: 123, host: ...}, collectionName, opts)
  • delete_collection(Connection.new(), collectionName, opts)

get_alias(aliasName)

@spec get_alias(String.t()) ::
  {:ok, OpenApiTypesense.CollectionAlias.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Retrieve an alias

Find out which collection an alias points to by fetching it

get_alias(aliasName, opts)

Either one of:

  • get_alias(aliasName, opts)
  • get_alias(%{api_key: 123, host: ...}, aliasName)
  • get_alias(Connection.new(), aliasName)

get_alias(conn, aliasName, opts)

Either one of:

  • get_alias(%{api_key: 123, host: ...}, aliasName, opts)
  • get_alias(Connection.new(), aliasName, opts)

get_aliases()

List all aliases

List all aliases and the corresponding collections that they map to.

get_aliases(opts)

Either one of:

  • get_aliases(opts)
  • get_aliases(%{api_key: 123, host: ...})
  • get_aliases(Connection.new())

get_aliases(conn, opts)

Either one of:

  • get_aliases(%{api_key: 123, host: ...}, opts)
  • get_aliases(Connection.new(), opts)

get_collection(collectionName)

@spec get_collection(String.t()) ::
  {:ok, OpenApiTypesense.CollectionResponse.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Retrieve a single collection

Retrieve the details of a collection, given its name.

get_collection(collectionName, opts)

Either one of:

  • get_collection(collectionName, opts)
  • get_collection(%{api_key: 123, host: ...}, collectionName)
  • get_collection(Connection.new(), collectionName)

get_collection(conn, collectionName, opts)

Either one of:

  • get_collection(%{api_key: 123, host: ...}, collectionName, opts)
  • get_collection(Connection.new(), collectionName, opts)

get_collections()

@spec get_collections() ::
  {:ok, [OpenApiTypesense.CollectionResponse.t()]}
  | {:error, OpenApiTypesense.ApiResponse.t()}

List all collections

Returns a summary of all your collections. The collections are returned sorted by creation date, with the most recent collections appearing first.

Options

  • limit: Limit results in paginating on collection listing.
  • offset: Skip a certain number of results and start after that.
  • exclude_fields: Exclude the field definitions from being returned in the response.

get_collections(opts)

Either one of:

  • get_collections(Connection.new())
  • get_collections(%{api_key: xyz, host: ...})
  • get_collections(exclude_fields: "fields", limit: 10)

get_collections(conn, opts)

Either one of:

  • get_collections(%{api_key: 123, host: ...}, opts)
  • get_collections(Connection.new(), opts)

update_collection(collectionName, body)

@spec update_collection(String.t(), map()) ::
  {:ok, OpenApiTypesense.CollectionUpdateSchema.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Update a collection

Update a collection's schema to modify the fields and their types.

update_collection(collectionName, body, opts)

Either one of:

  • update_collection(collectionName, body, opts)
  • update_collection(%{api_key: 123, host: ...}, collectionName, body)
  • update_collection(Connection.new(), collectionName, body)

update_collection(conn, collectionName, body, opts)

Either one of:

  • update_collection(%{api_key: 123, host: ...}, collectionName, body, opts)
  • update_collection(Connection.new(), collectionName, body, opts)

upsert_alias(aliasName, body)

@spec upsert_alias(String.t(), map()) ::
  {:ok, OpenApiTypesense.CollectionAlias.t()}
  | {:error, OpenApiTypesense.ApiResponse.t()}

Create or update a collection alias

Create or update a collection alias. An alias is a virtual collection name that points to a real collection. If you're familiar with symbolic links on Linux, it's very similar to that. Aliases are useful when you want to reindex your data in the background on a new collection and switch your application to it without any changes to your code.

Example

iex> body = %{"collection_name" => "companies"}
iex> OpenApiTypesense.Collections.upsert_alias("foo", body)

upsert_alias(aliasName, body, opts)

Either one of:

  • upsert_alias(%{api_key: 123, host: ...}, aliasName, body)
  • upsert_alias(Connection.new(), aliasName, body)
  • upsert_alias(aliasName, body, opts)

upsert_alias(conn, aliasName, body, opts)

Either one of:

  • upsert_alias(%{api_key: 123, host: ...}, aliasName, body, opts)
  • upsert_alias(Connection.new(), aliasName, body, opts)