git.iko.soy/typeable/bloodhound
on master help sign in
Merge branch 'master' of github.com:bitemyapp/bloodhound
81eef68Chris Allen
.gitignore+1
@@ -10,3 +10,4 @@ bloodhound-*-docs/
10bloodhound-*-docs.tar.gz
10bloodhound-*-docs.tar.gz
11bloodhound.iml
11bloodhound.iml
12.idea/
12.idea/
13+.stack-work/
README.md+28−14
@@ -23,13 +23,27 @@ Version compatibility
23
23
24Elasticsearch \>=1.0 && \<2.0 is recommended. Bloodhound mostly works with 0.9.x, but I don't recommend it if you expect everything to work. As of Bloodhound 0.3 all \>=1.0 && \<2.0 versions of Elasticsearch work. Some (or even most?) features will work with versions \>=2.0, but it is not officially supported yet.
24Elasticsearch \>=1.0 && \<2.0 is recommended. Bloodhound mostly works with 0.9.x, but I don't recommend it if you expect everything to work. As of Bloodhound 0.3 all \>=1.0 && \<2.0 versions of Elasticsearch work. Some (or even most?) features will work with versions \>=2.0, but it is not officially supported yet.
25
25
26−Current versions we test against are 1.0.3, 1.1.2, 1.2.3, 1.3.2, and 1.4.0. We also check that GHC 7.6 and 7.8 both build and pass tests. See our [TravisCI](https://travis-ci.org/bitemyapp/bloodhound) to learn more.
26+Current versions we test against are 1.2.4, 1.3.6, 1.4.1, 1.5.2, 1.6.0, and 1.7.2. We also check that GHC 7.6 and 7.8 both build and pass tests. See our [TravisCI](https://travis-ci.org/bitemyapp/bloodhound) to learn more.
27
27
28Stability
28Stability
29---------
29---------
30
30
31Bloodhound is stable for production use. I will strive to avoid breaking API compatibility from here on forward, but dramatic features like a type-safe, fully integrated mapping API may require breaking things in the future.
31Bloodhound is stable for production use. I will strive to avoid breaking API compatibility from here on forward, but dramatic features like a type-safe, fully integrated mapping API may require breaking things in the future.
32
32
33+Testing
34+---------
35+
36+The TravisCI tests are run using [Stack](http://docs.haskellstack.org/en/stable/README.html). You should use Stack instead of `cabal` to build and test Bloodhound to avoid compatibility problems. You will also need to have an ElasticSearch instance running at `localhost:9200` in order to execute some of the tests. See the "Version compatibility" section above for a list of ElasticSearch versions that are officially validated against in TravisCI.
37+
38+Steps to run the tests locally:
39+ 1. Dig through the [past releases] (https://www.elastic.co/downloads/past-releases) section of the ElasticSearch download page and install the desired ElasticSearch versions.
40+ 2. Install [Stack] (http://docs.haskellstack.org/en/stable/README.html#how-to-install)
41+ 3. In your local Bloodhound directory, run `stack setup && stack build`
42+ 4. Start the desired version of ElasticSearch at `localhost:9200`, which should be the default.
43+ 5. Run `stack test` in your local Bloodhound directory.
44+ 6. The unit tests will pass if you re-execute `stack test`, but some of the doctests might fail due to existing data in ElasticSearch. If you want to start with a clean slate, stop your ElasticSearch instance, delete the `data/` folder in the ElasticSearch installation, restart ElasticSearch, and re-run `stack test`.
45+
46+
33Hackage page and Haddock documentation
47Hackage page and Haddock documentation
34======================================
48======================================
35
49
@@ -38,7 +52,7 @@ Hackage page and Haddock documentation
38Elasticsearch Tutorial
52Elasticsearch Tutorial
39======================
53======================
40
54
41−It's not using Bloodhound, but if you need an introduction to or overview of Elasticsearch and how to use it, you can use [this screencast](http://vimeo.com/106463167).
55+It's not using Bloodhound, but if you need an introduction to or overview of Elasticsearch and how to use it, you can use [this screencast](https://vimeo.com/106463167).
42
56
43Examples
57Examples
44========
58========
@@ -820,7 +834,7 @@ let ta' = ta { termCollectMode = Just BreadthFirst }
820let ta'' = TermsAgg ta'
834let ta'' = TermsAgg ta'
821```
835```
822
836
823−For more documentation on how the Terms Aggregation works, see <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html>
837+For more documentation on how the Terms Aggregation works, see <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html>
824
838
825#### Date Histogram Aggregation
839#### Date Histogram Aggregation
826
840
@@ -873,7 +887,7 @@ It is an instance of `BucketAggregation`, and can have nested aggregations in ea
873Buckets can be extracted from an `AggregationResult` using
887Buckets can be extracted from an `AggregationResult` using
874`toDateHistogram name`
888`toDateHistogram name`
875
889
876−For more information on the Date Histogram Aggregation, see: <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html>
890+For more information on the Date Histogram Aggregation, see: <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html>
877
891
878
892
879Contributors
893Contributors
@@ -896,12 +910,12 @@ Possible future functionality
896Span Queries
910Span Queries
897------------
911------------
898
912
899−Beginning here: <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html>
913+Beginning here: <https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html>
900
914
901Function Score Query
915Function Score Query
902--------------------
916--------------------
903
917
904−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html>
918+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html>
905
919
906Node discovery and failover
920Node discovery and failover
907---------------------------
921---------------------------
@@ -921,42 +935,42 @@ Might require making a lucene index on disk with the appropriate format.
921GeoShapeQuery
935GeoShapeQuery
922-------------
936-------------
923
937
924−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html>
938+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html>
925
939
926GeoShapeFilter
940GeoShapeFilter
927--------------
941--------------
928
942
929−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html>
943+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html>
930
944
931Geohash cell filter
945Geohash cell filter
932-------------------
946-------------------
933
947
934−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html>
948+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html>
935
949
936HasChild Filter
950HasChild Filter
937---------------
951---------------
938
952
939−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html>
953+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html>
940
954
941HasParent Filter
955HasParent Filter
942----------------
956----------------
943
957
944−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html>
958+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html>
945
959
946Indices Filter
960Indices Filter
947--------------
961--------------
948
962
949−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html>
963+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html>
950
964
951Query Filter
965Query Filter
952------------
966------------
953
967
954−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html>
968+<https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html>
955
969
956Script based sorting
970Script based sorting
957--------------------
971--------------------
958
972
959−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_script_based_sorting>
973+<https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_script_based_sorting>
960
974
961Collapsing redundantly nested and/or structures
975Collapsing redundantly nested and/or structures
962-----------------------------------------------
976-----------------------------------------------
src/Database/Bloodhound/Types.hs+17−3
@@ -47,6 +47,7 @@ module Database.Bloodhound.Types
47 , mkDateHistogram
47 , mkDateHistogram
48 , mkDocVersion
48 , mkDocVersion
49 , docVersionNumber
49 , docVersionNumber
50+ , toMissing
50 , toTerms
51 , toTerms
51 , toDateHistogram
52 , toDateHistogram
52 , omitNulls
53 , omitNulls
@@ -238,6 +239,7 @@ module Database.Bloodhound.Types
238 , Aggregation(..)
239 , Aggregation(..)
239 , Aggregations
240 , Aggregations
240 , AggregationResults
241 , AggregationResults
242+ , BucketValue(..)
241 , Bucket(..)
243 , Bucket(..)
242 , BucketAggregation(..)
244 , BucketAggregation(..)
243 , TermsAggregation(..)
245 , TermsAggregation(..)
@@ -264,6 +266,7 @@ module Database.Bloodhound.Types
264 , HighlightTag(..)
266 , HighlightTag(..)
265 , HitHighlight
267 , HitHighlight
266
268
269+ , MissingResult(..)
267 , TermsResult(..)
270 , TermsResult(..)
268 , DateHistogramResult(..)
271 , DateHistogramResult(..)
269 , DateRangeResult(..)
272 , DateRangeResult(..)
@@ -1791,6 +1794,8 @@ data BucketValue = TextValue Text
1791 | ScientificValue Scientific
1794 | ScientificValue Scientific
1792 | BoolValue Bool deriving (Show)
1795 | BoolValue Bool deriving (Show)
1793
1796
1797+data MissingResult = MissingResult { missingDocCount :: Int } deriving (Show)
1798+
1794data TermsResult = TermsResult { termKey :: BucketValue
1799data TermsResult = TermsResult { termKey :: BucketValue
1795 , termsDocCount :: Int
1800 , termsDocCount :: Int
1796 , termsAggs :: Maybe AggregationResults } deriving (Show)
1801 , termsAggs :: Maybe AggregationResults } deriving (Show)
@@ -1809,11 +1814,16 @@ data DateRangeResult = DateRangeResult { dateRangeKey :: Text
1809 , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq, Generic, Typeable)
1814 , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq, Generic, Typeable)
1810
1815
1811toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1816toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1812−toTerms t a = M.lookup t a >>= deserialize
1817+toTerms = toAggResult
1813− where deserialize = parseMaybe parseJSON
1814
1818
1815toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1819toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1820+toDateHistogram = toAggResult
1821+
1822+toMissing :: Text -> AggregationResults -> Maybe MissingResult
1823+toMissing = toAggResult
1824+
1825+toAggResult :: (FromJSON a) => Text -> AggregationResults -> Maybe a
1816−toDateHistogram t a = M.lookup t a >>= deserialize
1826+toAggResult t a = M.lookup t a >>= deserialize
1817 where deserialize = parseMaybe parseJSON
1827 where deserialize = parseMaybe parseJSON
1818
1828
1819instance BucketAggregation TermsResult where
1829instance BucketAggregation TermsResult where
@@ -1842,6 +1852,10 @@ instance FromJSON BucketValue where
1842 parseJSON (Bool b) = return $ BoolValue b
1852 parseJSON (Bool b) = return $ BoolValue b
1843 parseJSON _ = mempty
1853 parseJSON _ = mempty
1844
1854
1855+instance FromJSON MissingResult where
1856+ parseJSON = withObject "MissingResult" parse
1857+ where parse v = MissingResult <$> v .: "doc_count"
1858+
1845instance FromJSON TermsResult where
1859instance FromJSON TermsResult where
1846 parseJSON (Object v) = TermsResult <$>
1860 parseJSON (Object v) = TermsResult <$>
1847 v .: "key" <*>
1861 v .: "key" <*>
tests/tests.hs−6
@@ -66,9 +66,6 @@ deleteExampleIndex = deleteIndex testIndex
66
66
67data ServerVersion = ServerVersion Int Int Int deriving (Show, Eq, Ord)
67data ServerVersion = ServerVersion Int Int Int deriving (Show, Eq, Ord)
68
68
69−es14 :: ServerVersion
70−es14 = ServerVersion 1 4 0
71−
72es13 :: ServerVersion
69es13 :: ServerVersion
73es13 = ServerVersion 1 3 0
70es13 = ServerVersion 1 3 0
74
71
@@ -78,9 +75,6 @@ es12 = ServerVersion 1 2 0
78es11 :: ServerVersion
75es11 :: ServerVersion
79es11 = ServerVersion 1 1 0
76es11 = ServerVersion 1 1 0
80
77
81−es10 :: ServerVersion
82−es10 = ServerVersion 1 0 0
83−
84serverBranch :: ServerVersion -> ServerVersion
78serverBranch :: ServerVersion -> ServerVersion
85serverBranch (ServerVersion majorVer minorVer patchVer) =
79serverBranch (ServerVersion majorVer minorVer patchVer) =
86 ServerVersion majorVer minorVer patchVer
80 ServerVersion majorVer minorVer patchVer