@@ -758,7 +758,8 @@ Since the \`\`\`Aggregations\`\`\` structure is just a Map Text Aggregation, M.i
759#### Extracting aggregations from results
759#### Extracting aggregations from results
761−Aggregations are part of the reply structure of every search, in the form of
761+Aggregations are part of the reply structure of every search, in the
762+form of `Maybe AggregationResults`
763``` {.haskell}
764``` {.haskell}
764-- Lift decode and response body to be in the IO monad.
765-- Lift decode and response body to be in the IO monad.
@@ -774,7 +775,7 @@ terms
774Just (Bucket {buckets = [TermsResult {termKey = "bitemyapp", termsDocCount = 1, termsAggs = Nothing}]})
775Just (Bucket {buckets = [TermsResult {termKey = "bitemyapp", termsDocCount = 1, termsAggs = Nothing}]})
777−Note that bucket aggregation results, such as the TermsResult is a member of the type class :
778+Note that bucket aggregation results, such as the TermsResult is a member of the type class `BucketAggregation`:
779``` {.haskell}
780``` {.haskell}
780class BucketAggregation a where
781class BucketAggregation a where
@@ -783,7 +784,10 @@ class BucketAggregation a where
783 aggs :: a -> Maybe AggregationResults
784 aggs :: a -> Maybe AggregationResults
787+You can use the `aggs` function to get any nested results, if there
786−You can use the function to get any nested results, if there were any. For example, if there were a nested terms aggregation keyed to "age" in a TermsResult named , you would call
788+were any. For example, if there were a nested terms aggregation keyed
789+to "age" in a TermsResult named `termresult` , you would call `aggs
790+termresult >>= toTerms "age"`
788#### Terms Aggregation
792#### Terms Aggregation
@@ -801,7 +805,8 @@ data TermsAggregation
801 termAggs :: Maybe Aggregations}
805 termAggs :: Maybe Aggregations}
804−Term Aggregations have two factory functions, , and , and can be used as follows:
808+Term Aggregations have two factory functions, `mkTermsAggregation`, and
809+`mkTermsScriptAggregation`, and can be used as follows:
806``` {.haskell}
811``` {.haskell}
807let ta = TermsAgg $ mkTermsAggregation "user"
812let ta = TermsAgg $ mkTermsAggregation "user"
@@ -833,13 +838,13 @@ data DateHistogramAggregation
834The Date Histogram Aggregation works much the same as the Terms Aggregation.
839The Date Histogram Aggregation works much the same as the Terms Aggregation.
836−Relevant functions include , and
841+Relevant functions include `mkDateHistogram`, and `toDateHistogram`
838``` {.haskell}
843``` {.haskell}
839let dh = DateHistogramAgg (mkDateHistogram (FieldName "postDate") Minute)
844let dh = DateHistogramAgg (mkDateHistogram (FieldName "postDate") Minute)
842−Date histograms also accept a :
847+Date histograms also accept a `FractionalInterval`:
844``` {.haskell}
849``` {.haskell}
845FractionalInterval :: Float -> TimeInterval -> Interval
850FractionalInterval :: Float -> TimeInterval -> Interval
@@ -853,7 +858,7 @@ It can be used as follows:
853let dh = DateHistogramAgg (mkDateHistogram (FieldName "postDate") (FractionalInterval 1.5 Minutes))
858let dh = DateHistogramAgg (mkDateHistogram (FieldName "postDate") (FractionalInterval 1.5 Minutes))
856−The is defined as:
861+The `DateHistogramResult` is defined as:
858``` {.haskell}
863``` {.haskell}
859data DateHistogramResult
864data DateHistogramResult
@@ -863,9 +868,10 @@ data DateHistogramResult
863 dateHistogramAggs :: Maybe AggregationResults}
868 dateHistogramAggs :: Maybe AggregationResults}
866−It is an instance of , and can have nested aggregations in each bucket.
871+It is an instance of `BucketAggregation`, and can have nested aggregations in each bucket.
868−Buckets can be extracted from a using
873+Buckets can be extracted from an `AggregationResult` using
874+`toDateHistogram name`
870For more information on the Date Histogram Aggregation, see: <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html>
876For more information on the Date Histogram Aggregation, see: <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html>