Requiring a file and sending commands to the repl have different behaviors

7 views
Skip to first unread message

Brian Marick

unread,
Mar 10, 2014, 6:17:51 PM3/10/14
to clojure-el...@googlegroups.com
I have this namespace (gist here: https://gist.github.com/marick/9475532)

(ns getset.services.derp)
(require '[clojurewerkz.elastisch.rest :as esr]
'[clojurewerkz.elastisch.rest.index :as index]
'[clojurewerkz.elastisch.rest.document :as document])

(esr/connect! "http://localhost:9200")

(when (index/exists? "myapp2_development") (prn (index/delete "myapp2_development")))
(prn 1 (index/create "myapp2_development" :mappings {"person" {:properties {:age {:type "integer"}}}}))
(prn 2 (document/create "myapp2_development" "person" {:age 55}))
(prn 3 (document/search "myapp2_development" "person" :query {"term" {"age" 55}}))

If I `require` the file from the repl, I get this:

user=> (require 'getset.services.derp)
{:ok true, :acknowledged true}
1 {:ok true, :acknowledged true}
2 {:ok true, :_index "myapp2_development", :_type "person", :_id "CNPjOEtdSF2BEj1YqQw6_w", :_version 1}
3 {:took 1, :timed_out false, :_shards {:total 5, :successful 5, :failed 0}, :hits {:total 0, :max_score nil, :hits []}}

Note there are no hits. If I paste the same lines into the repl (except for the `ns` form, and after a fresh start), I get this:

user=> (esr/connect! "http://localhost:9200")
#clojurewerkz.elastisch.rest.ElasticSearchEndpoint{:uri "http://localhost:9200", :version "0.90.11"}
user=> (when (index/exists? "myapp2_development") (prn (index/delete "myapp2_development")))
{:ok true, :acknowledged true}
user=> (prn 1 (index/create "myapp2_development" :mappings {"person" {:properties {:age {:type "integer"}}}}))
1 {:ok true, :acknowledged true}
user=> (prn 2 (document/create "myapp2_development" "person" {:age 55}))
2 {:ok true, :_index "myapp2_development", :_type "person", :_id "5dKWlBG7QVK1btqdctBuHw", :_version 1}
user=> (prn 3 (document/search "myapp2_development" "person" :query {"term" {"age" 55}}))
3 {:took 1, :timed_out false, :_shards {:total 5, :successful 5, :failed 0}, :hits {:total 1, :max_score 1.0, :hits [{:_index "myapp2_development", :_type "person", :_id "5dKWlBG7QVK1btqdctBuHw", :_score 1.0, :_source {:age 55}}]}}

In this case, I get the hit, as expected.

How is this possible?

I'm using elastisch "1.5.0-beta3" against ES 0.90.11


----
Let us go then, TMI,
When their profiles are spread out against the sky,
Like a patient etherized upon a table.

The Love Song of J. Random Profile

Brian Marick

unread,
Mar 10, 2014, 6:21:09 PM3/10/14
to clojure-el...@googlegroups.com
Never mind. It is because indexing is not immediate and the `require` executes forms too fast. 
Reply all
Reply to author
Forward
0 new messages