@@ -151,6 +151,12 @@ module Database.V5.Bloodhound.Types
151 , RegexpFlag(..)
151 , RegexpFlag(..)
152 , FieldName(..)
152 , FieldName(..)
153 , Script(..)
153 , Script(..)
154+ , ScriptLanguage(..)
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
1014newtype FieldName = FieldName Text deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1014newtype FieldName = FieldName Text deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1016+type ScriptFieldName = Text
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)
1025+newtype ScriptLanguage =
1026+ ScriptLanguage Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1028+newtype ScriptInline =
1029+ ScriptInline Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1032+ ScriptId Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
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)
1038+type ScriptParamName = Text
1039+type ScriptParamValue = Value
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)
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)
1483−data FunctionScoreScript =
1484− FunctionScoreScript { functionScoreScriptInline :: Maybe FunctionScoreScriptInline
1485− , functionScoreScriptStored :: Maybe FunctionScoreScriptId
1486− , functionScoreScriptParams :: Maybe FunctionScoreScriptParams
1487− } deriving (Eq, Read, Show, Generic, Typeable)
1489−newtype FunctionScoreScriptInline =
1490− FunctionScoreScriptInline Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1492−newtype FunctionScoreScriptId =
1493− FunctionScoreScriptId Text deriving (Eq, Read, Show, Generic, Typeable, ToJSON, FromJSON)
1495−newtype FunctionScoreScriptParams =
1496− FunctionScoreScriptParams (HM.HashMap FunctionScoreScriptParamName FunctionScoreScriptParamValue)
1497− deriving (Eq, Read, Show, Generic, Typeable)
1499−type FunctionScoreScriptParamName = Text
1500−type FunctionScoreScriptParamValue = Value
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)
@@ -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)
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
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 ]
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
2969− <$> o' .:? "inline"
2973+ <*> o' .:? "inline"
2970 <*> o' .:? "stored"
2974 <*> o' .:? "stored"
2971 <*> o' .:? "params"
2975 <*> o' .:? "params"
2973−instance ToJSON FunctionScoreScriptParams where
2977+instance ToJSON ScriptParams where
2974− toJSON (FunctionScoreScriptParams x) = Object x
2978+ toJSON (ScriptParams x) = Object x
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"
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)
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]
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" <*>
3935 v .:? "highlight"
3941 v .:? "highlight"
3936 parseJSON _ = empty
3942 parseJSON _ = empty