Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Clojure client for Apache Solr
branch: master

This branch is 16 commits behind mlehman:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


A clojure client for Apache Solr.


Creating the client

(use 'solrclj)
(use 'solrclj.servers)

;; Http Solr Example
(def server (create-solr-server {:type :http 
                                 :host "localhost"}))

;; Http Multi-core Solr Example
(def server (create-solr-server {:type :http 
                                 :core "books"
                                 :host "localhost"}))

;; Embedded Solr Example
(def server (create-solr-server {:type :embedded 
                                 :core "mycore"
                                 :dir "/home-path"}))


The first argument is the mandatory solr query parameter (q). Any additional solr parameters can be added using additional keyword arguments. Use a vector as the value to send multiple params. The query can use the Solr Query Syntax.

;; Simple Query 
(query server "la mancha")

;; Query with Solr Query Syntax
(query server "author:Dickens AND year:[1843 TO 1848]")

;; Paging
(query server "author:c*" :rows 100 :start 100)

;; Getting the documents from the response
(first (get-in (query server "la mancha") [:response :docs]))
;=>  {:title "Don Quixote" :author "Miguel de Cervantes" :summary "..." }

;; Multiple Filter Queries
(query server "la mancha" :fq ["language:es" "year:[* TO 1900]"])

Other Optional Query Params

  • :q.op - the default query operation - "AND" or "OR"
  • :sort - sorts the documents - "year desc", "author asc, year asc"
  • :start - start index of documents
  • :rows - number of documents returned
  • :fq - filter query to restrict results - "language:en"
  • :fl - specify fields returned - "score, author, title"

Faceting Query Results

;; Faceting
(query server "*:*" :rows 0 :facet true :facet.field :author)

Adding Documents

;; Adding a Document
(add server {:title "Don Quixote" :author "Miguel de Cervantes" :summary "..." })

;; Adding Documents
(apply add server seq-of-maps)

Deleting Documents

;; Delete
(delete-by-query server "*:*")

;; Commit 
(commit server)

Core Administration

To enable dynamic core configuration, make sure the adminPath attribute is set in your solr.xml. If this attribute is absent, the CoreAdminHandler will not be available.

(use 'solrclj.coreadmin)

;; Get the status
(status server)

;; Create a new core
(create server "my_core" "core_dir" core-config-file core-schema-file)

;; Reload a core
(reload server "my_core")


Modify your Leiningen dependencies to include Solrclj:

:dependencies [[solrclj/solrclj "0.1.1"] ...] 


Something went wrong with that request. Please try again.