@@ -143,15 +143,183 @@ instance ToJSON Query where
143 object [ "bool" .= toJSON boolQuery ]
143 object [ "bool" .= toJSON boolQuery ]
145 toJSON (QueryBoostingQuery boostingQuery) =
145 toJSON (QueryBoostingQuery boostingQuery) =
146− object ["boosting" .= toJSON boostingQuery]
146+ object [ "boosting" .= toJSON boostingQuery ]
148 toJSON (QueryCommonTermsQuery commonTermsQuery) =
148 toJSON (QueryCommonTermsQuery commonTermsQuery) =
149− object ["common" .= toJSON commonTermsQuery]
149+ object [ "common" .= toJSON commonTermsQuery ]
151+ toJSON (ConstantScoreFilter filter boost) =
152+ object [ "constant_score" .= toJSON filter
153+ , "boost" .= toJSON boost]
155+ toJSON (ConstantScoreQuery query boost) =
156+ object [ "constant_score" .= toJSON filter
157+ , "boost" .= toJSON boost]
159+ toJSON (QueryDisMaxQuery disMaxQuery) =
160+ object [ "dis_max" .= toJSON disMaxQuery ]
162+ toJSON (QueryFilteredQuery filteredQuery) =
163+ object [ "filtered" .= toJSON filteredQuery ]
165+ toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
166+ object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
168+ toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
169+ object [ "fuzzy_like_this_field" .= toJSON fuzzyFieldQuery ]
171+ toJSON (QueryFuzzyQuery fuzzyQuery) =
172+ object [ "fuzzy" .= toJSON fuzzyQuery ]
174+ toJSON (QueryHasChildQuery childQuery) =
175+ object [ "has_child" .= toJSON childQuery ]
177+ toJSON (QueryHasParentQuery parentQuery) =
178+ object [ "has_parent" .= toJSON parentQuery ]
180+ toJSON (QueryIndicesQuery indicesQuery) =
181+ object [ "indices" .= toJSON indicesQuery ]
183+ toJSON (MatchAllQuery boost) =
184+ object [ "match_all" .= object maybeAdd ]
185+ where maybeAdd catMaybes [ mField "boost" boost ]
187+ toJSON (QueryMoreLikeThisQuery query) =
188+ object [ "more_like_this" .= toJSON query ]
190+ toJSON (QueryMoreLikeThisFieldQuery query) =
191+ object [ "more_like_this_field" .= toJSON query ]
193+ toJSON (QueryNestedQuery query) =
194+ object [ "nested" .= toJSON query ]
151mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
197mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
152mField field = fmap ((field .=) . toJSON)
198mField field = fmap ((field .=) . toJSON)
201+instance NestedQuery where
202+ toJSON (NestedQuery path scoreType query) =
203+ object [ "path" .= toJSON path
204+ , "score_mode" .= toJSON scoreType
205+ , "query" .= toJSON query ]
208+instance MoreLikeThisFieldQuery where
209+ toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
210+ percent mtf mqt stopwords mindf maxdf
211+ minwl maxwl boostTerms boost analyzer) =
212+ object [ fieldName .= object conjoined ]
213+ where base = [ "like_text" .= toJSON text ]
214+ maybeAdd = catMaybes [ mField "fields" fields
215+ , mField "percent_terms_to_match" percent
216+ , mField "min_term_freq" mtf
217+ , mField "max_query_terms" mqt
218+ , mField "stop_words" stopwords
219+ , mField "min_doc_freq" mindf
220+ , mField "max_doc_freq" maxdf
221+ , mField "min_word_length" minwl
222+ , mField "max_word_length" maxwl
223+ , mField "boost_terms" boostTerms
224+ , mField "boost" boost
225+ , mField "analyzer" analyzer ]
226+ conjoined = base ++ maybeAdd
229+instance ToJSON MoreLikeThisQuery where
230+ toJSON (MoreLikeThisQuery text fields percent
231+ mtf mqt stopwords mindf maxdf
232+ minwl maxwl boostTerms boost analyzer) =
234+ where base = [ "like_text" .= toJSON text ]
235+ maybeAdd = catMaybes [ mField "fields" fields
236+ , mField "percent_terms_to_match" percent
237+ , mField "min_term_freq" mtf
238+ , mField "max_query_terms" mqt
239+ , mField "stop_words" stopwords
240+ , mField "min_doc_freq" mindf
241+ , mField "max_doc_freq" maxdf
242+ , mField "min_word_length" minwl
243+ , mField "max_word_length" maxwl
244+ , mField "boost_terms" boostTerms
245+ , mField "boost" boost
246+ , mField "analyzer" analyzer ]
247+ conjoined = base ++ maybeAdd
250+instance ToJSON IndicesQuery where
251+ toJSON (IndicesQuery indices query noMatch) =
252+ object [ "indices" .= toJSON indices
253+ , "query" .= toJSON query ] ++ maybeAdd
254+ where maybeAdd = catMaybes [ mField "no_match_query" noMatch ]
257+instance ToJSON HasParentQuery where
258+ toJSON (HasParentQuery queryType query scoreType) =
259+ object [ "parent_type" .= toJSON queryType
260+ , "query" .= toJSON query ] ++ maybeAdd
261+ where maybeAdd = catMaybes [ mField "score_type" scoreType ]
264+instance ToJSON HasChildQuery where
265+ toJSON (HasChildQuery queryType query scoreType) =
266+ object [ "query" .= toJSON query
267+ , "type" .= toJSON queryType ] ++ maybeAdd
268+ where maybeAdd = catMaybes [ mField "score_type" scoreType ]
271+instance ToJSON FuzzyQuery where
272+ toJSON (FuzzyQuery (FieldName fieldName) queryText
273+ prefixLength maxEx fuzziness boost) =
274+ object [ fieldName .= object conjoined ]
275+ where base = [ "value" .= toJSON queryText
276+ , "fuzziness" .= toJSON fuzziness
277+ , "prefix_length" .= toJSON prefixLength
278+ , "max_expansions" .= toJSON maxEx ]
279+ maybeAdd = catMaybes [ mField "boost" boost ]
280+ conjoined = base ++ maybeAdd
283+instance ToJSON FuzzyLikeFieldQuery where
284+ toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
285+ fieldText maxTerms ignoreFreq fuzziness prefixLength
287+ object [ fieldName .=
288+ object [ "like_text" .= toJSON fieldText
289+ , "max_query_terms" .= toJSON maxTerms
290+ , "ignore_tf" .= toJSON ignoreFreq
291+ , "fuzziness" .= toJSON fuzziness
292+ , "prefix_length" .= toJSON prefixLength
293+ , "boost" .= toJSON boost ]] ++ maybeAdd
294+ where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
297+instance ToJSON FuzzyLikeThisQuery where
298+ toJSON (FuzzyLikeThisQuery fields text maxTerms
299+ ignoreFreq fuzziness prefixLength boost analyzer) =
300+ object [ "fields" .= toJSON fields
301+ , "like_text" .= toJSON text
302+ , "max_query_terms" .= toJSON maxTerms
303+ , "ignore_tf" .= toJSON ignoreFreq
304+ , "fuzziness" .= toJSON fuzziness
305+ , "prefix_length" .= toJSON prefixLength
306+ , "boost" .= toJSON boost ] ++ maybeAdd
307+ where maybeAdd = catMaybes [ mField "analyzer" analyzer ]
310+instance ToJSON FilteredQuery where
311+ toJSON (FilteredQuery query filter) =
312+ object [ "query" .= toJSON query
313+ , "filter" .= toJSON filter ]
316+instance ToJSON DisMaxQuery where
317+ toJSON (DisMaxQuery queries tiebreaker boost) =
318+ object [ "queries" .= toJSON queries
319+ , "tie_breaker" .= toJSON tiebreaker ] ++ maybeAdd
320+ where maybeAdd = catMaybes [mField "boost" boost]
155instance ToJSON CommonTermsQuery where
323instance ToJSON CommonTermsQuery where
156 toJSON (CommonTermsQuery (FieldName fieldName)
324 toJSON (CommonTermsQuery (FieldName fieldName)
157 (QueryString query) cf lfo hfo msm
325 (QueryString query) cf lfo hfo msm