git.iko.soy/typeable/bloodhound
on master help sign in
Clean up script fields.
2be0cb9Will Jones
src/Database/V5/Bloodhound/Client.hs+3−3
@@ -1044,7 +1044,7 @@ scanSearch indexName mappingName search = do
1044-- >>> mkSearch (Just query) Nothing
1044-- >>> mkSearch (Just query) Nothing
1045-- Search {queryBody = Just (TermQuery (Term {termField = "user", termValue = "bitemyapp"}) Nothing), filterBody = Nothing, sortBody = Nothing, aggBody = Nothing, highlight = Nothing, trackSortScores = False, from = From 0, size = Size 10, searchType = SearchTypeQueryThenFetch, fields = Nothing, source = Nothing}
1045-- Search {queryBody = Just (TermQuery (Term {termField = "user", termValue = "bitemyapp"}) Nothing), filterBody = Nothing, sortBody = Nothing, aggBody = Nothing, highlight = Nothing, trackSortScores = False, from = From 0, size = Size 10, searchType = SearchTypeQueryThenFetch, fields = Nothing, source = Nothing}
1046mkSearch :: Maybe Query -> Maybe Filter -> Search
1046mkSearch :: Maybe Query -> Maybe Filter -> Search
1047−mkSearch query filter = Search query filter Nothing Nothing Nothing False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing Nothing
1047+mkSearch query filter = Search query filter Nothing Nothing Nothing False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing Nothing Nothing
1048
1048
1049-- | 'mkAggregateSearch' is a helper function that defaults everything in a 'Search' except for
1049-- | 'mkAggregateSearch' is a helper function that defaults everything in a 'Search' except for
1050-- the 'Query' and the 'Aggregation'.
1050-- the 'Query' and the 'Aggregation'.
@@ -1054,7 +1054,7 @@ mkSearch query filter = Search query filter Nothing Nothing Nothing False (From
1054-- TermsAgg (TermsAggregation {term = Left "user", termInclude = Nothing, termExclude = Nothing, termOrder = Nothing, termMinDocCount = Nothing, termSize = Nothing, termShardSize = Nothing, termCollectMode = Just BreadthFirst, termExecutionHint = Nothing, termAggs = Nothing})
1054-- TermsAgg (TermsAggregation {term = Left "user", termInclude = Nothing, termExclude = Nothing, termOrder = Nothing, termMinDocCount = Nothing, termSize = Nothing, termShardSize = Nothing, termCollectMode = Just BreadthFirst, termExecutionHint = Nothing, termAggs = Nothing})
1055-- >>> let myAggregation = mkAggregateSearch Nothing $ mkAggregations "users" terms
1055-- >>> let myAggregation = mkAggregateSearch Nothing $ mkAggregations "users" terms
1056mkAggregateSearch :: Maybe Query -> Aggregations -> Search
1056mkAggregateSearch :: Maybe Query -> Aggregations -> Search
1057−mkAggregateSearch query mkSearchAggs = Search query Nothing Nothing (Just mkSearchAggs) Nothing False (From 0) (Size 0) SearchTypeQueryThenFetch Nothing Nothing Nothing
1057+mkAggregateSearch query mkSearchAggs = Search query Nothing Nothing (Just mkSearchAggs) Nothing False (From 0) (Size 0) SearchTypeQueryThenFetch Nothing Nothing Nothing Nothing
1058
1058
1059-- | 'mkHighlightSearch' is a helper function that defaults everything in a 'Search' except for
1059-- | 'mkHighlightSearch' is a helper function that defaults everything in a 'Search' except for
1060-- the 'Query' and the 'Aggregation'.
1060-- the 'Query' and the 'Aggregation'.
@@ -1063,7 +1063,7 @@ mkAggregateSearch query mkSearchAggs = Search query Nothing Nothing (Just mkSear
1063-- >>> let testHighlight = Highlights Nothing [FieldHighlight (FieldName "message") Nothing]
1063-- >>> let testHighlight = Highlights Nothing [FieldHighlight (FieldName "message") Nothing]
1064-- >>> let search = mkHighlightSearch (Just query) testHighlight
1064-- >>> let search = mkHighlightSearch (Just query) testHighlight
1065mkHighlightSearch :: Maybe Query -> Highlights -> Search
1065mkHighlightSearch :: Maybe Query -> Highlights -> Search
1066−mkHighlightSearch query searchHighlights = Search query Nothing Nothing Nothing (Just searchHighlights) False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing Nothing
1066+mkHighlightSearch query searchHighlights = Search query Nothing Nothing Nothing (Just searchHighlights) False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing Nothing Nothing
1067
1067
1068-- | 'pageSearch' is a helper function that takes a search and assigns the from
1068-- | 'pageSearch' is a helper function that takes a search and assigns the from
1069-- and size fields for the search. The from parameter defines the offset
1069-- and size fields for the search. The from parameter defines the offset
src/Database/V5/Bloodhound/Types.hs+61−55
@@ -151,6 +151,12 @@ module Database.V5.Bloodhound.Types
151 , RegexpFlag(..)
151 , RegexpFlag(..)
152 , FieldName(..)
152 , FieldName(..)
153 , Script(..)
153 , Script(..)
154+ , ScriptLanguage(..)
155+ , ScriptInline(..)
156+ , ScriptId(..)
157+ , ScriptParams(..)
158+ , ScriptParamName
159+ , ScriptParamValue
154 , IndexName(..)
160 , IndexName(..)
155 , IndexSelection(..)
161 , IndexSelection(..)
156 , NodeSelection(..)
162 , NodeSelection(..)
@@ -186,12 +192,6 @@ module Database.V5.Bloodhound.Types
186 , FunctionScoreFunctions(..)
192 , FunctionScoreFunctions(..)
187 , ComponentFunctionScoreFunction(..)
193 , ComponentFunctionScoreFunction(..)
188 , FunctionScoreFunction(..)
194 , FunctionScoreFunction(..)
189− , FunctionScoreScript(..)
190− , FunctionScoreScriptInline(..)
191− , FunctionScoreScriptId(..)
192− , FunctionScoreScriptParams(..)
193− , FunctionScoreScriptParamName
194− , FunctionScoreScriptParamValue
195 , Weight(..)
195 , Weight(..)
196 , Seed(..)
196 , Seed(..)
197 , FieldValueFactor(..)
197 , FieldValueFactor(..)
@@ -1013,11 +1013,30 @@ newtype QueryString = QueryString Text deriving (Eq, Generic, Read, Show, ToJSON
1013-}
1013-}
1014newtype FieldName = FieldName Text deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1014newtype FieldName = FieldName Text deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1015
1015
1016+type ScriptFieldName = Text
1016
1017
1017−{-| 'Script' is often used in place of 'FieldName' to specify more
1018+data Script =
1018−complex ways of extracting a value from a document.
1019+ Script { scriptLanguage :: Maybe ScriptLanguage
1019−-}
1020+ , scriptInline :: Maybe ScriptInline
1021+ , scriptStored :: Maybe ScriptId
1022+ , scriptParams :: Maybe ScriptParams
1023+ } deriving (Eq, Read, Show, Generic, Typeable)
1024+
1025+newtype ScriptLanguage =
1026+ ScriptLanguage Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1027+
1028+newtype ScriptInline =
1029+ ScriptInline Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1030+
1031+newtype ScriptId =
1032+ ScriptId Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1033+
1034+newtype ScriptParams =
1035+ ScriptParams (HM.HashMap ScriptParamName ScriptParamValue)
1020−newtype Script = Script { scriptText :: Text } deriving (Eq, Read, Show, Generic, Typeable)
1036+ deriving (Eq, Read, Show, Generic, Typeable)
1037+
1038+type ScriptParamName = Text
1039+type ScriptParamValue = Value
1021
1040
1022{-| 'CacheName' is used in 'RegexpFilter' for describing the
1041{-| 'CacheName' is used in 'RegexpFilter' for describing the
1023 'CacheKey' keyed caching behavior.
1042 'CacheKey' keyed caching behavior.
@@ -1138,6 +1157,7 @@ data Search = Search { queryBody :: Maybe Query
1138 , size :: Size
1157 , size :: Size
1139 , searchType :: SearchType
1158 , searchType :: SearchType
1140 , fields :: Maybe [FieldName]
1159 , fields :: Maybe [FieldName]
1160+ , scriptFields :: Maybe (HM.HashMap ScriptFieldName Script)
1141 , source :: Maybe Source
1161 , source :: Maybe Source
1142 , suggestBody :: Maybe Suggest -- ^ Only one Suggestion request / response per Search is supported.
1162 , suggestBody :: Maybe Suggest -- ^ Only one Suggestion request / response per Search is supported.
1143 } deriving (Eq, Read, Show, Generic, Typeable)
1163 } deriving (Eq, Read, Show, Generic, Typeable)
@@ -1475,30 +1495,11 @@ data ComponentFunctionScoreFunction =
1475 } deriving (Eq, Read, Show, Generic, Typeable)
1495 } deriving (Eq, Read, Show, Generic, Typeable)
1476
1496
1477data FunctionScoreFunction =
1497data FunctionScoreFunction =
1478− FunctionScoreFunctionScript FunctionScoreScript
1498+ FunctionScoreFunctionScript Script
1479 | FunctionScoreFunctionRandom Seed
1499 | FunctionScoreFunctionRandom Seed
1480 | FunctionScoreFunctionFieldValueFactor FieldValueFactor
1500 | FunctionScoreFunctionFieldValueFactor FieldValueFactor
1481 deriving (Eq, Read, Show, Generic, Typeable)
1501 deriving (Eq, Read, Show, Generic, Typeable)
1482
1502
1483−data FunctionScoreScript =
1484− FunctionScoreScript { functionScoreScriptInline :: Maybe FunctionScoreScriptInline
1485− , functionScoreScriptStored :: Maybe FunctionScoreScriptId
1486− , functionScoreScriptParams :: Maybe FunctionScoreScriptParams
1487− } deriving (Eq, Read, Show, Generic, Typeable)
1488−
1489−newtype FunctionScoreScriptInline =
1490− FunctionScoreScriptInline Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1491−
1492−newtype FunctionScoreScriptId =
1493− FunctionScoreScriptId Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1494−
1495−newtype FunctionScoreScriptParams =
1496− FunctionScoreScriptParams (HM.HashMap FunctionScoreScriptParamName FunctionScoreScriptParamValue)
1497− deriving (Eq, Read, Show, Generic, Typeable)
1498−
1499−type FunctionScoreScriptParamName = Text
1500−type FunctionScoreScriptParamValue = Value
1501−
1502newtype Weight =
1503newtype Weight =
1503 Weight Float deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1504 Weight Float deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1504
1505
@@ -1814,6 +1815,7 @@ data Hit a =
1814 , hitDocId :: DocId
1815 , hitDocId :: DocId
1815 , hitScore :: Score
1816 , hitScore :: Score
1816 , hitSource :: Maybe a
1817 , hitSource :: Maybe a
1818+ , hitFields :: Maybe (HM.HashMap Text [Value])
1817 , hitHighlight :: Maybe HitHighlight } deriving (Eq, Read, Show, Generic, Typeable)
1819 , hitHighlight :: Maybe HitHighlight } deriving (Eq, Read, Show, Generic, Typeable)
1818
1820
1819data ShardResult =
1821data ShardResult =
@@ -2092,7 +2094,7 @@ instance ToJSON Aggregation where
2092 toJSON (ValueCountAgg a) = object ["value_count" .= v]
2094 toJSON (ValueCountAgg a) = object ["value_count" .= v]
2093 where v = case a of
2095 where v = case a of
2094 (FieldValueCount (FieldName n)) -> object ["field" .= n]
2096 (FieldValueCount (FieldName n)) -> object ["field" .= n]
2095− (ScriptValueCount (Script s)) -> object ["script" .= s]
2097+ (ScriptValueCount s) -> object ["script" .= s]
2096 toJSON (FilterAgg (FilterAggregation filt ags)) =
2098 toJSON (FilterAgg (FilterAggregation filt ags)) =
2097 omitNulls [ "filter" .= filt
2099 omitNulls [ "filter" .= filt
2098 , "aggs" .= ags]
2100 , "aggs" .= ags]
@@ -2955,27 +2957,29 @@ parseFunctionScoreFunction o =
2955 singleRandom o' = FunctionScoreFunctionRandom <$> o' .: "seed"
2957 singleRandom o' = FunctionScoreFunctionRandom <$> o' .: "seed"
2956 singleFieldValueFactor = pure . FunctionScoreFunctionFieldValueFactor
2958 singleFieldValueFactor = pure . FunctionScoreFunctionFieldValueFactor
2957
2959
2958−instance ToJSON FunctionScoreScript where
2960+instance ToJSON Script where
2959− toJSON (FunctionScoreScript inline stored params) =
2961+ toJSON (Script lang inline stored params) =
2960 object [ "script" .= omitNulls base ]
2962 object [ "script" .= omitNulls base ]
2963+ where base = [ "lang" .= lang
2961− where base = [ "inline" .= inline
2964+ , "inline" .= inline
2962 , "stored" .= stored
2965 , "stored" .= stored
2963 , "params" .= params ]
2966 , "params" .= params ]
2964
2967
2965−instance FromJSON FunctionScoreScript where
2968+instance FromJSON Script where
2966− parseJSON = withObject "FunctionScoreScript" parse
2969+ parseJSON = withObject "Script" parse
2967 where parse o = o .: "script" >>= \o' ->
2970 where parse o = o .: "script" >>= \o' ->
2968− FunctionScoreScript
2971+ Script
2972+ <$> o' .:? "lang"
2969− <$> o' .:? "inline"
2973+ <*> o' .:? "inline"
2970 <*> o' .:? "stored"
2974 <*> o' .:? "stored"
2971 <*> o' .:? "params"
2975 <*> o' .:? "params"
2972
2976
2973−instance ToJSON FunctionScoreScriptParams where
2977+instance ToJSON ScriptParams where
2974− toJSON (FunctionScoreScriptParams x) = Object x
2978+ toJSON (ScriptParams x) = Object x
2975
2979
2976−instance FromJSON FunctionScoreScriptParams where
2980+instance FromJSON ScriptParams where
2977− parseJSON (Object o) = pure (FunctionScoreScriptParams o)
2981+ parseJSON (Object o) = pure (ScriptParams o)
2978− parseJSON _ = fail "error parsing FunctionScoreScriptParams"
2982+ parseJSON _ = fail "error parsing ScriptParams"
2979
2983
2980instance ToJSON FieldValueFactor where
2984instance ToJSON FieldValueFactor where
2981 toJSON (FieldValueFactor field factor modifier missing) =
2985 toJSON (FieldValueFactor field factor modifier missing) =
@@ -3551,17 +3555,18 @@ instance FromJSON SearchAliasRouting where
3551 where parse t = SearchAliasRouting <$> parseNEJSON (String <$> T.splitOn "," t)
3555 where parse t = SearchAliasRouting <$> parseNEJSON (String <$> T.splitOn "," t)
3552
3556
3553instance ToJSON Search where
3557instance ToJSON Search where
3554− toJSON (Search mquery sFilter sort searchAggs highlight sTrackSortScores sFrom sSize _ sFields sSource sSuggest) =
3558+ toJSON (Search mquery sFilter sort searchAggs highlight sTrackSortScores sFrom sSize _ sFields sScriptFields sSource sSuggest) =
3555− omitNulls [ "query" .= query'
3559+ omitNulls [ "query" .= query'
3556− , "sort" .= sort
3560+ , "sort" .= sort
3557− , "aggregations" .= searchAggs
3561+ , "aggregations" .= searchAggs
3558− , "highlight" .= highlight
3562+ , "highlight" .= highlight
3559− , "from" .= sFrom
3563+ , "from" .= sFrom
3560− , "size" .= sSize
3564+ , "size" .= sSize
3561− , "track_scores" .= sTrackSortScores
3565+ , "track_scores" .= sTrackSortScores
3562− , "fields" .= sFields
3566+ , "fields" .= sFields
3567+ , "script_fields" .= sScriptFields
3563− , "_source" .= sSource
3568+ , "_source" .= sSource
3564− , "suggest" .= sSuggest]
3569+ , "suggest" .= sSuggest]
3565
3570
3566 where query' = case sFilter of
3571 where query' = case sFilter of
3567 Nothing -> mquery
3572 Nothing -> mquery
@@ -3931,7 +3936,8 @@ instance (FromJSON a) => FromJSON (Hit a) where
3931 v .: "_type" <*>
3936 v .: "_type" <*>
3932 v .: "_id" <*>
3937 v .: "_id" <*>
3933 v .: "_score" <*>
3938 v .: "_score" <*>
3934− v .:? "_source" <*>
3939+ v .:? "_source" <*>
3940+ v .:? "fields" <*>
3935 v .:? "highlight"
3941 v .:? "highlight"
3936 parseJSON _ = empty
3942 parseJSON _ = empty
3937
3943