Permalink
Browse files

Make sure mapping type is included in the count request URL generation

  • Loading branch information...
1 parent 51a8d74 commit 1dac6da2296f230b1eb6ac0a95150fb40d996430 @michaelklishin michaelklishin committed Oct 20, 2012
View
4 src/clojurewerkz/elastisch/rest/document.clj
@@ -104,9 +104,9 @@
Related ElasticSearch documentation guide: http://www.elasticsearch.org/guide/reference/api/count.html"
([index mapping-type]
- (rest/get (rest/count-url) (join-names index) (join-names mapping-type)))
+ (rest/get (rest/count-url (join-names index) (join-names mapping-type))))
([index mapping-type query]
- (rest/post (rest/count-url) (join-names index) (join-names mapping-type) :body query))
+ (rest/post (rest/count-url (join-names index) (join-names mapping-type)) :body query))
([index mapping-type query & { :as options }]
(rest/post (rest/count-url (join-names index) (join-names mapping-type))
:query-params (select-keys options [:df :analyzer :default_operator])
View
49 test/clojurewerkz/elastisch/rest_api/count_test.clj
@@ -0,0 +1,49 @@
+(ns clojurewerkz.elastisch.rest-api.count-test
+ (:refer-clojure :exclude [replace])
+ (:require [clojurewerkz.elastisch.rest.document :as doc]
+ [clojurewerkz.elastisch.rest.index :as idx]
+ [clojurewerkz.elastisch.query :as q]
+ [clojurewerkz.elastisch.fixtures :as fx])
+ (:use clojure.test clojurewerkz.elastisch.rest.response))
+
+(use-fixtures :each fx/reset-indexes)
+
+;;
+;; count
+;;
+
+(deftest test-count-with-the-default-query
+ (let [index-name "people"
+ index-type "person"]
+ (idx/create index-name :mappings fx/people-mapping)
+ (doc/create index-name index-type fx/person-jack)
+ (doc/create index-name index-type fx/person-joe)
+ (idx/refresh index-name)
+ (are [c r] (is (= c (count-from r)))
+ 2 (doc/count index-name index-type))))
+
+(deftest test-count-with-a-term-query
+ (let [index-name "people"
+ index-type "person"]
+ (idx/create index-name :mappings fx/people-mapping)
+ (doc/create index-name index-type fx/person-jack)
+ (doc/create index-name index-type fx/person-joe)
+ (idx/refresh index-name)
+ (are [c r] (is (= c (count-from r)))
+ 1 (doc/count index-name index-type (q/term :username "esjack"))
+ 1 (doc/count index-name index-type (q/term :username "esjoe"))
+ 0 (doc/count index-name index-type (q/term :username "esmary")))))
+
+
+(deftest test-count-with-mixed-mappings
+ (let [index-name "people"
+ index-type "person"]
+ (idx/create index-name :mappings fx/people-mapping)
+ (doc/create index-name index-type fx/person-jack)
+ (doc/create index-name index-type fx/person-joe)
+ (doc/create index-name "altpeople" fx/person-jack)
+ (idx/refresh index-name)
+ (are [c r] (is (= c (count-from r)))
+ 1 (doc/count index-name index-type (q/term :username "esjack"))
+ 1 (doc/count index-name "altpeople" (q/term :username "esjack"))
+ 0 (doc/count index-name "altpeople" (q/term :username "esjoe")))))
View
23 test/clojurewerkz/elastisch/rest_api/get_test.clj
@@ -1,7 +1,6 @@
(ns clojurewerkz.elastisch.rest-api.get-test
(:refer-clojure :exclude [replace])
(:require [clojurewerkz.elastisch.rest.document :as doc]
- [clojurewerkz.elastisch.rest :as rest]
[clojurewerkz.elastisch.rest.index :as idx]
[clojurewerkz.elastisch.query :as q]
[clojurewerkz.elastisch.fixtures :as fx])
@@ -37,28 +36,6 @@
(doc/put index-name index-type "1" fx/person-jack)
(is (doc/present? index-name index-type "1")))
-;;
-;; count
-;;
-
-(deftest test-count-with-a-term-query
- (idx/create index-name :mappings fx/people-mapping)
- (doc/create index-name index-type fx/person-jack)
- (doc/create index-name index-type fx/person-joe)
- (idx/refresh index-name)
- (are [c r] (is (= c (count-from r)))
- 2 (doc/count index-name index-type)))
-
-(deftest test-count-with-a-term-query
- (idx/create index-name :mappings fx/people-mapping)
- (doc/create index-name index-type fx/person-jack)
- (doc/create index-name index-type fx/person-joe)
- (idx/refresh index-name)
- (are [c r] (is (= c (count-from r)))
- 1 (doc/count index-name index-type (q/term :username "esjack"))
- 1 (doc/count index-name index-type (q/term :username "esjoe"))
- 0 (doc/count index-name index-type (q/term :username "esmary"))))
-
;;

0 comments on commit 1dac6da

Please sign in to comment.