{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Database.Bloodhound.Internal.Aggregation where
import Bloodhound.Import
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.KeyMap as X
import qualified Data.Map.Strict as M
import qualified Data.Text as T
import Database.Bloodhound.Internal.Client
import Database.Bloodhound.Internal.Highlight (HitHighlight)
import Database.Bloodhound.Internal.Newtypes
import Database.Bloodhound.Internal.Query
import Database.Bloodhound.Internal.Sort
type Aggregations = M.Map Key Aggregation
emptyAggregations :: Aggregations
emptyAggregations :: Aggregations
emptyAggregations = Aggregations
forall k a. Map k a
M.empty
mkAggregations :: Key -> Aggregation -> Aggregations
mkAggregations :: Key -> Aggregation -> Aggregations
mkAggregations Key
name Aggregation
aggregation = Key -> Aggregation -> Aggregations -> Aggregations
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Key
name Aggregation
aggregation Aggregations
emptyAggregations
data Aggregation = TermsAgg TermsAggregation
| CardinalityAgg CardinalityAggregation
| DateHistogramAgg DateHistogramAggregation
| ValueCountAgg ValueCountAggregation
| FilterAgg FilterAggregation
| DateRangeAgg DateRangeAggregation
| MissingAgg MissingAggregation
| TopHitsAgg TopHitsAggregation
| StatsAgg StatisticsAggregation
deriving (Aggregation -> Aggregation -> Bool
(Aggregation -> Aggregation -> Bool)
-> (Aggregation -> Aggregation -> Bool) -> Eq Aggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Aggregation -> Aggregation -> Bool
$c/= :: Aggregation -> Aggregation -> Bool
== :: Aggregation -> Aggregation -> Bool
$c== :: Aggregation -> Aggregation -> Bool
Eq, Int -> Aggregation -> ShowS
[Aggregation] -> ShowS
Aggregation -> String
(Int -> Aggregation -> ShowS)
-> (Aggregation -> String)
-> ([Aggregation] -> ShowS)
-> Show Aggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Aggregation] -> ShowS
$cshowList :: [Aggregation] -> ShowS
show :: Aggregation -> String
$cshow :: Aggregation -> String
showsPrec :: Int -> Aggregation -> ShowS
$cshowsPrec :: Int -> Aggregation -> ShowS
Show)
instance ToJSON Aggregation where
toJSON :: Aggregation -> Value
toJSON (TermsAgg (TermsAggregation Either Text Text
term Maybe TermInclusion
include Maybe TermInclusion
exclude Maybe TermOrder
order Maybe Int
minDocCount Maybe Int
size Maybe Int
shardSize Maybe CollectionMode
collectMode Maybe ExecutionHint
executionHint Maybe Aggregations
termAggs)) =
[(Key, Value)] -> Value
omitNulls [Key
"terms" Key -> Value -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [(Key, Value)] -> Value
omitNulls [ Either Text Text -> (Key, Value)
forall p v v. (KeyValue p, ToJSON v, ToJSON v) => Either v v -> p
toJSON' Either Text Text
term,
Key
"include" Key -> Maybe TermInclusion -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe TermInclusion
include,
Key
"exclude" Key -> Maybe TermInclusion -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe TermInclusion
exclude,
Key
"order" Key -> Maybe TermOrder -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe TermOrder
order,
Key
"min_doc_count" Key -> Maybe Int -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
minDocCount,
Key
"size" Key -> Maybe Int -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
size,
Key
"shard_size" Key -> Maybe Int -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
shardSize,
Key
"collect_mode" Key -> Maybe CollectionMode -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe CollectionMode
collectMode,
Key
"execution_hint" Key -> Maybe ExecutionHint -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe ExecutionHint
executionHint
],
Key
"aggs" Key -> Maybe Aggregations -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Aggregations
termAggs ]
where
toJSON' :: Either v v -> p
toJSON' Either v v
x = case Either v v
x of { Left v
y -> Key
"field" Key -> v -> p
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= v
y; Right v
y -> Key
"script" Key -> v -> p
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= v
y }
toJSON (CardinalityAgg (CardinalityAggregation FieldName
field Maybe Int
precisionThreshold)) =
[(Key, Value)] -> Value
object [Key
"cardinality" Key -> Value -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [(Key, Value)] -> Value
omitNulls [ Key
"field" Key -> FieldName -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FieldName
field,
Key
"precisionThreshold" Key -> Maybe Int -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Int
precisionThreshold
]
]
toJSON (DateHistogramAgg
(DateHistogramAggregation FieldName
field Interval
interval Maybe Text
format
Maybe Text
preZone Maybe Text
postZone Maybe Text
preOffset Maybe Text
postOffset Maybe Aggregations
dateHistoAggs)) =
[(Key, Value)] -> Value
omitNulls [Key
"date_histogram" Key -> Value -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [(Key, Value)] -> Value
omitNulls [ Key
"field" Key -> FieldName -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FieldName
field,
Key
"interval" Key -> Interval -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Interval
interval,
Key
"format" Key -> Maybe Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
format,
Key
"pre_zone" Key -> Maybe Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
preZone,
Key
"post_zone" Key -> Maybe Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
postZone,
Key
"pre_offset" Key -> Maybe Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
preOffset,
Key
"post_offset" Key -> Maybe Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
postOffset
],
Key
"aggs" Key -> Maybe Aggregations -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Aggregations
dateHistoAggs ]
toJSON (ValueCountAgg ValueCountAggregation
a) = [(Key, Value)] -> Value
object [Key
"value_count" Key -> Value -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Value
v]
where v :: Value
v = case ValueCountAggregation
a of
(FieldValueCount (FieldName Text
n)) ->
[(Key, Value)] -> Value
object [Key
"field" Key -> Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
n]
(ScriptValueCount Script
s) ->
[(Key, Value)] -> Value
object [Key
"script" Key -> Script -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Script
s]
toJSON (FilterAgg (FilterAggregation Filter
filt Maybe Aggregations
ags)) =
[(Key, Value)] -> Value
omitNulls [ Key
"filter" Key -> Filter -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Filter
filt
, Key
"aggs" Key -> Maybe Aggregations -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Aggregations
ags]
toJSON (DateRangeAgg DateRangeAggregation
a) = [(Key, Value)] -> Value
object [ Key
"date_range" Key -> DateRangeAggregation -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DateRangeAggregation
a
]
toJSON (MissingAgg (MissingAggregation{Text
maField :: MissingAggregation -> Text
maField :: Text
..})) =
[(Key, Value)] -> Value
object [Key
"missing" Key -> Value -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [(Key, Value)] -> Value
object [Key
"field" Key -> Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
maField]]
toJSON (TopHitsAgg (TopHitsAggregation Maybe From
mfrom Maybe Size
msize Maybe Sort
msort)) =
[(Key, Value)] -> Value
omitNulls [Key
"top_hits" Key -> Value -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [(Key, Value)] -> Value
omitNulls [ Key
"size" Key -> Maybe Size -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Size
msize
, Key
"from" Key -> Maybe From -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe From
mfrom
, Key
"sort" Key -> Maybe Sort -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Sort
msort
]
]
toJSON (StatsAgg (StatisticsAggregation StatsType
typ FieldName
field)) =
[(Key, Value)] -> Value
object [Key
stType Key -> Value -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [(Key, Value)] -> Value
omitNulls [ Key
"field" Key -> FieldName -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FieldName
field ]]
where
stType :: Key
stType | StatsType
typ StatsType -> StatsType -> Bool
forall a. Eq a => a -> a -> Bool
== StatsType
Basic = Key
"stats"
| Bool
otherwise = Key
"extended_stats"
data TopHitsAggregation = TopHitsAggregation
{ TopHitsAggregation -> Maybe From
taFrom :: Maybe From
, TopHitsAggregation -> Maybe Size
taSize :: Maybe Size
, TopHitsAggregation -> Maybe Sort
taSort :: Maybe Sort
} deriving (TopHitsAggregation -> TopHitsAggregation -> Bool
(TopHitsAggregation -> TopHitsAggregation -> Bool)
-> (TopHitsAggregation -> TopHitsAggregation -> Bool)
-> Eq TopHitsAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopHitsAggregation -> TopHitsAggregation -> Bool
$c/= :: TopHitsAggregation -> TopHitsAggregation -> Bool
== :: TopHitsAggregation -> TopHitsAggregation -> Bool
$c== :: TopHitsAggregation -> TopHitsAggregation -> Bool
Eq, Int -> TopHitsAggregation -> ShowS
[TopHitsAggregation] -> ShowS
TopHitsAggregation -> String
(Int -> TopHitsAggregation -> ShowS)
-> (TopHitsAggregation -> String)
-> ([TopHitsAggregation] -> ShowS)
-> Show TopHitsAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopHitsAggregation] -> ShowS
$cshowList :: [TopHitsAggregation] -> ShowS
show :: TopHitsAggregation -> String
$cshow :: TopHitsAggregation -> String
showsPrec :: Int -> TopHitsAggregation -> ShowS
$cshowsPrec :: Int -> TopHitsAggregation -> ShowS
Show)
data MissingAggregation = MissingAggregation
{ MissingAggregation -> Text
maField :: Text
} deriving (MissingAggregation -> MissingAggregation -> Bool
(MissingAggregation -> MissingAggregation -> Bool)
-> (MissingAggregation -> MissingAggregation -> Bool)
-> Eq MissingAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MissingAggregation -> MissingAggregation -> Bool
$c/= :: MissingAggregation -> MissingAggregation -> Bool
== :: MissingAggregation -> MissingAggregation -> Bool
$c== :: MissingAggregation -> MissingAggregation -> Bool
Eq, Int -> MissingAggregation -> ShowS
[MissingAggregation] -> ShowS
MissingAggregation -> String
(Int -> MissingAggregation -> ShowS)
-> (MissingAggregation -> String)
-> ([MissingAggregation] -> ShowS)
-> Show MissingAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MissingAggregation] -> ShowS
$cshowList :: [MissingAggregation] -> ShowS
show :: MissingAggregation -> String
$cshow :: MissingAggregation -> String
showsPrec :: Int -> MissingAggregation -> ShowS
$cshowsPrec :: Int -> MissingAggregation -> ShowS
Show)
data TermsAggregation = TermsAggregation
{ TermsAggregation -> Either Text Text
term :: Either Text Text
, TermsAggregation -> Maybe TermInclusion
termInclude :: Maybe TermInclusion
, TermsAggregation -> Maybe TermInclusion
termExclude :: Maybe TermInclusion
, TermsAggregation -> Maybe TermOrder
termOrder :: Maybe TermOrder
, TermsAggregation -> Maybe Int
termMinDocCount :: Maybe Int
, TermsAggregation -> Maybe Int
termSize :: Maybe Int
, TermsAggregation -> Maybe Int
termShardSize :: Maybe Int
, TermsAggregation -> Maybe CollectionMode
termCollectMode :: Maybe CollectionMode
, TermsAggregation -> Maybe ExecutionHint
termExecutionHint :: Maybe ExecutionHint
, TermsAggregation -> Maybe Aggregations
termAggs :: Maybe Aggregations
} deriving (TermsAggregation -> TermsAggregation -> Bool
(TermsAggregation -> TermsAggregation -> Bool)
-> (TermsAggregation -> TermsAggregation -> Bool)
-> Eq TermsAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TermsAggregation -> TermsAggregation -> Bool
$c/= :: TermsAggregation -> TermsAggregation -> Bool
== :: TermsAggregation -> TermsAggregation -> Bool
$c== :: TermsAggregation -> TermsAggregation -> Bool
Eq, Int -> TermsAggregation -> ShowS
[TermsAggregation] -> ShowS
TermsAggregation -> String
(Int -> TermsAggregation -> ShowS)
-> (TermsAggregation -> String)
-> ([TermsAggregation] -> ShowS)
-> Show TermsAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TermsAggregation] -> ShowS
$cshowList :: [TermsAggregation] -> ShowS
show :: TermsAggregation -> String
$cshow :: TermsAggregation -> String
showsPrec :: Int -> TermsAggregation -> ShowS
$cshowsPrec :: Int -> TermsAggregation -> ShowS
Show)
data CardinalityAggregation = CardinalityAggregation
{ CardinalityAggregation -> FieldName
cardinalityField :: FieldName,
CardinalityAggregation -> Maybe Int
precisionThreshold :: Maybe Int
} deriving (CardinalityAggregation -> CardinalityAggregation -> Bool
(CardinalityAggregation -> CardinalityAggregation -> Bool)
-> (CardinalityAggregation -> CardinalityAggregation -> Bool)
-> Eq CardinalityAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CardinalityAggregation -> CardinalityAggregation -> Bool
$c/= :: CardinalityAggregation -> CardinalityAggregation -> Bool
== :: CardinalityAggregation -> CardinalityAggregation -> Bool
$c== :: CardinalityAggregation -> CardinalityAggregation -> Bool
Eq, Int -> CardinalityAggregation -> ShowS
[CardinalityAggregation] -> ShowS
CardinalityAggregation -> String
(Int -> CardinalityAggregation -> ShowS)
-> (CardinalityAggregation -> String)
-> ([CardinalityAggregation] -> ShowS)
-> Show CardinalityAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CardinalityAggregation] -> ShowS
$cshowList :: [CardinalityAggregation] -> ShowS
show :: CardinalityAggregation -> String
$cshow :: CardinalityAggregation -> String
showsPrec :: Int -> CardinalityAggregation -> ShowS
$cshowsPrec :: Int -> CardinalityAggregation -> ShowS
Show)
data DateHistogramAggregation = DateHistogramAggregation
{ DateHistogramAggregation -> FieldName
dateField :: FieldName
, DateHistogramAggregation -> Interval
dateInterval :: Interval
, DateHistogramAggregation -> Maybe Text
dateFormat :: Maybe Text
, DateHistogramAggregation -> Maybe Text
datePreZone :: Maybe Text
, DateHistogramAggregation -> Maybe Text
datePostZone :: Maybe Text
, DateHistogramAggregation -> Maybe Text
datePreOffset :: Maybe Text
, DateHistogramAggregation -> Maybe Text
datePostOffset :: Maybe Text
, DateHistogramAggregation -> Maybe Aggregations
dateAggs :: Maybe Aggregations
} deriving (DateHistogramAggregation -> DateHistogramAggregation -> Bool
(DateHistogramAggregation -> DateHistogramAggregation -> Bool)
-> (DateHistogramAggregation -> DateHistogramAggregation -> Bool)
-> Eq DateHistogramAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateHistogramAggregation -> DateHistogramAggregation -> Bool
$c/= :: DateHistogramAggregation -> DateHistogramAggregation -> Bool
== :: DateHistogramAggregation -> DateHistogramAggregation -> Bool
$c== :: DateHistogramAggregation -> DateHistogramAggregation -> Bool
Eq, Int -> DateHistogramAggregation -> ShowS
[DateHistogramAggregation] -> ShowS
DateHistogramAggregation -> String
(Int -> DateHistogramAggregation -> ShowS)
-> (DateHistogramAggregation -> String)
-> ([DateHistogramAggregation] -> ShowS)
-> Show DateHistogramAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateHistogramAggregation] -> ShowS
$cshowList :: [DateHistogramAggregation] -> ShowS
show :: DateHistogramAggregation -> String
$cshow :: DateHistogramAggregation -> String
showsPrec :: Int -> DateHistogramAggregation -> ShowS
$cshowsPrec :: Int -> DateHistogramAggregation -> ShowS
Show)
data DateRangeAggregation = DateRangeAggregation
{ DateRangeAggregation -> FieldName
draField :: FieldName
, DateRangeAggregation -> Maybe Text
draFormat :: Maybe Text
, DateRangeAggregation -> NonEmpty DateRangeAggRange
draRanges :: NonEmpty DateRangeAggRange
} deriving (DateRangeAggregation -> DateRangeAggregation -> Bool
(DateRangeAggregation -> DateRangeAggregation -> Bool)
-> (DateRangeAggregation -> DateRangeAggregation -> Bool)
-> Eq DateRangeAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateRangeAggregation -> DateRangeAggregation -> Bool
$c/= :: DateRangeAggregation -> DateRangeAggregation -> Bool
== :: DateRangeAggregation -> DateRangeAggregation -> Bool
$c== :: DateRangeAggregation -> DateRangeAggregation -> Bool
Eq, Int -> DateRangeAggregation -> ShowS
[DateRangeAggregation] -> ShowS
DateRangeAggregation -> String
(Int -> DateRangeAggregation -> ShowS)
-> (DateRangeAggregation -> String)
-> ([DateRangeAggregation] -> ShowS)
-> Show DateRangeAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateRangeAggregation] -> ShowS
$cshowList :: [DateRangeAggregation] -> ShowS
show :: DateRangeAggregation -> String
$cshow :: DateRangeAggregation -> String
showsPrec :: Int -> DateRangeAggregation -> ShowS
$cshowsPrec :: Int -> DateRangeAggregation -> ShowS
Show)
instance ToJSON DateRangeAggregation where
toJSON :: DateRangeAggregation -> Value
toJSON DateRangeAggregation {Maybe Text
NonEmpty DateRangeAggRange
FieldName
draRanges :: NonEmpty DateRangeAggRange
draFormat :: Maybe Text
draField :: FieldName
draRanges :: DateRangeAggregation -> NonEmpty DateRangeAggRange
draFormat :: DateRangeAggregation -> Maybe Text
draField :: DateRangeAggregation -> FieldName
..} =
[(Key, Value)] -> Value
omitNulls [ Key
"field" Key -> FieldName -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= FieldName
draField
, Key
"format" Key -> Maybe Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Text
draFormat
, Key
"ranges" Key -> [DateRangeAggRange] -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= NonEmpty DateRangeAggRange -> [DateRangeAggRange]
forall a. NonEmpty a -> [a]
toList NonEmpty DateRangeAggRange
draRanges
]
data DateRangeAggRange =
DateRangeFrom DateMathExpr
| DateRangeTo DateMathExpr
| DateRangeFromAndTo DateMathExpr DateMathExpr
deriving (DateRangeAggRange -> DateRangeAggRange -> Bool
(DateRangeAggRange -> DateRangeAggRange -> Bool)
-> (DateRangeAggRange -> DateRangeAggRange -> Bool)
-> Eq DateRangeAggRange
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateRangeAggRange -> DateRangeAggRange -> Bool
$c/= :: DateRangeAggRange -> DateRangeAggRange -> Bool
== :: DateRangeAggRange -> DateRangeAggRange -> Bool
$c== :: DateRangeAggRange -> DateRangeAggRange -> Bool
Eq, Int -> DateRangeAggRange -> ShowS
[DateRangeAggRange] -> ShowS
DateRangeAggRange -> String
(Int -> DateRangeAggRange -> ShowS)
-> (DateRangeAggRange -> String)
-> ([DateRangeAggRange] -> ShowS)
-> Show DateRangeAggRange
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateRangeAggRange] -> ShowS
$cshowList :: [DateRangeAggRange] -> ShowS
show :: DateRangeAggRange -> String
$cshow :: DateRangeAggRange -> String
showsPrec :: Int -> DateRangeAggRange -> ShowS
$cshowsPrec :: Int -> DateRangeAggRange -> ShowS
Show)
instance ToJSON DateRangeAggRange where
toJSON :: DateRangeAggRange -> Value
toJSON (DateRangeFrom DateMathExpr
e) = [(Key, Value)] -> Value
object [ Key
"from" Key -> DateMathExpr -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DateMathExpr
e ]
toJSON (DateRangeTo DateMathExpr
e) = [(Key, Value)] -> Value
object [ Key
"to" Key -> DateMathExpr -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DateMathExpr
e ]
toJSON (DateRangeFromAndTo DateMathExpr
f DateMathExpr
t) = [(Key, Value)] -> Value
object [ Key
"from" Key -> DateMathExpr -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DateMathExpr
f, Key
"to" Key -> DateMathExpr -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= DateMathExpr
t ]
data ValueCountAggregation =
FieldValueCount FieldName
| ScriptValueCount Script
deriving (ValueCountAggregation -> ValueCountAggregation -> Bool
(ValueCountAggregation -> ValueCountAggregation -> Bool)
-> (ValueCountAggregation -> ValueCountAggregation -> Bool)
-> Eq ValueCountAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ValueCountAggregation -> ValueCountAggregation -> Bool
$c/= :: ValueCountAggregation -> ValueCountAggregation -> Bool
== :: ValueCountAggregation -> ValueCountAggregation -> Bool
$c== :: ValueCountAggregation -> ValueCountAggregation -> Bool
Eq, Int -> ValueCountAggregation -> ShowS
[ValueCountAggregation] -> ShowS
ValueCountAggregation -> String
(Int -> ValueCountAggregation -> ShowS)
-> (ValueCountAggregation -> String)
-> ([ValueCountAggregation] -> ShowS)
-> Show ValueCountAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ValueCountAggregation] -> ShowS
$cshowList :: [ValueCountAggregation] -> ShowS
show :: ValueCountAggregation -> String
$cshow :: ValueCountAggregation -> String
showsPrec :: Int -> ValueCountAggregation -> ShowS
$cshowsPrec :: Int -> ValueCountAggregation -> ShowS
Show)
data FilterAggregation = FilterAggregation
{ FilterAggregation -> Filter
faFilter :: Filter
, FilterAggregation -> Maybe Aggregations
faAggs :: Maybe Aggregations }
deriving (FilterAggregation -> FilterAggregation -> Bool
(FilterAggregation -> FilterAggregation -> Bool)
-> (FilterAggregation -> FilterAggregation -> Bool)
-> Eq FilterAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FilterAggregation -> FilterAggregation -> Bool
$c/= :: FilterAggregation -> FilterAggregation -> Bool
== :: FilterAggregation -> FilterAggregation -> Bool
$c== :: FilterAggregation -> FilterAggregation -> Bool
Eq, Int -> FilterAggregation -> ShowS
[FilterAggregation] -> ShowS
FilterAggregation -> String
(Int -> FilterAggregation -> ShowS)
-> (FilterAggregation -> String)
-> ([FilterAggregation] -> ShowS)
-> Show FilterAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FilterAggregation] -> ShowS
$cshowList :: [FilterAggregation] -> ShowS
show :: FilterAggregation -> String
$cshow :: FilterAggregation -> String
showsPrec :: Int -> FilterAggregation -> ShowS
$cshowsPrec :: Int -> FilterAggregation -> ShowS
Show)
data StatisticsAggregation = StatisticsAggregation
{ StatisticsAggregation -> StatsType
statsType :: StatsType
, StatisticsAggregation -> FieldName
statsField :: FieldName }
deriving (StatisticsAggregation -> StatisticsAggregation -> Bool
(StatisticsAggregation -> StatisticsAggregation -> Bool)
-> (StatisticsAggregation -> StatisticsAggregation -> Bool)
-> Eq StatisticsAggregation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatisticsAggregation -> StatisticsAggregation -> Bool
$c/= :: StatisticsAggregation -> StatisticsAggregation -> Bool
== :: StatisticsAggregation -> StatisticsAggregation -> Bool
$c== :: StatisticsAggregation -> StatisticsAggregation -> Bool
Eq, Int -> StatisticsAggregation -> ShowS
[StatisticsAggregation] -> ShowS
StatisticsAggregation -> String
(Int -> StatisticsAggregation -> ShowS)
-> (StatisticsAggregation -> String)
-> ([StatisticsAggregation] -> ShowS)
-> Show StatisticsAggregation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StatisticsAggregation] -> ShowS
$cshowList :: [StatisticsAggregation] -> ShowS
show :: StatisticsAggregation -> String
$cshow :: StatisticsAggregation -> String
showsPrec :: Int -> StatisticsAggregation -> ShowS
$cshowsPrec :: Int -> StatisticsAggregation -> ShowS
Show)
data StatsType
= Basic
| Extended
deriving (StatsType -> StatsType -> Bool
(StatsType -> StatsType -> Bool)
-> (StatsType -> StatsType -> Bool) -> Eq StatsType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatsType -> StatsType -> Bool
$c/= :: StatsType -> StatsType -> Bool
== :: StatsType -> StatsType -> Bool
$c== :: StatsType -> StatsType -> Bool
Eq, Int -> StatsType -> ShowS
[StatsType] -> ShowS
StatsType -> String
(Int -> StatsType -> ShowS)
-> (StatsType -> String)
-> ([StatsType] -> ShowS)
-> Show StatsType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StatsType] -> ShowS
$cshowList :: [StatsType] -> ShowS
show :: StatsType -> String
$cshow :: StatsType -> String
showsPrec :: Int -> StatsType -> ShowS
$cshowsPrec :: Int -> StatsType -> ShowS
Show)
mkTermsAggregation :: Text -> TermsAggregation
mkTermsAggregation :: Text -> TermsAggregation
mkTermsAggregation Text
t =
Either Text Text
-> Maybe TermInclusion
-> Maybe TermInclusion
-> Maybe TermOrder
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe CollectionMode
-> Maybe ExecutionHint
-> Maybe Aggregations
-> TermsAggregation
TermsAggregation (Text -> Either Text Text
forall a b. a -> Either a b
Left Text
t)
Maybe TermInclusion
forall a. Maybe a
Nothing Maybe TermInclusion
forall a. Maybe a
Nothing Maybe TermOrder
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe CollectionMode
forall a. Maybe a
Nothing Maybe ExecutionHint
forall a. Maybe a
Nothing Maybe Aggregations
forall a. Maybe a
Nothing
mkTermsScriptAggregation :: Text -> TermsAggregation
mkTermsScriptAggregation :: Text -> TermsAggregation
mkTermsScriptAggregation Text
t = Either Text Text
-> Maybe TermInclusion
-> Maybe TermInclusion
-> Maybe TermOrder
-> Maybe Int
-> Maybe Int
-> Maybe Int
-> Maybe CollectionMode
-> Maybe ExecutionHint
-> Maybe Aggregations
-> TermsAggregation
TermsAggregation (Text -> Either Text Text
forall a b. b -> Either a b
Right Text
t) Maybe TermInclusion
forall a. Maybe a
Nothing Maybe TermInclusion
forall a. Maybe a
Nothing Maybe TermOrder
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe Int
forall a. Maybe a
Nothing Maybe CollectionMode
forall a. Maybe a
Nothing Maybe ExecutionHint
forall a. Maybe a
Nothing Maybe Aggregations
forall a. Maybe a
Nothing
mkDateHistogram :: FieldName -> Interval -> DateHistogramAggregation
mkDateHistogram :: FieldName -> Interval -> DateHistogramAggregation
mkDateHistogram FieldName
t Interval
i = FieldName
-> Interval
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Aggregations
-> DateHistogramAggregation
DateHistogramAggregation FieldName
t Interval
i Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Text
forall a. Maybe a
Nothing Maybe Aggregations
forall a. Maybe a
Nothing
mkCardinalityAggregation :: FieldName -> CardinalityAggregation
mkCardinalityAggregation :: FieldName -> CardinalityAggregation
mkCardinalityAggregation FieldName
t = FieldName -> Maybe Int -> CardinalityAggregation
CardinalityAggregation FieldName
t Maybe Int
forall a. Maybe a
Nothing
mkStatsAggregation :: FieldName -> StatisticsAggregation
mkStatsAggregation :: FieldName -> StatisticsAggregation
mkStatsAggregation = StatsType -> FieldName -> StatisticsAggregation
StatisticsAggregation StatsType
Basic
mkExtendedStatsAggregation :: FieldName -> StatisticsAggregation
mkExtendedStatsAggregation :: FieldName -> StatisticsAggregation
mkExtendedStatsAggregation = StatsType -> FieldName -> StatisticsAggregation
StatisticsAggregation StatsType
Extended
type AggregationResults = M.Map Key Value
class BucketAggregation a where
key :: a -> BucketValue
docCount :: a -> Int
aggs :: a -> Maybe AggregationResults
data Bucket a = Bucket
{ Bucket a -> [a]
buckets :: [a]
} deriving (ReadPrec [Bucket a]
ReadPrec (Bucket a)
Int -> ReadS (Bucket a)
ReadS [Bucket a]
(Int -> ReadS (Bucket a))
-> ReadS [Bucket a]
-> ReadPrec (Bucket a)
-> ReadPrec [Bucket a]
-> Read (Bucket a)
forall a. Read a => ReadPrec [Bucket a]
forall a. Read a => ReadPrec (Bucket a)
forall a. Read a => Int -> ReadS (Bucket a)
forall a. Read a => ReadS [Bucket a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Bucket a]
$creadListPrec :: forall a. Read a => ReadPrec [Bucket a]
readPrec :: ReadPrec (Bucket a)
$creadPrec :: forall a. Read a => ReadPrec (Bucket a)
readList :: ReadS [Bucket a]
$creadList :: forall a. Read a => ReadS [Bucket a]
readsPrec :: Int -> ReadS (Bucket a)
$creadsPrec :: forall a. Read a => Int -> ReadS (Bucket a)
Read, Int -> Bucket a -> ShowS
[Bucket a] -> ShowS
Bucket a -> String
(Int -> Bucket a -> ShowS)
-> (Bucket a -> String) -> ([Bucket a] -> ShowS) -> Show (Bucket a)
forall a. Show a => Int -> Bucket a -> ShowS
forall a. Show a => [Bucket a] -> ShowS
forall a. Show a => Bucket a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Bucket a] -> ShowS
$cshowList :: forall a. Show a => [Bucket a] -> ShowS
show :: Bucket a -> String
$cshow :: forall a. Show a => Bucket a -> String
showsPrec :: Int -> Bucket a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Bucket a -> ShowS
Show)
instance (FromJSON a) => FromJSON (Bucket a) where
parseJSON :: Value -> Parser (Bucket a)
parseJSON (Object Object
v) = [a] -> Bucket a
forall a. [a] -> Bucket a
Bucket ([a] -> Bucket a) -> Parser [a] -> Parser (Bucket a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Object
v Object -> Key -> Parser [a]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"buckets"
parseJSON Value
_ = Parser (Bucket a)
forall a. Monoid a => a
mempty
data BucketValue = TextValue Text
| ScientificValue Scientific
| BoolValue Bool deriving (ReadPrec [BucketValue]
ReadPrec BucketValue
Int -> ReadS BucketValue
ReadS [BucketValue]
(Int -> ReadS BucketValue)
-> ReadS [BucketValue]
-> ReadPrec BucketValue
-> ReadPrec [BucketValue]
-> Read BucketValue
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BucketValue]
$creadListPrec :: ReadPrec [BucketValue]
readPrec :: ReadPrec BucketValue
$creadPrec :: ReadPrec BucketValue
readList :: ReadS [BucketValue]
$creadList :: ReadS [BucketValue]
readsPrec :: Int -> ReadS BucketValue
$creadsPrec :: Int -> ReadS BucketValue
Read, Int -> BucketValue -> ShowS
[BucketValue] -> ShowS
BucketValue -> String
(Int -> BucketValue -> ShowS)
-> (BucketValue -> String)
-> ([BucketValue] -> ShowS)
-> Show BucketValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BucketValue] -> ShowS
$cshowList :: [BucketValue] -> ShowS
show :: BucketValue -> String
$cshow :: BucketValue -> String
showsPrec :: Int -> BucketValue -> ShowS
$cshowsPrec :: Int -> BucketValue -> ShowS
Show)
instance FromJSON BucketValue where
parseJSON :: Value -> Parser BucketValue
parseJSON (String Text
t) = BucketValue -> Parser BucketValue
forall (m :: * -> *) a. Monad m => a -> m a
return (BucketValue -> Parser BucketValue)
-> BucketValue -> Parser BucketValue
forall a b. (a -> b) -> a -> b
$ Text -> BucketValue
TextValue Text
t
parseJSON (Number Scientific
s) = BucketValue -> Parser BucketValue
forall (m :: * -> *) a. Monad m => a -> m a
return (BucketValue -> Parser BucketValue)
-> BucketValue -> Parser BucketValue
forall a b. (a -> b) -> a -> b
$ Scientific -> BucketValue
ScientificValue Scientific
s
parseJSON (Bool Bool
b) = BucketValue -> Parser BucketValue
forall (m :: * -> *) a. Monad m => a -> m a
return (BucketValue -> Parser BucketValue)
-> BucketValue -> Parser BucketValue
forall a b. (a -> b) -> a -> b
$ Bool -> BucketValue
BoolValue Bool
b
parseJSON Value
_ = Parser BucketValue
forall a. Monoid a => a
mempty
data TermInclusion = TermInclusion Text
| TermPattern Text Text deriving (TermInclusion -> TermInclusion -> Bool
(TermInclusion -> TermInclusion -> Bool)
-> (TermInclusion -> TermInclusion -> Bool) -> Eq TermInclusion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TermInclusion -> TermInclusion -> Bool
$c/= :: TermInclusion -> TermInclusion -> Bool
== :: TermInclusion -> TermInclusion -> Bool
$c== :: TermInclusion -> TermInclusion -> Bool
Eq, Int -> TermInclusion -> ShowS
[TermInclusion] -> ShowS
TermInclusion -> String
(Int -> TermInclusion -> ShowS)
-> (TermInclusion -> String)
-> ([TermInclusion] -> ShowS)
-> Show TermInclusion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TermInclusion] -> ShowS
$cshowList :: [TermInclusion] -> ShowS
show :: TermInclusion -> String
$cshow :: TermInclusion -> String
showsPrec :: Int -> TermInclusion -> ShowS
$cshowsPrec :: Int -> TermInclusion -> ShowS
Show)
instance ToJSON TermInclusion where
toJSON :: TermInclusion -> Value
toJSON (TermInclusion Text
x) = Text -> Value
forall a. ToJSON a => a -> Value
toJSON Text
x
toJSON (TermPattern Text
pattern Text
flags) =
[(Key, Value)] -> Value
omitNulls [ Key
"pattern" Key -> Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
pattern
, Key
"flags" Key -> Text -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
flags]
data TermOrder = TermOrder
{ TermOrder -> Text
termSortField :: Text
, TermOrder -> SortOrder
termSortOrder :: SortOrder } deriving (TermOrder -> TermOrder -> Bool
(TermOrder -> TermOrder -> Bool)
-> (TermOrder -> TermOrder -> Bool) -> Eq TermOrder
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TermOrder -> TermOrder -> Bool
$c/= :: TermOrder -> TermOrder -> Bool
== :: TermOrder -> TermOrder -> Bool
$c== :: TermOrder -> TermOrder -> Bool
Eq, Int -> TermOrder -> ShowS
[TermOrder] -> ShowS
TermOrder -> String
(Int -> TermOrder -> ShowS)
-> (TermOrder -> String)
-> ([TermOrder] -> ShowS)
-> Show TermOrder
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TermOrder] -> ShowS
$cshowList :: [TermOrder] -> ShowS
show :: TermOrder -> String
$cshow :: TermOrder -> String
showsPrec :: Int -> TermOrder -> ShowS
$cshowsPrec :: Int -> TermOrder -> ShowS
Show)
instance ToJSON TermOrder where
toJSON :: TermOrder -> Value
toJSON (TermOrder Text
termSortField SortOrder
termSortOrder) =
[(Key, Value)] -> Value
object [Text -> Key
fromText Text
termSortField Key -> SortOrder -> (Key, Value)
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= SortOrder
termSortOrder]
data CollectionMode = BreadthFirst
| DepthFirst deriving (CollectionMode -> CollectionMode -> Bool
(CollectionMode -> CollectionMode -> Bool)
-> (CollectionMode -> CollectionMode -> Bool) -> Eq CollectionMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CollectionMode -> CollectionMode -> Bool
$c/= :: CollectionMode -> CollectionMode -> Bool
== :: CollectionMode -> CollectionMode -> Bool
$c== :: CollectionMode -> CollectionMode -> Bool
Eq, Int -> CollectionMode -> ShowS
[CollectionMode] -> ShowS
CollectionMode -> String
(Int -> CollectionMode -> ShowS)
-> (CollectionMode -> String)
-> ([CollectionMode] -> ShowS)
-> Show CollectionMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CollectionMode] -> ShowS
$cshowList :: [CollectionMode] -> ShowS
show :: CollectionMode -> String
$cshow :: CollectionMode -> String
showsPrec :: Int -> CollectionMode -> ShowS
$cshowsPrec :: Int -> CollectionMode -> ShowS
Show)
instance ToJSON CollectionMode where
toJSON :: CollectionMode -> Value
toJSON CollectionMode
BreadthFirst = Value
"breadth_first"
toJSON CollectionMode
DepthFirst = Value
"depth_first"
data ExecutionHint = GlobalOrdinals
| Map deriving (ExecutionHint -> ExecutionHint -> Bool
(ExecutionHint -> ExecutionHint -> Bool)
-> (ExecutionHint -> ExecutionHint -> Bool) -> Eq ExecutionHint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExecutionHint -> ExecutionHint -> Bool
$c/= :: ExecutionHint -> ExecutionHint -> Bool
== :: ExecutionHint -> ExecutionHint -> Bool
$c== :: ExecutionHint -> ExecutionHint -> Bool
Eq, Int -> ExecutionHint -> ShowS
[ExecutionHint] -> ShowS
ExecutionHint -> String
(Int -> ExecutionHint -> ShowS)
-> (ExecutionHint -> String)
-> ([ExecutionHint] -> ShowS)
-> Show ExecutionHint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExecutionHint] -> ShowS
$cshowList :: [ExecutionHint] -> ShowS
show :: ExecutionHint -> String
$cshow :: ExecutionHint -> String
showsPrec :: Int -> ExecutionHint -> ShowS
$cshowsPrec :: Int -> ExecutionHint -> ShowS
Show)
instance ToJSON ExecutionHint where
toJSON :: ExecutionHint -> Value
toJSON ExecutionHint
GlobalOrdinals = Value
"global_ordinals"
toJSON ExecutionHint
Map = Value
"map"
data DateMathExpr =
DateMathExpr DateMathAnchor [DateMathModifier]
deriving (DateMathExpr -> DateMathExpr -> Bool
(DateMathExpr -> DateMathExpr -> Bool)
-> (DateMathExpr -> DateMathExpr -> Bool) -> Eq DateMathExpr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateMathExpr -> DateMathExpr -> Bool
$c/= :: DateMathExpr -> DateMathExpr -> Bool
== :: DateMathExpr -> DateMathExpr -> Bool
$c== :: DateMathExpr -> DateMathExpr -> Bool
Eq, Int -> DateMathExpr -> ShowS
[DateMathExpr] -> ShowS
DateMathExpr -> String
(Int -> DateMathExpr -> ShowS)
-> (DateMathExpr -> String)
-> ([DateMathExpr] -> ShowS)
-> Show DateMathExpr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateMathExpr] -> ShowS
$cshowList :: [DateMathExpr] -> ShowS
show :: DateMathExpr -> String
$cshow :: DateMathExpr -> String
showsPrec :: Int -> DateMathExpr -> ShowS
$cshowsPrec :: Int -> DateMathExpr -> ShowS
Show)
instance ToJSON DateMathExpr where
toJSON :: DateMathExpr -> Value
toJSON (DateMathExpr DateMathAnchor
a [DateMathModifier]
mods) = Text -> Value
String (DateMathAnchor -> Text
fmtA DateMathAnchor
a Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat (DateMathModifier -> Text
fmtMod (DateMathModifier -> Text) -> [DateMathModifier] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [DateMathModifier]
mods))
where fmtA :: DateMathAnchor -> Text
fmtA DateMathAnchor
DMNow = Text
"now"
fmtA (DMDate Day
date) = (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Day -> String
showGregorian Day
date) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"||"
fmtMod :: DateMathModifier -> Text
fmtMod (AddTime Int
n DateMathUnit
u) = Text
"+" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
showText Int
n Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> DateMathUnit -> Text
forall p. IsString p => DateMathUnit -> p
fmtU DateMathUnit
u
fmtMod (SubtractTime Int
n DateMathUnit
u) = Text
"-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall a. Show a => a -> Text
showText Int
n Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> DateMathUnit -> Text
forall p. IsString p => DateMathUnit -> p
fmtU DateMathUnit
u
fmtMod (RoundDownTo DateMathUnit
u) = Text
"/" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> DateMathUnit -> Text
forall p. IsString p => DateMathUnit -> p
fmtU DateMathUnit
u
fmtU :: DateMathUnit -> p
fmtU DateMathUnit
DMYear = p
"y"
fmtU DateMathUnit
DMMonth = p
"M"
fmtU DateMathUnit
DMWeek = p
"w"
fmtU DateMathUnit
DMDay = p
"d"
fmtU DateMathUnit
DMHour = p
"h"
fmtU DateMathUnit
DMMinute = p
"m"
fmtU DateMathUnit
DMSecond = p
"s"
data DateMathAnchor =
DMNow
| DMDate Day
deriving (DateMathAnchor -> DateMathAnchor -> Bool
(DateMathAnchor -> DateMathAnchor -> Bool)
-> (DateMathAnchor -> DateMathAnchor -> Bool) -> Eq DateMathAnchor
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateMathAnchor -> DateMathAnchor -> Bool
$c/= :: DateMathAnchor -> DateMathAnchor -> Bool
== :: DateMathAnchor -> DateMathAnchor -> Bool
$c== :: DateMathAnchor -> DateMathAnchor -> Bool
Eq, Int -> DateMathAnchor -> ShowS
[DateMathAnchor] -> ShowS
DateMathAnchor -> String
(Int -> DateMathAnchor -> ShowS)
-> (DateMathAnchor -> String)
-> ([DateMathAnchor] -> ShowS)
-> Show DateMathAnchor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateMathAnchor] -> ShowS
$cshowList :: [DateMathAnchor] -> ShowS
show :: DateMathAnchor -> String
$cshow :: DateMathAnchor -> String
showsPrec :: Int -> DateMathAnchor -> ShowS
$cshowsPrec :: Int -> DateMathAnchor -> ShowS
Show)
data DateMathModifier =
AddTime Int DateMathUnit
| SubtractTime Int DateMathUnit
| RoundDownTo DateMathUnit
deriving (DateMathModifier -> DateMathModifier -> Bool
(DateMathModifier -> DateMathModifier -> Bool)
-> (DateMathModifier -> DateMathModifier -> Bool)
-> Eq DateMathModifier
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateMathModifier -> DateMathModifier -> Bool
$c/= :: DateMathModifier -> DateMathModifier -> Bool
== :: DateMathModifier -> DateMathModifier -> Bool
$c== :: DateMathModifier -> DateMathModifier -> Bool
Eq, Int -> DateMathModifier -> ShowS
[DateMathModifier] -> ShowS
DateMathModifier -> String
(Int -> DateMathModifier -> ShowS)
-> (DateMathModifier -> String)
-> ([DateMathModifier] -> ShowS)
-> Show DateMathModifier
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateMathModifier] -> ShowS
$cshowList :: [DateMathModifier] -> ShowS
show :: DateMathModifier -> String
$cshow :: DateMathModifier -> String
showsPrec :: Int -> DateMathModifier -> ShowS
$cshowsPrec :: Int -> DateMathModifier -> ShowS
Show)
data DateMathUnit =
DMYear
| DMMonth
| DMWeek
| DMDay
| DMHour
| DMMinute
| DMSecond
deriving (DateMathUnit -> DateMathUnit -> Bool
(DateMathUnit -> DateMathUnit -> Bool)
-> (DateMathUnit -> DateMathUnit -> Bool) -> Eq DateMathUnit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateMathUnit -> DateMathUnit -> Bool
$c/= :: DateMathUnit -> DateMathUnit -> Bool
== :: DateMathUnit -> DateMathUnit -> Bool
$c== :: DateMathUnit -> DateMathUnit -> Bool
Eq, Int -> DateMathUnit -> ShowS
[DateMathUnit] -> ShowS
DateMathUnit -> String
(Int -> DateMathUnit -> ShowS)
-> (DateMathUnit -> String)
-> ([DateMathUnit] -> ShowS)
-> Show DateMathUnit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateMathUnit] -> ShowS
$cshowList :: [DateMathUnit] -> ShowS
show :: DateMathUnit -> String
$cshow :: DateMathUnit -> String
showsPrec :: Int -> DateMathUnit -> ShowS
$cshowsPrec :: Int -> DateMathUnit -> ShowS
Show)
data TermsResult = TermsResult
{ TermsResult -> BucketValue
termKey :: BucketValue
, TermsResult -> Int
termsDocCount :: Int
, TermsResult -> Maybe AggregationResults
termsAggs :: Maybe AggregationResults
} deriving (ReadPrec [TermsResult]
ReadPrec TermsResult
Int -> ReadS TermsResult
ReadS [TermsResult]
(Int -> ReadS TermsResult)
-> ReadS [TermsResult]
-> ReadPrec TermsResult
-> ReadPrec [TermsResult]
-> Read TermsResult
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TermsResult]
$creadListPrec :: ReadPrec [TermsResult]
readPrec :: ReadPrec TermsResult
$creadPrec :: ReadPrec TermsResult
readList :: ReadS [TermsResult]
$creadList :: ReadS [TermsResult]
readsPrec :: Int -> ReadS TermsResult
$creadsPrec :: Int -> ReadS TermsResult
Read, Int -> TermsResult -> ShowS
[TermsResult] -> ShowS
TermsResult -> String
(Int -> TermsResult -> ShowS)
-> (TermsResult -> String)
-> ([TermsResult] -> ShowS)
-> Show TermsResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TermsResult] -> ShowS
$cshowList :: [TermsResult] -> ShowS
show :: TermsResult -> String
$cshow :: TermsResult -> String
showsPrec :: Int -> TermsResult -> ShowS
$cshowsPrec :: Int -> TermsResult -> ShowS
Show)
instance FromJSON TermsResult where
parseJSON :: Value -> Parser TermsResult
parseJSON (Object Object
v) = BucketValue -> Int -> Maybe AggregationResults -> TermsResult
TermsResult (BucketValue -> Int -> Maybe AggregationResults -> TermsResult)
-> Parser BucketValue
-> Parser (Int -> Maybe AggregationResults -> TermsResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Object
v Object -> Key -> Parser BucketValue
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"key" Parser (Int -> Maybe AggregationResults -> TermsResult)
-> Parser Int -> Parser (Maybe AggregationResults -> TermsResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"doc_count" Parser (Maybe AggregationResults -> TermsResult)
-> Parser (Maybe AggregationResults) -> Parser TermsResult
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
(Maybe AggregationResults -> Parser (Maybe AggregationResults)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe AggregationResults -> Parser (Maybe AggregationResults))
-> Maybe AggregationResults -> Parser (Maybe AggregationResults)
forall a b. (a -> b) -> a -> b
$ Object -> [Key] -> Maybe AggregationResults
getNamedSubAgg Object
v [Key
"key", Key
"doc_count"])
parseJSON Value
_ = Parser TermsResult
forall a. Monoid a => a
mempty
instance BucketAggregation TermsResult where
key :: TermsResult -> BucketValue
key = TermsResult -> BucketValue
termKey
docCount :: TermsResult -> Int
docCount = TermsResult -> Int
termsDocCount
aggs :: TermsResult -> Maybe AggregationResults
aggs = TermsResult -> Maybe AggregationResults
termsAggs
data DateHistogramResult = DateHistogramResult
{ DateHistogramResult -> Int
dateKey :: Int
, DateHistogramResult -> Maybe Text
dateKeyStr :: Maybe Text
, DateHistogramResult -> Int
dateDocCount :: Int
, DateHistogramResult -> Maybe AggregationResults
dateHistogramAggs :: Maybe AggregationResults
} deriving (Int -> DateHistogramResult -> ShowS
[DateHistogramResult] -> ShowS
DateHistogramResult -> String
(Int -> DateHistogramResult -> ShowS)
-> (DateHistogramResult -> String)
-> ([DateHistogramResult] -> ShowS)
-> Show DateHistogramResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateHistogramResult] -> ShowS
$cshowList :: [DateHistogramResult] -> ShowS
show :: DateHistogramResult -> String
$cshow :: DateHistogramResult -> String
showsPrec :: Int -> DateHistogramResult -> ShowS
$cshowsPrec :: Int -> DateHistogramResult -> ShowS
Show)
instance FromJSON DateHistogramResult where
parseJSON :: Value -> Parser DateHistogramResult
parseJSON (Object Object
v) = Int
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateHistogramResult
DateHistogramResult (Int
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateHistogramResult)
-> Parser Int
-> Parser
(Maybe Text
-> Int -> Maybe AggregationResults -> DateHistogramResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"key" Parser
(Maybe Text
-> Int -> Maybe AggregationResults -> DateHistogramResult)
-> Parser (Maybe Text)
-> Parser (Int -> Maybe AggregationResults -> DateHistogramResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"key_as_string" Parser (Int -> Maybe AggregationResults -> DateHistogramResult)
-> Parser Int
-> Parser (Maybe AggregationResults -> DateHistogramResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"doc_count" Parser (Maybe AggregationResults -> DateHistogramResult)
-> Parser (Maybe AggregationResults) -> Parser DateHistogramResult
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
(Maybe AggregationResults -> Parser (Maybe AggregationResults)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe AggregationResults -> Parser (Maybe AggregationResults))
-> Maybe AggregationResults -> Parser (Maybe AggregationResults)
forall a b. (a -> b) -> a -> b
$ Object -> [Key] -> Maybe AggregationResults
getNamedSubAgg Object
v [ Key
"key"
, Key
"doc_count"
, Key
"key_as_string"
]
)
parseJSON Value
_ = Parser DateHistogramResult
forall a. Monoid a => a
mempty
instance BucketAggregation DateHistogramResult where
key :: DateHistogramResult -> BucketValue
key = Text -> BucketValue
TextValue (Text -> BucketValue)
-> (DateHistogramResult -> Text)
-> DateHistogramResult
-> BucketValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text
forall a. Show a => a -> Text
showText (Int -> Text)
-> (DateHistogramResult -> Int) -> DateHistogramResult -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DateHistogramResult -> Int
dateKey
docCount :: DateHistogramResult -> Int
docCount = DateHistogramResult -> Int
dateDocCount
aggs :: DateHistogramResult -> Maybe AggregationResults
aggs = DateHistogramResult -> Maybe AggregationResults
dateHistogramAggs
data DateRangeResult = DateRangeResult
{ DateRangeResult -> Text
dateRangeKey :: Text
, DateRangeResult -> Maybe UTCTime
dateRangeFrom :: Maybe UTCTime
, DateRangeResult -> Maybe Text
dateRangeFromAsString :: Maybe Text
, DateRangeResult -> Maybe UTCTime
dateRangeTo :: Maybe UTCTime
, DateRangeResult -> Maybe Text
dateRangeToAsString :: Maybe Text
, DateRangeResult -> Int
dateRangeDocCount :: Int
, DateRangeResult -> Maybe AggregationResults
dateRangeAggs :: Maybe AggregationResults
} deriving (DateRangeResult -> DateRangeResult -> Bool
(DateRangeResult -> DateRangeResult -> Bool)
-> (DateRangeResult -> DateRangeResult -> Bool)
-> Eq DateRangeResult
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DateRangeResult -> DateRangeResult -> Bool
$c/= :: DateRangeResult -> DateRangeResult -> Bool
== :: DateRangeResult -> DateRangeResult -> Bool
$c== :: DateRangeResult -> DateRangeResult -> Bool
Eq, Int -> DateRangeResult -> ShowS
[DateRangeResult] -> ShowS
DateRangeResult -> String
(Int -> DateRangeResult -> ShowS)
-> (DateRangeResult -> String)
-> ([DateRangeResult] -> ShowS)
-> Show DateRangeResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DateRangeResult] -> ShowS
$cshowList :: [DateRangeResult] -> ShowS
show :: DateRangeResult -> String
$cshow :: DateRangeResult -> String
showsPrec :: Int -> DateRangeResult -> ShowS
$cshowsPrec :: Int -> DateRangeResult -> ShowS
Show)
instance FromJSON DateRangeResult where
parseJSON :: Value -> Parser DateRangeResult
parseJSON = String
-> (Object -> Parser DateRangeResult)
-> Value
-> Parser DateRangeResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"DateRangeResult" Object -> Parser DateRangeResult
parse
where parse :: Object -> Parser DateRangeResult
parse Object
v = Text
-> Maybe UTCTime
-> Maybe Text
-> Maybe UTCTime
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateRangeResult
DateRangeResult (Text
-> Maybe UTCTime
-> Maybe Text
-> Maybe UTCTime
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateRangeResult)
-> Parser Text
-> Parser
(Maybe UTCTime
-> Maybe Text
-> Maybe UTCTime
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateRangeResult)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"key" Parser
(Maybe UTCTime
-> Maybe Text
-> Maybe UTCTime
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateRangeResult)
-> Parser (Maybe UTCTime)
-> Parser
(Maybe Text
-> Maybe UTCTime
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateRangeResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
((POSIXMS -> UTCTime) -> Maybe POSIXMS -> Maybe UTCTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap POSIXMS -> UTCTime
posixMS (Maybe POSIXMS -> Maybe UTCTime)
-> Parser (Maybe POSIXMS) -> Parser (Maybe UTCTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe POSIXMS)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"from") Parser
(Maybe Text
-> Maybe UTCTime
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateRangeResult)
-> Parser (Maybe Text)
-> Parser
(Maybe UTCTime
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateRangeResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"from_as_string" Parser
(Maybe UTCTime
-> Maybe Text
-> Int
-> Maybe AggregationResults
-> DateRangeResult)
-> Parser (Maybe UTCTime)
-> Parser
(Maybe Text -> Int -> Maybe AggregationResults -> DateRangeResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
((POSIXMS -> UTCTime) -> Maybe POSIXMS -> Maybe UTCTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap POSIXMS -> UTCTime
posixMS (Maybe POSIXMS -> Maybe UTCTime)
-> Parser (Maybe POSIXMS) -> Parser (Maybe UTCTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe POSIXMS)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"to") Parser
(Maybe Text -> Int -> Maybe AggregationResults -> DateRangeResult)
-> Parser (Maybe Text)
-> Parser (Int -> Maybe AggregationResults -> DateRangeResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"to_as_string" Parser (Int -> Maybe AggregationResults -> DateRangeResult)
-> Parser Int
-> Parser (Maybe AggregationResults -> DateRangeResult)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"doc_count" Parser (Maybe AggregationResults -> DateRangeResult)
-> Parser (Maybe AggregationResults) -> Parser DateRangeResult
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
(Maybe AggregationResults -> Parser (Maybe AggregationResults)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe AggregationResults -> Parser (Maybe AggregationResults))
-> Maybe AggregationResults -> Parser (Maybe AggregationResults)
forall a b. (a -> b) -> a -> b
$ Object -> [Key] -> Maybe AggregationResults
getNamedSubAgg Object
v [ Key
"key"
, Key
"from"
, Key
"from_as_string"
, Key
"to"
, Key
"to_as_string"
, Key
"doc_count"
]
)
instance BucketAggregation DateRangeResult where
key :: DateRangeResult -> BucketValue
key = Text -> BucketValue
TextValue (Text -> BucketValue)
-> (DateRangeResult -> Text) -> DateRangeResult -> BucketValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DateRangeResult -> Text
dateRangeKey
docCount :: DateRangeResult -> Int
docCount = DateRangeResult -> Int
dateRangeDocCount
aggs :: DateRangeResult -> Maybe AggregationResults
aggs = DateRangeResult -> Maybe AggregationResults
dateRangeAggs
toTerms :: Key -> AggregationResults -> Maybe (Bucket TermsResult)
toTerms :: Key -> AggregationResults -> Maybe (Bucket TermsResult)
toTerms = Key -> AggregationResults -> Maybe (Bucket TermsResult)
forall a. FromJSON a => Key -> AggregationResults -> Maybe a
toAggResult
toDateHistogram :: Key -> AggregationResults -> Maybe (Bucket DateHistogramResult)
toDateHistogram :: Key -> AggregationResults -> Maybe (Bucket DateHistogramResult)
toDateHistogram = Key -> AggregationResults -> Maybe (Bucket DateHistogramResult)
forall a. FromJSON a => Key -> AggregationResults -> Maybe a
toAggResult
toMissing :: Key -> AggregationResults -> Maybe MissingResult
toMissing :: Key -> AggregationResults -> Maybe MissingResult
toMissing = Key -> AggregationResults -> Maybe MissingResult
forall a. FromJSON a => Key -> AggregationResults -> Maybe a
toAggResult
toTopHits :: (FromJSON a) => Key -> AggregationResults -> Maybe (TopHitResult a)
toTopHits :: Key -> AggregationResults -> Maybe (TopHitResult a)
toTopHits = Key -> AggregationResults -> Maybe (TopHitResult a)
forall a. FromJSON a => Key -> AggregationResults -> Maybe a
toAggResult
toAggResult :: (FromJSON a) => Key -> AggregationResults -> Maybe a
toAggResult :: Key -> AggregationResults -> Maybe a
toAggResult Key
t AggregationResults
a = Key -> AggregationResults -> Maybe Value
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Key
t AggregationResults
a Maybe Value -> (Value -> Maybe a) -> Maybe a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> Maybe a
deserialize
where deserialize :: Value -> Maybe a
deserialize = (Value -> Parser a) -> Value -> Maybe a
forall a b. (a -> Parser b) -> a -> Maybe b
parseMaybe Value -> Parser a
forall a. FromJSON a => Value -> Parser a
parseJSON
getNamedSubAgg :: Object -> [Key] -> Maybe AggregationResults
getNamedSubAgg :: Object -> [Key] -> Maybe AggregationResults
getNamedSubAgg Object
o [Key]
knownKeys = Maybe AggregationResults
maggRes
where unknownKeys :: Object
unknownKeys = (Key -> Value -> Bool) -> Object -> Object
forall v. (Key -> v -> Bool) -> KeyMap v -> KeyMap v
X.filterWithKey (\Key
k Value
_ -> Key
k Key -> [Key] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Key]
knownKeys) Object
o
maggRes :: Maybe AggregationResults
maggRes
| Object -> Bool
forall v. KeyMap v -> Bool
X.null Object
unknownKeys = Maybe AggregationResults
forall a. Maybe a
Nothing
| Bool
otherwise = AggregationResults -> Maybe AggregationResults
forall a. a -> Maybe a
Just (AggregationResults -> Maybe AggregationResults)
-> ([(Key, Value)] -> AggregationResults)
-> [(Key, Value)]
-> Maybe AggregationResults
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Key, Value)] -> AggregationResults
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList ([(Key, Value)] -> Maybe AggregationResults)
-> [(Key, Value)] -> Maybe AggregationResults
forall a b. (a -> b) -> a -> b
$ Object -> [(Key, Value)]
forall v. KeyMap v -> [(Key, v)]
X.toList Object
unknownKeys
data MissingResult = MissingResult
{ MissingResult -> Int
missingDocCount :: Int
} deriving (Int -> MissingResult -> ShowS
[MissingResult] -> ShowS
MissingResult -> String
(Int -> MissingResult -> ShowS)
-> (MissingResult -> String)
-> ([MissingResult] -> ShowS)
-> Show MissingResult
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MissingResult] -> ShowS
$cshowList :: [MissingResult] -> ShowS
show :: MissingResult -> String
$cshow :: MissingResult -> String
showsPrec :: Int -> MissingResult -> ShowS
$cshowsPrec :: Int -> MissingResult -> ShowS
Show)
instance FromJSON MissingResult where
parseJSON :: Value -> Parser MissingResult
parseJSON = String
-> (Object -> Parser MissingResult)
-> Value
-> Parser MissingResult
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"MissingResult" Object -> Parser MissingResult
parse
where parse :: Object -> Parser MissingResult
parse Object
v = Int -> MissingResult
MissingResult (Int -> MissingResult) -> Parser Int -> Parser MissingResult
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"doc_count"
data TopHitResult a = TopHitResult
{ TopHitResult a -> SearchHits a
tarHits :: (SearchHits a)
} deriving (TopHitResult a -> TopHitResult a -> Bool
(TopHitResult a -> TopHitResult a -> Bool)
-> (TopHitResult a -> TopHitResult a -> Bool)
-> Eq (TopHitResult a)
forall a. Eq a => TopHitResult a -> TopHitResult a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TopHitResult a -> TopHitResult a -> Bool
$c/= :: forall a. Eq a => TopHitResult a -> TopHitResult a -> Bool
== :: TopHitResult a -> TopHitResult a -> Bool
$c== :: forall a. Eq a => TopHitResult a -> TopHitResult a -> Bool
Eq, Int -> TopHitResult a -> ShowS
[TopHitResult a] -> ShowS
TopHitResult a -> String
(Int -> TopHitResult a -> ShowS)
-> (TopHitResult a -> String)
-> ([TopHitResult a] -> ShowS)
-> Show (TopHitResult a)
forall a. Show a => Int -> TopHitResult a -> ShowS
forall a. Show a => [TopHitResult a] -> ShowS
forall a. Show a => TopHitResult a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopHitResult a] -> ShowS
$cshowList :: forall a. Show a => [TopHitResult a] -> ShowS
show :: TopHitResult a -> String
$cshow :: forall a. Show a => TopHitResult a -> String
showsPrec :: Int -> TopHitResult a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> TopHitResult a -> ShowS
Show)
instance (FromJSON a) => FromJSON (TopHitResult a) where
parseJSON :: Value -> Parser (TopHitResult a)
parseJSON (Object Object
v) = SearchHits a -> TopHitResult a
forall a. SearchHits a -> TopHitResult a
TopHitResult (SearchHits a -> TopHitResult a)
-> Parser (SearchHits a) -> Parser (TopHitResult a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Object
v Object -> Key -> Parser (SearchHits a)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"hits"
parseJSON Value
_ = String -> Parser (TopHitResult a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"Failure in FromJSON (TopHitResult a)"
data HitsTotalRelation = HTR_EQ | HTR_GTE deriving (HitsTotalRelation -> HitsTotalRelation -> Bool
(HitsTotalRelation -> HitsTotalRelation -> Bool)
-> (HitsTotalRelation -> HitsTotalRelation -> Bool)
-> Eq HitsTotalRelation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HitsTotalRelation -> HitsTotalRelation -> Bool
$c/= :: HitsTotalRelation -> HitsTotalRelation -> Bool
== :: HitsTotalRelation -> HitsTotalRelation -> Bool
$c== :: HitsTotalRelation -> HitsTotalRelation -> Bool
Eq, Int -> HitsTotalRelation -> ShowS
[HitsTotalRelation] -> ShowS
HitsTotalRelation -> String
(Int -> HitsTotalRelation -> ShowS)
-> (HitsTotalRelation -> String)
-> ([HitsTotalRelation] -> ShowS)
-> Show HitsTotalRelation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HitsTotalRelation] -> ShowS
$cshowList :: [HitsTotalRelation] -> ShowS
show :: HitsTotalRelation -> String
$cshow :: HitsTotalRelation -> String
showsPrec :: Int -> HitsTotalRelation -> ShowS
$cshowsPrec :: Int -> HitsTotalRelation -> ShowS
Show)
instance FromJSON HitsTotalRelation where
parseJSON :: Value -> Parser HitsTotalRelation
parseJSON (String Text
"eq") = HitsTotalRelation -> Parser HitsTotalRelation
forall (f :: * -> *) a. Applicative f => a -> f a
pure HitsTotalRelation
HTR_EQ
parseJSON (String Text
"gte") = HitsTotalRelation -> Parser HitsTotalRelation
forall (f :: * -> *) a. Applicative f => a -> f a
pure HitsTotalRelation
HTR_GTE
parseJSON Value
_ = Parser HitsTotalRelation
forall (f :: * -> *) a. Alternative f => f a
empty
data HitsTotal =
HitsTotal { HitsTotal -> Int
value :: Int
, HitsTotal -> HitsTotalRelation
relation :: HitsTotalRelation } deriving (HitsTotal -> HitsTotal -> Bool
(HitsTotal -> HitsTotal -> Bool)
-> (HitsTotal -> HitsTotal -> Bool) -> Eq HitsTotal
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HitsTotal -> HitsTotal -> Bool
$c/= :: HitsTotal -> HitsTotal -> Bool
== :: HitsTotal -> HitsTotal -> Bool
$c== :: HitsTotal -> HitsTotal -> Bool
Eq, Int -> HitsTotal -> ShowS
[HitsTotal] -> ShowS
HitsTotal -> String
(Int -> HitsTotal -> ShowS)
-> (HitsTotal -> String)
-> ([HitsTotal] -> ShowS)
-> Show HitsTotal
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HitsTotal] -> ShowS
$cshowList :: [HitsTotal] -> ShowS
show :: HitsTotal -> String
$cshow :: HitsTotal -> String
showsPrec :: Int -> HitsTotal -> ShowS
$cshowsPrec :: Int -> HitsTotal -> ShowS
Show)
instance FromJSON HitsTotal where
parseJSON :: Value -> Parser HitsTotal
parseJSON (Object Object
v) = Int -> HitsTotalRelation -> HitsTotal
HitsTotal (Int -> HitsTotalRelation -> HitsTotal)
-> Parser Int -> Parser (HitsTotalRelation -> HitsTotal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value" Parser (HitsTotalRelation -> HitsTotal)
-> Parser HitsTotalRelation -> Parser HitsTotal
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser HitsTotalRelation
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"relation"
parseJSON Value
_ = Parser HitsTotal
forall (f :: * -> *) a. Alternative f => f a
empty
instance Semigroup HitsTotal where
(HitsTotal Int
ta HitsTotalRelation
HTR_EQ) <> :: HitsTotal -> HitsTotal -> HitsTotal
<> (HitsTotal Int
tb HitsTotalRelation
HTR_EQ) = Int -> HitsTotalRelation -> HitsTotal
HitsTotal (Int
ta Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
tb) HitsTotalRelation
HTR_EQ
(HitsTotal Int
ta HitsTotalRelation
HTR_GTE) <> (HitsTotal Int
tb HitsTotalRelation
_) = Int -> HitsTotalRelation -> HitsTotal
HitsTotal (Int
ta Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
tb) HitsTotalRelation
HTR_GTE
(HitsTotal Int
ta HitsTotalRelation
_) <> (HitsTotal Int
tb HitsTotalRelation
HTR_GTE) = Int -> HitsTotalRelation -> HitsTotal
HitsTotal (Int
ta Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
tb) HitsTotalRelation
HTR_GTE
data SearchHits a =
SearchHits { SearchHits a -> HitsTotal
hitsTotal :: HitsTotal
, SearchHits a -> Score
maxScore :: Score
, SearchHits a -> [Hit a]
hits :: [Hit a] } deriving (SearchHits a -> SearchHits a -> Bool
(SearchHits a -> SearchHits a -> Bool)
-> (SearchHits a -> SearchHits a -> Bool) -> Eq (SearchHits a)
forall a. Eq a => SearchHits a -> SearchHits a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SearchHits a -> SearchHits a -> Bool
$c/= :: forall a. Eq a => SearchHits a -> SearchHits a -> Bool
== :: SearchHits a -> SearchHits a -> Bool
$c== :: forall a. Eq a => SearchHits a -> SearchHits a -> Bool
Eq, Int -> SearchHits a -> ShowS
[SearchHits a] -> ShowS
SearchHits a -> String
(Int -> SearchHits a -> ShowS)
-> (SearchHits a -> String)
-> ([SearchHits a] -> ShowS)
-> Show (SearchHits a)
forall a. Show a => Int -> SearchHits a -> ShowS
forall a. Show a => [SearchHits a] -> ShowS
forall a. Show a => SearchHits a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SearchHits a] -> ShowS
$cshowList :: forall a. Show a => [SearchHits a] -> ShowS
show :: SearchHits a -> String
$cshow :: forall a. Show a => SearchHits a -> String
showsPrec :: Int -> SearchHits a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> SearchHits a -> ShowS
Show)
instance (FromJSON a) => FromJSON (SearchHits a) where
parseJSON :: Value -> Parser (SearchHits a)
parseJSON (Object Object
v) = HitsTotal -> Score -> [Hit a] -> SearchHits a
forall a. HitsTotal -> Score -> [Hit a] -> SearchHits a
SearchHits (HitsTotal -> Score -> [Hit a] -> SearchHits a)
-> Parser HitsTotal -> Parser (Score -> [Hit a] -> SearchHits a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Object
v Object -> Key -> Parser HitsTotal
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"total" Parser (Score -> [Hit a] -> SearchHits a)
-> Parser Score -> Parser ([Hit a] -> SearchHits a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser Score
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"max_score" Parser ([Hit a] -> SearchHits a)
-> Parser [Hit a] -> Parser (SearchHits a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser [Hit a]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"hits"
parseJSON Value
_ = Parser (SearchHits a)
forall (f :: * -> *) a. Alternative f => f a
empty
instance Semigroup (SearchHits a) where
(SearchHits HitsTotal
ta Score
ma [Hit a]
ha) <> :: SearchHits a -> SearchHits a -> SearchHits a
<> (SearchHits HitsTotal
tb Score
mb [Hit a]
hb) =
HitsTotal -> Score -> [Hit a] -> SearchHits a
forall a. HitsTotal -> Score -> [Hit a] -> SearchHits a
SearchHits (HitsTotal
ta HitsTotal -> HitsTotal -> HitsTotal
forall a. Semigroup a => a -> a -> a
<> HitsTotal
tb) (Score -> Score -> Score
forall a. Ord a => a -> a -> a
max Score
ma Score
mb) ([Hit a]
ha [Hit a] -> [Hit a] -> [Hit a]
forall a. Semigroup a => a -> a -> a
<> [Hit a]
hb)
instance Monoid (SearchHits a) where
mempty :: SearchHits a
mempty = HitsTotal -> Score -> [Hit a] -> SearchHits a
forall a. HitsTotal -> Score -> [Hit a] -> SearchHits a
SearchHits (Int -> HitsTotalRelation -> HitsTotal
HitsTotal Int
0 HitsTotalRelation
HTR_EQ) Score
forall a. Maybe a
Nothing [Hit a]
forall a. Monoid a => a
mempty
mappend :: SearchHits a -> SearchHits a -> SearchHits a
mappend = SearchHits a -> SearchHits a -> SearchHits a
forall a. Semigroup a => a -> a -> a
(<>)
type SearchAfterKey = [Aeson.Value]
data Hit a =
Hit { Hit a -> IndexName
hitIndex :: IndexName
, Hit a -> DocId
hitDocId :: DocId
, Hit a -> Score
hitScore :: Score
, Hit a -> Maybe a
hitSource :: Maybe a
, Hit a -> Maybe SearchAfterKey
hitSort :: Maybe SearchAfterKey
, Hit a -> Maybe HitFields
hitFields :: Maybe HitFields
, Hit a -> Maybe HitHighlight
hitHighlight :: Maybe HitHighlight
, Hit a -> Maybe (KeyMap (TopHitResult Value))
hitInnerHits :: Maybe (X.KeyMap (TopHitResult Value)) } deriving (Hit a -> Hit a -> Bool
(Hit a -> Hit a -> Bool) -> (Hit a -> Hit a -> Bool) -> Eq (Hit a)
forall a. Eq a => Hit a -> Hit a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Hit a -> Hit a -> Bool
$c/= :: forall a. Eq a => Hit a -> Hit a -> Bool
== :: Hit a -> Hit a -> Bool
$c== :: forall a. Eq a => Hit a -> Hit a -> Bool
Eq, Int -> Hit a -> ShowS
[Hit a] -> ShowS
Hit a -> String
(Int -> Hit a -> ShowS)
-> (Hit a -> String) -> ([Hit a] -> ShowS) -> Show (Hit a)
forall a. Show a => Int -> Hit a -> ShowS
forall a. Show a => [Hit a] -> ShowS
forall a. Show a => Hit a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Hit a] -> ShowS
$cshowList :: forall a. Show a => [Hit a] -> ShowS
show :: Hit a -> String
$cshow :: forall a. Show a => Hit a -> String
showsPrec :: Int -> Hit a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Hit a -> ShowS
Show)
instance (FromJSON a) => FromJSON (Hit a) where
parseJSON :: Value -> Parser (Hit a)
parseJSON (Object Object
v) = IndexName
-> DocId
-> Score
-> Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a
forall a.
IndexName
-> DocId
-> Score
-> Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a
Hit (IndexName
-> DocId
-> Score
-> Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
-> Parser IndexName
-> Parser
(DocId
-> Score
-> Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Object
v Object -> Key -> Parser IndexName
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"_index" Parser
(DocId
-> Score
-> Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
-> Parser DocId
-> Parser
(Score
-> Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser DocId
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"_id" Parser
(Score
-> Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
-> Parser Score
-> Parser
(Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser Score
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"_score" Parser
(Maybe a
-> Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
-> Parser (Maybe a)
-> Parser
(Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser (Maybe a)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"_source" Parser
(Maybe SearchAfterKey
-> Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
-> Parser (Maybe SearchAfterKey)
-> Parser
(Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser (Maybe SearchAfterKey)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"sort" Parser
(Maybe HitFields
-> Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value))
-> Hit a)
-> Parser (Maybe HitFields)
-> Parser
(Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value)) -> Hit a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser (Maybe HitFields)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"fields" Parser
(Maybe HitHighlight
-> Maybe (KeyMap (TopHitResult Value)) -> Hit a)
-> Parser (Maybe HitHighlight)
-> Parser (Maybe (KeyMap (TopHitResult Value)) -> Hit a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser (Maybe HitHighlight)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"highlight" Parser (Maybe (KeyMap (TopHitResult Value)) -> Hit a)
-> Parser (Maybe (KeyMap (TopHitResult Value))) -> Parser (Hit a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
Object
v Object -> Key -> Parser (Maybe (KeyMap (TopHitResult Value)))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"inner_hits"
parseJSON Value
_ = Parser (Hit a)
forall (f :: * -> *) a. Alternative f => f a
empty