@@ -14,6 +14,7 @@ import Data.List (nub)
1414import Data.List.NonEmpty (NonEmpty (..))
1515import qualified Data.List.NonEmpty as NE
1616import qualified Data.Map.Strict as M
17+import Data.Monoid
1718import Data.Text (Text)
1819import qualified Data.Text as T
1920import Data.Time.Calendar (Day (..))
@@ -174,15 +175,16 @@ insertOther = do
174175
175176searchTweet :: Search -> BH IO (Either String Tweet)
176177searchTweet search = do
177− reply <- searchByIndex testIndex search
178− let result = eitherDecode (responseBody reply) :: Either String (SearchResult Tweet)
178+ result <- searchTweets search
179179 let myTweet = fmap (hitSource . head . hits . searchHits) result
180180 return myTweet
181181
182+searchTweets :: Search -> BH IO (Either String (SearchResult Tweet))
183+searchTweets search = eitherDecode . responseBody <$> searchByIndex testIndex search
184+
182185searchExpectNoResults :: Search -> BH IO ()
183186searchExpectNoResults search = do
184− reply <- searchByIndex testIndex search
185− let result = eitherDecode (responseBody reply) :: Either String (SearchResult Tweet)
187+ result <- searchTweets search
186188 let emptyHits = fmap (hits . searchHits) result
187189 liftIO $
188190 emptyHits `shouldBe` Right []
@@ -214,8 +216,7 @@ searchTermsAggHint hints = do
214216
215217searchTweetHighlight :: Search -> BH IO (Either String (Maybe HitHighlight))
216218searchTweetHighlight search = do
217− reply <- searchByIndex testIndex search
218− let result = eitherDecode (responseBody reply) :: Either String (SearchResult Tweet)
219+ result <- searchTweets search
219220 let myHighlight = fmap (hitHighlight . head . hits . searchHits) result
220221 return myHighlight
221222
@@ -435,8 +436,7 @@ main = hspec $ do
435436 let search = Search Nothing
436437 (Just IdentityFilter) (Just [sortSpec]) Nothing Nothing
437438 False (From 0) (Size 10) Nothing
438− reply <- searchByIndex testIndex search
439− let result = eitherDecode (responseBody reply) :: Either String (SearchResult Tweet)
439+ result <- searchTweets search
440440 let myTweet = fmap (hitSource . head . hits . searchHits) result
441441 liftIO $
442442 myTweet `shouldBe` Right otherTweet
@@ -628,6 +628,19 @@ main = hspec $ do
628628 _ <- insertData
629629 searchTermsAggHint [GlobalOrdinals, GlobalOrdinalsHash, GlobalOrdinalsLowCardinality, Map]
630630
631+
632+ it "can execute value_count aggregations" $ withTestEnv $ do
633+ _ <- insertData
634+ _ <- insertOther
635+ let ags = mkAggregations "user_count" (ValueCountAgg (FieldValueCount (FieldName "user"))) <>
636+ mkAggregations "bogus_count" (ValueCountAgg (FieldValueCount (FieldName "bogus")))
637+ let search = mkAggregateSearch Nothing ags
638+ let countPair k n = (k, object ["value" .= Number n])
639+ res <- searchTweets search
640+ liftIO $
641+ fmap aggregations res `shouldBe` Right (Just (M.fromList [ countPair "user_count" 2
642+ , countPair "bogus_count" 0
643+ ]))
631644 -- Interaction of date serialization and date histogram aggregation is broken.
632645 -- it "returns date histogram aggregation results" $ withTestEnv $ do
633646 -- _ <- insertData