@@ -137,6 +137,8 @@ instance ToJSON Query where
137137 toJSON (QueryMatchQuery matchQuery) =
138138 object ["match" .= toJSON matchQuery]
139139
140+ toJSON (QueryMultiMatchQuery multiMatchQuery) =
141+ object ["multi_match" .= toJSON multiMatchQuery]
140142
141143instance ToJSON MatchQuery where
142144 toJSON (MatchQuery (FieldName fieldName)
@@ -155,6 +157,29 @@ instance ToJSON MatchQuery where
155157 , f "max_expansions" maxExpansions
156158 , f "lenient" lenient ]
157159
160+instance ToJSON MultiMatchQuery where
161+ toJSON (MultiMatchQuery fields (QueryString query) boolOp
162+ ztQ tb mmqt cf analyzer maxEx lenient) =
163+ object ["multi_match" .= object conjoined]
164+ where baseQuery = [ "fields" .= fmap toJSON fields
165+ , "query" .= query
166+ , "operator" .= toJSON boolOp
167+ , "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 ]
175+ conjoined = baseQuery ++ maybeAdd
176+
177+instance ToJSON MultiMatchQueryType where
178+ toJSON MultiMatchBestFields = "best_fields"
179+ toJSON MultiMatchMostFields = "most_fields"
180+ toJSON MultiMatchCrossFields = "cross_fields"
181+ toJSON MultiMatchPhrase = "phrase"
182+ toJSON MultiMatchPhrasePrefix = "phrase_prefix"
158183
159184instance ToJSON BooleanOperator where
160185 toJSON And = String "and"
@@ -168,6 +193,9 @@ instance ToJSON MatchQueryType where
168193 toJSON MatchPhrase = "phrase"
169194 toJSON MatchPhrasePrefix = "phrase_prefix"
170195
196+instance ToJSON FieldName where
197+ toJSON (FieldName fieldName) = String fieldName
198+
171199instance ToJSON ReplicaCount
172200instance ToJSON ShardCount
173201instance ToJSON CutoffFrequency
@@ -176,6 +204,7 @@ instance ToJSON MaxExpansions
176204instance ToJSON Lenient
177205instance ToJSON Boost
178206instance ToJSON Version
207+instance ToJSON Tiebreaker
179208instance FromJSON Version
180209instance FromJSON IndexName
181210instance FromJSON MappingName
@@ -233,6 +262,11 @@ instance ToJSON SortSpec where
233262 lNestedFilter = maybeJson "nested_filter" nestedFilter
234263 merged = mconcat [base, lSortMode, lMissingSort, lNestedFilter]
235264
265+ toJSON (GeoDistanceSortSpec sortOrder (GeoPoint (FieldName field) latLon) units) =
266+ object [ "unit" .= toJSON units
267+ , field .= toJSON latLon
268+ , "order" .= toJSON sortOrder ]
269+
236270
237271instance ToJSON SortOrder where
238272 toJSON Ascending = String "asc"