0

I am trying out clojure elastic search API Elastisch.

I was following the demo code given in the documentation I am getting document/index created output for the following code

(defn demo-search-connect []
  (esr/connect! "http://127.0.0.1:9200")
  (let [mapping-types {:person {:properties {:username   {:type "string" :store "yes"}
                                         :first-name {:type "string" :store "yes"}
                                         :last-name  {:type "string"}
                                         :age        {:type "integer"}
                                         :title      {:type "string" :analyzer
                                          "snowball"}
                                         :planet     {:type "string"}
                                         :biography  {:type "string" :analyzer   "snowball" :term_vector "with_positions_offsets"}}}}
    doc {:username "happyjoe" :first-name "Joe" :last-name "Smith" :age 30 :title "Teh Boss" :planet "Earth" :biography "N/A"}]

 (esi/create "myapp2_development" :mappings mapping-types)
;; adds a document to the index, id is automatically generated by ElasticSearch
;= {:ok true, :_index people, :_type person, :_id "2vr8sP-LTRWhSKOxyWOi_Q", :_version 1}
(println (esd/create "myapp2_development" :person doc :settings {"number_of_shards" 1}))
))

;Supposed to return an output for the search query 
(defn demo-search-index [] 
  (esr/connect! "http://127.0.0.1:9200")
  (esd/search "myapp2_development" "person" :query {:term {:last_name "Smith"}})
  )

;Supposed to return the document with the given id
(defn get-document [id]
  (esr/connect! "http://127.0.0.1:9200")
  (esd/get "myapp2_development" "person" id)
  )

I am getting the output for the first function as :

{:ok true, :_index myapp2_development, :_type :person, :_id GzNdzrqhQECQDlkSbq-GHA, :_version 1}

From the output I believe the document is getting indexed properly

The issue is that the second and third functions returns:

{:took 153, :timed_out false, :_shards {:total 5, :successful 5, :failed 0}, :hits {:total 0, :max_score nil, :hits []}}

and nil respectively.

What am I missing here?

P.S : I am new to clojure and elastic search

ponzao
  • 20,684
  • 3
  • 41
  • 58
Devasia Joseph
  • 388
  • 4
  • 14

1 Answers1

1

esd/get fails because your mapping type is :person not "person" (keyword vs. string).

Your code esd/search has the same problem, but in addition you should change last_name to last-name and by lower casing "Smith" to "smith" everything should work.

ponzao
  • 20,684
  • 3
  • 41
  • 58
  • Thank you!!! That solves it. Was wondering why demo code in the documentation had the keyword as a string? – Devasia Joseph Mar 16 '13 at 19:42
  • 1
    Might be a mistake on their part, or a problem with different versions behaving in a different way (I am using 1.0.2 and I could repeat your problems). They are quite helpful on GitHub and on their mailing list (https://groups.google.com/forum/#!forum/clojure-elasticsearch) if you wish to find out more. – ponzao Mar 16 '13 at 20:40