https://github.com/agrison/duct-elasticsearch
Integrant multimethods for connecting to ElasticSearch via Spandex.
https://github.com/agrison/duct-elasticsearch
Last synced: 2 months ago
JSON representation
Integrant multimethods for connecting to ElasticSearch via Spandex.
- Host: GitHub
- URL: https://github.com/agrison/duct-elasticsearch
- Owner: agrison
- License: epl-1.0
- Created: 2018-06-21T13:44:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-21T13:54:54.000Z (almost 8 years ago)
- Last Synced: 2025-07-10T16:39:37.512Z (11 months ago)
- Language: Clojure
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Duct database.elasticsearch.spandex
[](https://travis-ci.org/agrison/duct-elasticsearch)
Integrant multimethods for connecting to [ElasticSearch][] via [Spandex][].
[elasticsearch]: http://elastic.co
[spandex]: https://github.com/mpenet/spandex
## Installation
To install, add the following to your project `:dependencies`:
[me.grison/duct-elasticsearch "0.1.0"]
## Usage
This library provides two things:
* a `Boundary` record that holds both the Spandex client (`:client`)
and a sniffer (`:sniffer`) if asked for.
* a multimethod for `:duct.database.elasticsearch/spandex` that initiates
the client based on those options into the Boundary.
When you write functions against the ElasticSearch database,
consider using a protocol and extending the Boundary record.
This will allow you to easily mock or stub out the database
using a tool like [Shrubbery][].
A `:logger` key may also be specified, which will be used to log when
the module connects to or disconnects from ElasticSearch.
The value of the key should be an implementation of the
`duct.logger/Logger` protocol from the [duct.logger][] library
[shrubbery]: https://github.com/bguthrie/shrubbery
[duct.logger]: https://github.com/duct-framework/logger
## Connection settings
### Client
```edn
{:duct.database.elasticsearch/spandex
{:client {:hosts ["127.0.0.1" "192.168.0.234"]}}}
```
### Sniffer
```edn
{:duct.database.elasticsearch/spandex
{:client {:hosts ["127.0.0.1" "192.168.0.234"]}}
:sniffer? true
:sniffer { ... }}
```
For more information about Spandex client options you can see their
[client documentation](https://mpenet.github.io/spandex/qbits.spandex.html#var-client)
and [sniffer documentation](https://mpenet.github.io/spandex/qbits.spandex.html#var-sniffer)
## Example
The ES REST client can be extracted from this module Boundary by using the `:client` key.
```clojure
(ns my-project.boundary.entry-db
(:require [duct.database.elasticsearch.spandex]
[qbits.spandex :as s]))
(defprotocol EntryDatabase
(search [db]))
(extend-protocol EntryDatabase
duct.database.elasticsearch.spandex.Boundary
(search [{:keys [client]}]
(s/request client {:url "/entries/entry/_search"
:method :get
:body {:query {:match_all {}}}})))
```
## License
Copyright © 2018 Alexandre Grison
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.