If available in Hex, the package can be installed as:
- Add
scrivener_esx
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:scrivener_esx, "~> 0.1.0"}]
end
```
- Ensure
scrivener_esx
is started before your application:
```elixir
def application do
[applications: [:scrivener_esx]]
end
```
defmodule MyApp.ESx do
use ESx.Model.Base, app: :my_app
use Scrivener, page_size: 10
end
defmodule MyApp.Blog do
use MyApp.Web, :model
use ESx.Schema
schema "blogs" do
field :title, :string
field :content, :string
field :publish, :boolean
timestamps
end
mapping do
indexes :title, type: "string"
indexes :content, type: "string"
indexes :publish, type: "boolean"
end
def index(conn, params) do
page =
MyApp.Blog
|> MyApp.ESx.search(%{query: %{match: %{title: "foo"}}})
|> MyApp.ESx.paginate(params)
render conn, :index,
people: page.entries,
page_number: page.page_number,
page_size: page.page_size,
total_pages: page.total_pages,
total_entries: page.total_entries
end
page =
MyApp.Blog
|> MyApp.ESx.search(%{query: %{match: %{title: "foo"}}})
|> MyApp.ESx.paginate(page: 2, page_size: 5)