2013-03-16 145 views
0

我嘗試了clojure彈性搜索API ElastischClojure彈性搜索API Elastisch沒有返回結果或文件

我是按照文檔中提供的演示代碼 我收到文件/索引創建的輸出以下代碼

(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) 
) 

我收到輸出的第一個功能爲:

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

從輸出我相信該文檔正在索引

問題是,第二個和第三個函數返回:

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

nil

我在這裏錯過了什麼?

P.S:我是新來的Clojure和彈性搜索

回答

1

esd/get失敗,因爲你映射類型爲:person沒有"person"(關鍵字與字符串)。

您的代碼esd/search有同樣的問題,但除此之外,你應該改變last_namelast-name和下殼"Smith""smith"一切都應該工作。

+0

謝謝!解決了它。想知道爲什麼文檔中的演示代碼將關鍵字作爲字符串? – 2013-03-16 19:42:09

+1

可能是他們的錯誤,或者不同版本的問題以不同的方式表現(我正在使用1.0.2,我可以重複您的問題)。如果您想了解更多信息,他們在GitHub和他們的郵件列表(https://groups.google.com/forum/#!forum/clojure-elasticsearch)上非常有用。 – ponzao 2013-03-16 20:40:39