A Clojure client for Apache Solr
Latest commit 978c8c5 Sep 26, 2013 @mlehman Update .travis.yml
Failed to load latest commit information.
src Upgrade to Solr 3.6.2 Apr 4, 2013
test-jetty Upgrade to Solr 3.6.2 Apr 4, 2013
test-solr solrclj/query now returns properly oredered maps Jun 23, 2011
.gitignore Update to Lein 2 and Clojure 1.5 Removed java contrib dependency Apr 2, 2013
.travis.yml Update .travis.yml Sep 25, 2013
CHANGES.md 0.1.1 release changes Aug 13, 2011
project.clj Use 0.3.0 as new base version Apr 5, 2013



A clojure client for Apache Solr.

Build Status


Creating the client

(use 'solrclj)

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

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

;; Embedded Solr Example
(def server (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.2"] ...]