@@ -120,25 +120,46 @@ instance ToJSON Filter where
120120
121121instance ToJSON GeoPoint where
122122 toJSON (GeoPoint (FieldName geoField) latLon) =
123− object [geoField .= toJSON latLon]
123+ object [ geoField .= toJSON latLon ]
124124
125125
126126instance ToJSON Query where
127127 toJSON (TermQuery (Term termField termValue) boost) =
128− object ["term" .=
129− object [termField .= object merged]]
128+ object [ "term" .=
129+ object [termField .= object merged]]
130130 where
131− base = ["value" .= termValue]
131+ base = [ "value" .= termValue ]
132132 boosted = case boost of
133− (Just boostValue) -> ["boost" .= boostValue]
133+ (Just boostValue) -> [ "boost" .= boostValue ]
134134 Nothing -> []
135135 merged = mappend base boosted
136136
137137 toJSON (QueryMatchQuery matchQuery) =
138− object ["match" .= toJSON matchQuery]
138+ object [ "match" .= toJSON matchQuery ]
139139
140140 toJSON (QueryMultiMatchQuery multiMatchQuery) =
141− object ["multi_match" .= toJSON multiMatchQuery]
141+ object [ "multi_match" .= toJSON multiMatchQuery ]
142+
143+ toJSON (QueryBoolQuery boolQuery) =
144+ object [ "bool" .= toJSON boolQuery ]
145+
146+
147+mField :: (ToJSON a, Functor f) => T.Text -> f a -> f (T.Text, Value)
148+mField field = fmap ((field .=) . toJSON)
149+
150+
151+instance ToJSON BoolQuery where
152+ toJSON (BoolQuery mustM notM shouldM min boost disableCoord) =
153+ object filtered
154+ where f field = fmap ((field .=) . toJSON)
155+ filtered = catMaybes
156+ [ mField "must" mustM
157+ , mField "must_not" notM
158+ , mField "should" shouldM
159+ , mField "minimum_should_match" min
160+ , mField "boost" boost
161+ , mField "disable_coord" disableCoord ]
162+
142163
143164instance ToJSON MatchQuery where
144165 toJSON (MatchQuery (FieldName fieldName)
@@ -150,12 +171,12 @@ instance ToJSON MatchQuery where
150171 , "operator" .= toJSON booleanOperator
151172 , "zero_terms_query" .= toJSON zeroTermsQuery]
152173 ++ maybeAdd
153− f field = fmap ((field .=) . toJSON)
154− maybeAdd = catMaybes [ f "cutoff_frequency" cutoffFrequency
155− , f "type" matchQueryType
156− , f "analyzer" analyzer
157− , f "max_expansions" maxExpansions
158− , f "lenient" lenient ]
174+ maybeAdd = catMaybes [ mField "cutoff_frequency" cutoffFrequency
175+ , mField "type" matchQueryType
176+ , mField "analyzer" analyzer
177+ , mField "max_expansions" maxExpansions
178+ , mField "lenient" lenient ]
179+
159180
160181instance ToJSON MultiMatchQuery where
161182 toJSON (MultiMatchQuery fields (QueryString query) boolOp
@@ -165,15 +186,15 @@ instance ToJSON MultiMatchQuery where
165186 , "query" .= query
166187 , "operator" .= toJSON boolOp
167188 , "zero_terms_query" .= toJSON ztQ ]
168− f field = fmap ((field .=) . toJSON)
169− maybeAdd = catMaybes [ f "tiebreaker" tb
170− , f "type" mmqt
171− , f "cutoff_frequency" cf
172− , f "analyzer" analyzer
173− , f "max_expansions" maxEx
174− , f "lenient" lenient ]
189+ maybeAdd = catMaybes [ mField "tiebreaker" tb
190+ , mField "type" mmqt
191+ , mField "cutoff_frequency" cf
192+ , mField "analyzer" analyzer
193+ , mField "max_expansions" maxEx
194+ , mField "lenient" lenient ]
175195 conjoined = baseQuery ++ maybeAdd
176196
197+
177198instance ToJSON MultiMatchQueryType where
178199 toJSON MultiMatchBestFields = "best_fields"
179200 toJSON MultiMatchMostFields = "most_fields"
@@ -205,6 +226,8 @@ instance ToJSON Lenient
205226instance ToJSON Boost
206227instance ToJSON Version
207228instance ToJSON Tiebreaker
229+instance ToJSON MinimumMatch
230+instance ToJSON DisableCoord
208231instance FromJSON Version
209232instance FromJSON IndexName
210233instance FromJSON MappingName