@@ -153,7 +153,7 @@ instance ToJSON Query where
153 , "boost" .= toJSON boost]
153 , "boost" .= toJSON boost]
155 toJSON (ConstantScoreQuery query boost) =
155 toJSON (ConstantScoreQuery query boost) =
156− object [ "constant_score" .= toJSON filter
156+ object [ "constant_score" .= toJSON query
157 , "boost" .= toJSON boost]
157 , "boost" .= toJSON boost]
159 toJSON (QueryDisMaxQuery disMaxQuery) =
159 toJSON (QueryDisMaxQuery disMaxQuery) =
@@ -182,7 +182,7 @@ instance ToJSON Query where
183 toJSON (MatchAllQuery boost) =
183 toJSON (MatchAllQuery boost) =
184 object [ "match_all" .= object maybeAdd ]
184 object [ "match_all" .= object maybeAdd ]
185− where maybeAdd catMaybes [ mField "boost" boost ]
185+ where maybeAdd = catMaybes [ mField "boost" boost ]
187 toJSON (QueryMoreLikeThisQuery query) =
187 toJSON (QueryMoreLikeThisQuery query) =
188 object [ "more_like_this" .= toJSON query ]
188 object [ "more_like_this" .= toJSON query ]
@@ -201,29 +201,28 @@ mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
201mField field = fmap ((field .=) . toJSON)
201mField field = fmap ((field .=) . toJSON)
204−instance PrefixQuery where
204+instance ToJSON PrefixQuery where
205 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
205 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
206 object [ fieldName .= object conjoined ]
206 object [ fieldName .= object conjoined ]
207 where base = [ "value" .= toJSON queryValue ]
207 where base = [ "value" .= toJSON queryValue ]
208− maybeAdd = [ mField "boost" boost ]
208+ maybeAdd = catMaybes [ mField "boost" boost ]
209 conjoined = base ++ maybeAdd
209 conjoined = base ++ maybeAdd
212−instance NestedQuery where
212+instance ToJSON NestedQuery where
213 toJSON (NestedQuery path scoreType query) =
213 toJSON (NestedQuery path scoreType query) =
214 object [ "path" .= toJSON path
214 object [ "path" .= toJSON path
215 , "score_mode" .= toJSON scoreType
215 , "score_mode" .= toJSON scoreType
216 , "query" .= toJSON query ]
216 , "query" .= toJSON query ]
219−instance MoreLikeThisFieldQuery where
219+instance ToJSON MoreLikeThisFieldQuery where
220 toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
220 toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
221 percent mtf mqt stopwords mindf maxdf
221 percent mtf mqt stopwords mindf maxdf
222 minwl maxwl boostTerms boost analyzer) =
222 minwl maxwl boostTerms boost analyzer) =
223 object [ fieldName .= object conjoined ]
223 object [ fieldName .= object conjoined ]
224 where base = [ "like_text" .= toJSON text ]
224 where base = [ "like_text" .= toJSON text ]
225− maybeAdd = catMaybes [ mField "fields" fields
226− , mField "percent_terms_to_match" percent
225+ maybeAdd = catMaybes [ mField "percent_terms_to_match" percent
227 , mField "min_term_freq" mtf
226 , mField "min_term_freq" mtf
228 , mField "max_query_terms" mqt
227 , mField "max_query_terms" mqt
229 , mField "stop_words" stopwords
228 , mField "stop_words" stopwords
@@ -260,22 +259,22 @@ instance ToJSON MoreLikeThisQuery where
261instance ToJSON IndicesQuery where
260instance ToJSON IndicesQuery where
262 toJSON (IndicesQuery indices query noMatch) =
261 toJSON (IndicesQuery indices query noMatch) =
263− object [ "indices" .= toJSON indices
262+ object $ [ "indices" .= toJSON indices
264− , "query" .= toJSON query ] ++ maybeAdd
263+ , "query" .= toJSON query ] ++ maybeAdd
265 where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
264 where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
268instance ToJSON HasParentQuery where
267instance ToJSON HasParentQuery where
269 toJSON (HasParentQuery queryType query scoreType) =
268 toJSON (HasParentQuery queryType query scoreType) =
270− object [ "parent_type" .= toJSON queryType
269+ object $ [ "parent_type" .= toJSON queryType
271− , "query" .= toJSON query ] ++ maybeAdd
270+ , "query" .= toJSON query ] ++ maybeAdd
272 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
271 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
275instance ToJSON HasChildQuery where
274instance ToJSON HasChildQuery where
276 toJSON (HasChildQuery queryType query scoreType) =
275 toJSON (HasChildQuery queryType query scoreType) =
277− object [ "query" .= toJSON query
276+ object $ [ "query" .= toJSON query
278− , "type" .= toJSON queryType ] ++ maybeAdd
277+ , "type" .= toJSON queryType ] ++ maybeAdd
279 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
278 where maybeAdd = catMaybes [ mField "score_type" scoreType ]
@@ -295,27 +294,29 @@ instance ToJSON FuzzyLikeFieldQuery where
295 toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
294 toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
296 fieldText maxTerms ignoreFreq fuzziness prefixLength
295 fieldText maxTerms ignoreFreq fuzziness prefixLength
297 boost analyzer) =
296 boost analyzer) =
298− object [ fieldName .=
297+ object $ [ fieldName .=
299− object [ "like_text" .= toJSON fieldText
298+ object [ "like_text" .= toJSON fieldText
300− , "max_query_terms" .= toJSON maxTerms
299+ , "max_query_terms" .= toJSON maxTerms
301− , "ignore_tf" .= toJSON ignoreFreq
300+ , "ignore_tf" .= toJSON ignoreFreq
302− , "fuzziness" .= toJSON fuzziness
301+ , "fuzziness" .= toJSON fuzziness
303− , "prefix_length" .= toJSON prefixLength
302+ , "prefix_length" .= toJSON prefixLength
304− , "boost" .= toJSON boost ]] ++ maybeAdd
303+ , "boost" .= toJSON boost ]] ++ maybeAdd
305 where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
304 where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
308instance ToJSON FuzzyLikeThisQuery where
307instance ToJSON FuzzyLikeThisQuery where
309 toJSON (FuzzyLikeThisQuery fields text maxTerms
308 toJSON (FuzzyLikeThisQuery fields text maxTerms
310 ignoreFreq fuzziness prefixLength boost analyzer) =
309 ignoreFreq fuzziness prefixLength boost analyzer) =
311− object [ "fields" .= toJSON fields
311+ where base = [ "fields" .= toJSON fields
312− , "like_text" .= toJSON text
312+ , "like_text" .= toJSON text
313− , "max_query_terms" .= toJSON maxTerms
313+ , "max_query_terms" .= toJSON maxTerms
314− , "ignore_tf" .= toJSON ignoreFreq
314+ , "ignore_tf" .= toJSON ignoreFreq
315− , "fuzziness" .= toJSON fuzziness
315+ , "fuzziness" .= toJSON fuzziness
316− , "prefix_length" .= toJSON prefixLength
316+ , "prefix_length" .= toJSON prefixLength
317− , "boost" .= toJSON boost ] ++ maybeAdd
317+ , "boost" .= toJSON boost ]
318− where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
318+ maybeAdd = catMaybes [ mField "analyzer" analyzer ]
319+ conjoined = base ++ maybeAdd
321instance ToJSON FilteredQuery where
322instance ToJSON FilteredQuery where
@@ -326,9 +327,11 @@ instance ToJSON FilteredQuery where
327instance ToJSON DisMaxQuery where
328instance ToJSON DisMaxQuery where
328 toJSON (DisMaxQuery queries tiebreaker boost) =
329 toJSON (DisMaxQuery queries tiebreaker boost) =
329− object [ "queries" .= toJSON queries
330+ object conjoined
330− , "tie_breaker" .= toJSON tiebreaker ] ++ maybeAdd
331 where maybeAdd = catMaybes [mField "boost" boost]
331 where maybeAdd = catMaybes [mField "boost" boost]
332+ base = [ "queries" .= toJSON queries
333+ , "tie_breaker" .= toJSON tiebreaker ]
334+ conjoined = base ++ maybeAdd
334instance ToJSON CommonTermsQuery where
337instance ToJSON CommonTermsQuery where
@@ -440,6 +443,22 @@ instance ToJSON Version
440instance ToJSON Tiebreaker
443instance ToJSON Tiebreaker
441instance ToJSON MinimumMatch
444instance ToJSON MinimumMatch
442instance ToJSON DisableCoord
445instance ToJSON DisableCoord
446+instance ToJSON PrefixLength
447+instance ToJSON Fuzziness
448+instance ToJSON IgnoreTermFrequency
449+instance ToJSON MaxQueryTerms
450+instance ToJSON TypeName
451+instance ToJSON IndexName
452+instance ToJSON BoostTerms
453+instance ToJSON MaxWordLength
454+instance ToJSON MinWordLength
455+instance ToJSON MaxDocFrequency
456+instance ToJSON MinDocFrequency
457+instance ToJSON PhraseSlop
458+instance ToJSON StopWord
459+instance ToJSON QueryPath
460+instance ToJSON MinimumTermFrequency
461+instance ToJSON PercentMatch
443instance FromJSON Version
462instance FromJSON Version
444instance FromJSON IndexName
463instance FromJSON IndexName
445instance FromJSON MappingName
464instance FromJSON MappingName
@@ -521,6 +540,13 @@ instance ToJSON Missing where
521 toJSON (CustomMissing txt) = String txt
540 toJSON (CustomMissing txt) = String txt
543+instance ToJSON ScoreType where
544+ toJSON ScoreTypeMax = "max"
545+ toJSON ScoreTypeAvg = "avg"
546+ toJSON ScoreTypeSum = "sum"
547+ toJSON ScoreTypeNone = "none"
524instance ToJSON Distance where
550instance ToJSON Distance where
525 toJSON (Distance coefficient unit) =
551 toJSON (Distance coefficient unit) =
526 String boltedTogether where
552 String boltedTogether where