View Source ExTypesense.Collection (ExTypesense v0.4.1)

Module for creating, listing and deleting collections and aliases.

In Typesense, a Collection is a group of related Documents that is roughly equivalent to a table in a relational database. When we create a collection, we give it a name and describe the fields that will be indexed when a document is added to the collection.

Summary

Functions

Create collection from a map, or module name. Collection name is matched on table name if using Ecto schema by default.

Deletes a collection alias. The collection itself is not affected by this action.

Permanently drops a collection by collection name or module name.

Get a specific collection by string or module name.

Get a specific collection alias by string or module name.

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

Make changes in a collection's fields: adding, removing or updating an existing field(s). Key name is drop to indicate which field is removed (example described below). Only fields can only be updated at the moment.

Types

Link to this type

response()

View Source (since 0.1.0)
@type response() :: t() | [t() | map()] | map() | {:error, map()}
@type t() :: %ExTypesense.Collection{
  created_at: integer(),
  default_sorting_field: String.t(),
  enable_nested_fields: boolean(),
  fields: ExTypesense.Collection.Field.t(),
  name: String.t(),
  num_documents: integer(),
  symbols_to_index: list(),
  token_separators: list()
}

Functions

Link to this function

create_collection(conn \\ Connection.new(), schema)

View Source (since 0.1.0)
@spec create_collection(ExTypesense.Connection.t(), schema :: module() | map()) ::
  response()

Create collection from a map, or module name. Collection name is matched on table name if using Ecto schema by default.

Please refer to these list of schema params.

Examples

iex> schema = %{
...>   name: "companies",
...>   fields: [
...>     %{name: "company_name", type: "string"},
...>     %{name: "company_id", type: "int32"},
...>     %{name: "country", type: "string", facet: true}
...>   ],
...>   default_sorting_field: "company_id"
...> }
iex> ExTypesense.create_collection(schema)
%ExTypesense.Collection{
  created_at: 1234567890,
  default_sorting_field: "company_id",
  fields: [...],
  name: "companies",
  num_documents: 0,
  symbols_to_index: [],
  token_separators: []
}

iex> ExTypesense.create_collection(Person)
%ExTypesense.Collection{
  created_at: 1234567890,
  default_sorting_field: "person_id",
  fields: [...],
  name: "persons",
  num_documents: 0,
  symbols_to_index: [],
  token_separators: []
}
Link to this function

delete_collection_alias(conn \\ Connection.new(), alias_name)

View Source (since 0.1.0)
@spec delete_collection_alias(ExTypesense.Connection.t(), String.t() | module()) ::
  response()

Deletes a collection alias. The collection itself is not affected by this action.

Link to this function

drop_collection(conn \\ Connection.new(), name)

View Source (since 0.1.0)
@spec drop_collection(ExTypesense.Connection.t(), name :: String.t() | module()) ::
  response()

Permanently drops a collection by collection name or module name.

Note: dropping a collection does not remove the referenced alias, only the indexed documents.

Link to this function

get_collection(conn \\ Connection.new(), name)

View Source (since 0.1.0)
@spec get_collection(ExTypesense.Connection.t(), String.t() | module()) :: response()

Get a specific collection by string or module name.

Link to this function

get_collection_alias(conn \\ Connection.new(), alias_name)

View Source (since 0.1.0)
@spec get_collection_alias(ExTypesense.Connection.t(), String.t() | module()) ::
  response()

Get a specific collection alias by string or module name.

Link to this function

get_collection_name(conn \\ Connection.new(), alias_name)

View Source (since 0.3.0)
@spec get_collection_name(ExTypesense.Connection.t(), String.t() | module()) ::
  String.t()

Get the collection name by alias.

Link to this function

list_collection_aliases(conn \\ Connection.new())

View Source (since 0.1.0)
@spec list_collection_aliases(ExTypesense.Connection.t()) :: response()

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

Link to this function

list_collections(conn \\ Connection.new())

View Source (since 0.1.0)
@spec list_collections(ExTypesense.Connection.t()) :: response()

Lists all collections.

Link to this function

update_collection_fields(conn \\ Connection.new(), name, fields \\ %{})

View Source (since 0.1.0)
@spec update_collection_fields(
  ExTypesense.Connection.t(),
  name :: String.t() | module(),
  map()
) ::
  response()

Make changes in a collection's fields: adding, removing or updating an existing field(s). Key name is drop to indicate which field is removed (example described below). Only fields can only be updated at the moment.

Note: Typesense supports updating all fields except the id field (since it's a special field within Typesense).

Examples

iex> fields = %{
...>  fields: [
...>    %{name: "num_employees", drop: true},
...>    %{name: "company_category", type: "string"},
...>  ],
...> }
iex> ExTypesense.update_collection_fields("companies", fields)
%ExTypesense.Collection{
  created_at: 1234567890,
  name: companies,
  default_sorting_field: "company_id",
  fields: [...],
  num_documents: 0,
  symbols_to_index: [],
  token_separators: []
}

iex> ExTypesense.update_collection_fields(Company, fields)
%ExTypesense.Collection{
  created_at: 1234567890,
  name: companies,
  default_sorting_field: "company_id",
  fields: [...],
  num_documents: 0,
  symbols_to_index: [],
  token_separators: []
}
Link to this function

upsert_collection_alias(conn \\ Connection.new(), alias_name, collection_name)

View Source (since 0.1.0)
@spec upsert_collection_alias(
  ExTypesense.Connection.t(),
  String.t() | module(),
  String.t()
) ::
  response()

Upserts a collection alias.