@@ -122,6 +122,7 @@ module Database.V5.Bloodhound.Types
122 , Pattern(..)
122 , Pattern(..)
123 , ShardResult(..)
123 , ShardResult(..)
124 , Hit(..)
124 , Hit(..)
125 , Filter(..)
126 , Filter(..)
126 , Seminearring(..)
127 , Seminearring(..)
127 , BoolMatch(..)
128 , BoolMatch(..)
@@ -150,7 +151,16 @@ module Database.V5.Bloodhound.Types
150 , RegexpFlags(..)
151 , RegexpFlags(..)
151 , RegexpFlag(..)
152 , RegexpFlag(..)
152 , FieldName(..)
153 , FieldName(..)
153 , Script(..)
157 , Script(..)
158+ , ScriptLanguage(..)
154 , IndexName(..)
164 , IndexName(..)
155 , IndexSelection(..)
165 , IndexSelection(..)
156 , NodeSelection(..)
166 , NodeSelection(..)
@@ -180,6 +190,18 @@ module Database.V5.Bloodhound.Types
180 , BoolQuery(..)
190 , BoolQuery(..)
181 , BoostingQuery(..)
191 , BoostingQuery(..)
182 , CommonTermsQuery(..)
192 , CommonTermsQuery(..)
193+ , FunctionScoreQuery(..)
196+ , FunctionScoreFunctions(..)
197+ , ComponentFunctionScoreFunction(..)
198+ , FunctionScoreFunction(..)
201+ , FieldValueFactor(..)
203+ , FactorModifier(..)
204+ , FactorMissingFieldValue(..)
183 , DisMaxQuery(..)
205 , DisMaxQuery(..)
184 , FuzzyLikeThisQuery(..)
206 , FuzzyLikeThisQuery(..)
185 , FuzzyLikeFieldQuery(..)
207 , FuzzyLikeFieldQuery(..)
@@ -521,6 +543,7 @@ data Search = Search { queryBody :: Maybe Query
521 , size :: Size
543 , size :: Size
522 , searchType :: SearchType
544 , searchType :: SearchType
523 , fields :: Maybe [FieldName]
545 , fields :: Maybe [FieldName]
546+ , scriptFields :: Maybe ScriptFields
524 , source :: Maybe Source
547 , source :: Maybe Source
525 , suggestBody :: Maybe Suggest -- ^ Only one Suggestion request / response per Search is supported.
548 , suggestBody :: Maybe Suggest -- ^ Only one Suggestion request / response per Search is supported.
526 } deriving (Eq, Show)
549 } deriving (Eq, Show)
@@ -607,9 +630,6 @@ data HighlightTag =
607 | CustomTags ([Text], [Text])
630 | CustomTags ([Text], [Text])
608 deriving (Eq, Show)
631 deriving (Eq, Show)
613data SearchResult a =
633data SearchResult a =
614 SearchResult { took :: Int
634 SearchResult { took :: Int
615 , timedOut :: Bool
635 , timedOut :: Bool
@@ -617,7 +637,8 @@ data SearchResult a =
617 , searchHits :: SearchHits a
637 , searchHits :: SearchHits a
618 , aggregations :: Maybe AggregationResults
638 , aggregations :: Maybe AggregationResults
619 , scrollId :: Maybe ScrollId
639 , scrollId :: Maybe ScrollId
620− , suggest :: Maybe NamedSuggestionResponse -- ^ Only one Suggestion request / response per Search is supported.
640+ -- ^ Only one Suggestion request / response per Search is supported.
641+ , suggest :: Maybe NamedSuggestionResponse
622 deriving (Eq, Show)
643 deriving (Eq, Show)
@@ -625,8 +646,6 @@ newtype ScrollId =
625 ScrollId Text
646 ScrollId Text
626 deriving (Eq, Show, Ord, ToJSON, FromJSON)
647 deriving (Eq, Show, Ord, ToJSON, FromJSON)
628−type Score = Maybe Double
630data SearchHits a =
649data SearchHits a =
631 SearchHits { hitsTotal :: Int
650 SearchHits { hitsTotal :: Int
632 , maxScore :: Score
651 , maxScore :: Score
@@ -645,8 +664,13 @@ data Hit a =
645 , hitDocId :: DocId
664 , hitDocId :: DocId
646 , hitScore :: Score
665 , hitScore :: Score
647 , hitSource :: Maybe a
666 , hitSource :: Maybe a
667+ , hitFields :: Maybe HitFields
648 , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show)
668 , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show)
671+ HitFields (M.Map Text [Value])
650type HitHighlight = M.Map Text [Text]
674type HitHighlight = M.Map Text [Text]
@@ -856,7 +880,9 @@ instance ToJSON Aggregation where
883+ toJSON (DateHistogramAgg
884+ (DateHistogramAggregation field interval format
859− toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
885+ preZone postZone preOffset postOffset dateHistoAggs)) =
860 omitNulls ["date_histogram" .= omitNulls [ "field" .= field,
886 omitNulls ["date_histogram" .= omitNulls [ "field" .= field,
861 "interval" .= interval,
887 "interval" .= interval,
862 "format" .= format,
888 "format" .= format,
@@ -868,8 +894,10 @@ instance ToJSON Aggregation where
868 "aggs" .= dateHistoAggs ]
894 "aggs" .= dateHistoAggs ]
869 toJSON (ValueCountAgg a) = object ["value_count" .= v]
895 toJSON (ValueCountAgg a) = object ["value_count" .= v]
870 where v = case a of
896 where v = case a of
871− (FieldValueCount (FieldName n)) -> object ["field" .= n]
897+ (FieldValueCount (FieldName n)) ->
898+ object ["field" .= n]
872− (ScriptValueCount (Script s)) -> object ["script" .= s]
899+ (ScriptValueCount s) ->
900+ object ["script" .= s]
873 toJSON (FilterAgg (FilterAggregation filt ags)) =
901 toJSON (FilterAgg (FilterAggregation filt ags)) =
874 omitNulls [ "filter" .= filt
902 omitNulls [ "filter" .= filt
875 , "aggs" .= ags]
903 , "aggs" .= ags]
@@ -1058,11 +1086,6 @@ instance ToJSON GeoPoint where
1058 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1086 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1059 object [ geoPointField .= geoPointLatLon ]
1087 object [ geoPointField .= geoPointLatLon ]
1066instance FromJSON Status where
1089instance FromJSON Status where
1067 parseJSON (Object v) = Status <$>
1090 parseJSON (Object v) = Status <$>
1068 v .: "name" <*>
1091 v .: "name" <*>
@@ -1393,21 +1416,28 @@ instance FromJSON SearchAliasRouting where
1393 where parse t = SearchAliasRouting <$> parseNEJSON (String <$> T.splitOn "," t)
1416 where parse t = SearchAliasRouting <$> parseNEJSON (String <$> T.splitOn "," t)
1395instance ToJSON Search where
1418instance ToJSON Search where
1419+ toJSON (Search mquery sFilter sort searchAggs
1396− toJSON (Search mquery sFilter sort searchAggs highlight sTrackSortScores sFrom sSize _ sFields sSource sSuggest) =
1420+ highlight sTrackSortScores sFrom sSize _ sFields
1421+ sScriptFields sSource sSuggest) =
1397− omitNulls [ "query" .= query'
1422+ omitNulls [ "query" .= query'
1398− , "sort" .= sort
1423+ , "sort" .= sort
1399− , "aggregations" .= searchAggs
1424+ , "aggregations" .= searchAggs
1400− , "highlight" .= highlight
1425+ , "highlight" .= highlight
1401− , "from" .= sFrom
1426+ , "from" .= sFrom
1402− , "size" .= sSize
1427+ , "size" .= sSize
1403− , "track_scores" .= sTrackSortScores
1428+ , "track_scores" .= sTrackSortScores
1404− , "fields" .= sFields
1429+ , "fields" .= sFields
1430+ , "script_fields" .= sScriptFields
1405− , "_source" .= sSource
1431+ , "_source" .= sSource
1406− , "suggest" .= sSuggest]
1432+ , "suggest" .= sSuggest]
1408 where query' = case sFilter of
1434 where query' = case sFilter of
1409 Nothing -> mquery
1435 Nothing -> mquery
1410− Just x -> Just . QueryBoolQuery $ mkBoolQuery (maybeToList mquery) [x] [] []
1439+ $ mkBoolQuery (maybeToList mquery)
1412instance ToJSON Source where
1442instance ToJSON Source where
1413 toJSON NoSource = toJSON False
1443 toJSON NoSource = toJSON False
@@ -1568,10 +1598,14 @@ instance (FromJSON a) => FromJSON (Hit a) where
1568 v .: "_type" <*>
1598 v .: "_type" <*>
1569 v .: "_id" <*>
1599 v .: "_id" <*>
1570 v .: "_score" <*>
1600 v .: "_score" <*>
1571− v .:? "_source" <*>
1601+ v .:? "_source" <*>
1572 v .:? "highlight"
1603 v .:? "highlight"
1573 parseJSON _ = empty
1604 parseJSON _ = empty
1606+instance FromJSON HitFields where
1608+ = HitFields <$> parseJSON x
1576instance FromJSON DocVersion where
1610instance FromJSON DocVersion where
1577 parseJSON v = do
1611 parseJSON v = do
@@ -1579,8 +1613,6 @@ instance FromJSON DocVersion where
1579 maybe (fail "DocVersion out of range") return $ mkDocVersion i
1613 maybe (fail "DocVersion out of range") return $ mkDocVersion i
1584data Suggest = Suggest { suggestText :: Text
1616data Suggest = Suggest { suggestText :: Text
1585 , suggestName :: Text
1617 , suggestName :: Text
1586 , suggestType :: SuggestType
1618 , suggestType :: SuggestType