clojurewerkz.elastisch.rest.document

Key operations on documents: indexing, search, deletion, etc

analyze

(analyze conn text & args)
Examples:

(require '[clojurewerkz.elastisch.rest.document :as doc])

(doc/analyze conn "foo bar baz")
(doc/analyze conn "foo bar baz" :index "some-index-name")
(doc/analyze conn "foo bar baz" :analyzer "whitespace")
(doc/analyze conn "foo bar baz" :index "some-index-name" :field "some-field-name")

count

(count conn index mapping-type)(count conn index mapping-type query)(count conn index mapping-type query & args)
Performs a count query.

Examples:

(require '[clojurewerkz.elastisch.rest.document :as doc])
(require '[clojurewerkz.elastisch.query :as q])

(doc/count conn "people" "person")
(doc/count conn "people" "person" (q/prefix :username "appl"))

create

(create conn index mapping-type document & args)
Adds document to the search index. Document id will be generated automatically.

Options:

  * :id (string): unique document id. If not provided, it will be generated by ElasticSearch
  * :timestamp (string): document timestamp either as millis since the epoch,
                                       or, in the configured date format
  * :ttl (long): document TTL in milliseconds. Must be > 0
  * :refresh (boolean, default: false): should a refresh be executed post this index operation?
  * :version (long): document version
  * :version-type (string, default: "internal"): "internal" or "external"
  * :content-type (string): document content type
  * :routing (string): controls the shard routing of the request. Using this value to hash the shard
                       and not the id
  * :percolate (string): the percolate query to use to reduce the percolated queries that are going to run against this doc.
                        Can be set to "*" which means "all queries"
  * :parent (string): parent document id

Examples:

(require '[clojurewerkz.elastisch.rest.document :as doc])

(doc/create conn "people" "person" {:first-name "John" :last-name "Appleseed" :age 28})

(doc/create conn "people" "person" {:first-name "John" :last-name "Appleseed" :age 28} :id "1825c5432775b8d1a477acfae57e91ac8c767aed")

delete

(delete conn index mapping-type id)(delete conn index mapping-type id & args)
Deletes document from the index.

delete-by-query

(delete-by-query conn index mapping-type query)(delete-by-query conn index mapping-type query & args)
Performs a delete-by-query operation.

delete-by-query-across-all-indexes-and-types

(delete-by-query-across-all-indexes-and-types conn query)(delete-by-query-across-all-indexes-and-types conn query & args)
Performs a delete-by-query operation across all indexes and mapping types.
This may put very high load on your ElasticSearch cluster so use this function with care.

delete-by-query-across-all-types

(delete-by-query-across-all-types conn index query)(delete-by-query-across-all-types conn index query & args)
Performs a delete-by-query operation across all mapping types.

get

(get conn index mapping-type id & args)
Fetches and returns a document by id or nil if it does not exist.

Examples:

(require '[clojurewerkz.elastisch.rest.document :as doc])

(doc/get conn "people" "person" "1825c5432775b8d1a477acfae57e91ac8c767aed")

more-like-this

(more-like-this conn index mapping-type id & args)
Performs a More Like This (MLT) query.

multi-get

(multi-get conn query)(multi-get conn index query)(multi-get conn index mapping-type query)
Multi get returns only documents that are found (exist).

Queries can passed as a collection of maps with three keys: :_index,
:_type and :_id:

(doc/multi-get conn [{:_index index-name :_type mapping-type :_id "1"}
                     {:_index index-name :_type mapping-type :_id "2"}])


2-argument version accepts an index name that eliminates the need to include
:_index in every query map:

(doc/multi-get conn index-name [{:_type mapping-type :_id "1"}
                                {:_type mapping-type :_id "2"}])

3-argument version also accepts a mapping type that eliminates the need to include
:_type in every query map:

(doc/multi-get conn index-name mapping-type [{:_id "1"}
                                             {:_id "2"}])

optional-delete-query-parameters

Optional parameters that all query-based delete functions share

present?

(present? conn index mapping-type id)
Returns true if a document with the given id is present in the provided index
with the given mapping type.

put

(put conn index mapping-type id document)(put conn index mapping-type id document & args)
Creates or updates a document in the search index, using the provided document id

replace

(replace conn index mapping-type id document)
Replaces document with given id with a new one

scroll

(scroll conn scroll-id & args)
Performs a scroll query, fetching the next page of results from a
query given a scroll id

scroll-seq

(scroll-seq conn prev-resp {:keys [search_type]})(scroll-seq conn prev-resp)
Returns a lazy sequence of all documents for a given scroll query

search-all-indexes-and-types

(search-all-indexes-and-types conn & args)
Performs a search query across all indexes and all mapping types.
This may put very high load on your ElasticSearch cluster so use
this function with care.

search-all-types

(search-all-types conn index & args)
Performs a search query across one or more indexes and all mapping types.

update-with-partial-doc

(update-with-partial-doc conn index mapping-type id partial-doc)(update-with-partial-doc conn index mapping-type id partial-doc & args)
Updates an existing document in the search index with given partial document

update-with-script

(update-with-script conn index mapping-type id script)(update-with-script conn index mapping-type id script params)(update-with-script conn index mapping-type id script params & args)
Updates a document using a script.

Examples:

(require '[clojurewerkz.elastisch.rest.document :as doc])

(doc/update-with-script conn "people" "person" "1825c5432775b8d1a477acfae57e91ac8c767aed"
                                "ctx._source.age = ctx._source.age += 1" {} :lang "groovy")

upsert

(upsert conn index mapping-type id partial-doc)(upsert conn index mapping-type id partial-doc & args)
Updates an existing document in the search index with given partial document,
the provided document will be inserted if the document does not already exist

validate-query

(validate-query conn index query & args)
Validates a query without actually executing it. Has the same API as clojurewerkz.elastisch.rest.document/search
but does not take the mapping type parameter.