esx v0.5.7 ESx.Model

Already defined ESx Model using ESx.Model.Base

Summary

Functions

config()
create_index(schema, opts \\ [])

Create index with any options.

Options

  • :index - document index name
  • :type - document type name

Example

# Make index with defined schema
MyESx.create_index MyModel

# Make index with defined schema
MyESx.create_index MyModel, index: "any-index", type: "any-type"
delete_document(schema, opts \\ %{})
delete_index(schema, opts \\ [])
import(schema, opts \\ [])
index_document(schema, opts \\ %{})
index_exists?(schema, opts \\ [])
records(search)

See ESx.Model.Response.records/1.

records(search, queryable)

See ESx.Model.Response.records/2.

refresh_index(schema, opts \\ [])
reindex(schema, opts \\ [])
repo()
results(search)

See ESx.Model.Response.results/1.

search(queryable, query_or_payload, opts \\ [])

Search document from the data store matching the given query.

Options

  • :index - document index name in es
  • :type - document type name in es

Example

# Search 'my document' from elasticsearch
query = MyESx.search MyModel, %{query: %{match: %{title: "my document"}}}

# Featch docuemnt from elasticsarch
MyESx.results query

# Featch docuemnt from elasticsarch as Record struct which contains [Ecto.Schema.t] records.
MyESx.records query

Example with ecto queryable

# Set condition as issues ecto query.
query = from q in MyModel,
  where: q.publish == true,
  preload: [:thumbs, :category, :maker]

# Search 'my document' from elasticsearch
query = MyESx.search query, %{query: %{match: %{title: "my document"}}}

# Featch docuemnt from elasticsarch
MyESx.results query

# Featch docuemnt from elasticsarch as Record struct which contains [Ecto.Schema.t] records.
MyESx.records query
transport()