@@ -624,11 +624,11 @@ data BooleanOperator = And | Or deriving (Eq, Show)
624624
625625{-| 'ShardCount' is part of 'IndexSettings'
626626-}
627−newtype ShardCount = ShardCount Int deriving (Eq, Show, Generic)
627+newtype ShardCount = ShardCount Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
628628
629629{-| 'ReplicaCount' is part of 'IndexSettings'
630630-}
631−newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic)
631+newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
632632
633633{-| 'Server' is used with the client functions to point at the ES instance
634634-}
@@ -636,35 +636,35 @@ newtype Server = Server Text deriving (Eq, Show)
636636
637637{-| 'IndexName' is used to describe which index to query/create/delete
638638-}
639−newtype IndexName = IndexName Text deriving (Eq, Generic, Show)
639+newtype IndexName = IndexName Text deriving (Eq, Generic, Show, ToJSON, FromJSON)
640640
641641{-| 'TemplateName' is used to describe which template to query/create/delete
642642-}
643−newtype TemplateName = TemplateName Text deriving (Eq, Show, Generic)
643+newtype TemplateName = TemplateName Text deriving (Eq, Show, Generic, ToJSON, FromJSON)
644644
645645{-| 'TemplatePattern' represents a pattern which is matched against index names
646646-}
647−newtype TemplatePattern = TemplatePattern Text deriving (Eq, Show, Generic)
647+newtype TemplatePattern = TemplatePattern Text deriving (Eq, Show, Generic, ToJSON, FromJSON)
648648
649649{-| 'MappingName' is part of mappings which are how ES describes and schematizes
650650 the data in the indices.
651651-}
652−newtype MappingName = MappingName Text deriving (Eq, Generic, Show)
652+newtype MappingName = MappingName Text deriving (Eq, Generic, Show, ToJSON, FromJSON)
653653
654654{-| 'DocId' is a generic wrapper value for expressing unique Document IDs.
655655 Can be set by the user or created by ES itself. Often used in client
656656 functions for poking at specific documents.
657657-}
658−newtype DocId = DocId Text deriving (Eq, Generic, Show)
658+newtype DocId = DocId Text deriving (Eq, Generic, Show, ToJSON, FromJSON)
659659
660660{-| 'QueryString' is used to wrap query text bodies, be they human written or not.
661661-}
662−newtype QueryString = QueryString Text deriving (Eq, Generic, Show)
662+newtype QueryString = QueryString Text deriving (Eq, Generic, Show, ToJSON, FromJSON)
663663
664664{-| 'FieldName' is used all over the place wherever a specific field within
665665 a document needs to be specified, usually in 'Query's or 'Filter's.
666666-}
667−newtype FieldName = FieldName Text deriving (Eq, Show, FromJSON)
667+newtype FieldName = FieldName Text deriving (Eq, Show, ToJSON, FromJSON)
668668
669669
670670{-| 'Script' is often used in place of 'FieldName' to specify more
@@ -675,100 +675,100 @@ newtype Script = Script { scriptText :: Text } deriving (Eq, Show)
675675{-| 'CacheName' is used in 'RegexpFilter' for describing the
676676 'CacheKey' keyed caching behavior.
677677-}
678−newtype CacheName = CacheName Text deriving (Eq, Show, FromJSON)
678+newtype CacheName = CacheName Text deriving (Eq, Show, ToJSON, FromJSON)
679679
680680{-| 'CacheKey' is used in 'RegexpFilter' to key regex caching.
681681-}
682682newtype CacheKey =
683− CacheKey Text deriving (Eq, Show, FromJSON)
683+ CacheKey Text deriving (Eq, Show, ToJSON, FromJSON)
684684newtype Existence =
685− Existence Bool deriving (Eq, Show, FromJSON)
685+ Existence Bool deriving (Eq, Show, ToJSON, FromJSON)
686686newtype NullValue =
687− NullValue Bool deriving (Eq, Show, FromJSON)
687+ NullValue Bool deriving (Eq, Show, ToJSON, FromJSON)
688688newtype CutoffFrequency =
689− CutoffFrequency Double deriving (Eq, Show, Generic)
689+ CutoffFrequency Double deriving (Eq, Show, Generic, ToJSON, FromJSON)
690690newtype Analyzer =
691− Analyzer Text deriving (Eq, Show, Generic)
691+ Analyzer Text deriving (Eq, Show, Generic, ToJSON, FromJSON)
692692newtype MaxExpansions =
693− MaxExpansions Int deriving (Eq, Show, Generic)
693+ MaxExpansions Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
694694
695695{-| 'Lenient', if set to true, will cause format based failures to be
696696 ignored. I don't know what the bloody default is, Elasticsearch
697697 documentation didn't say what it was. Let me know if you figure it out.
698698-}
699699newtype Lenient =
700− Lenient Bool deriving (Eq, Show, Generic)
700+ Lenient Bool deriving (Eq, Show, Generic, ToJSON, FromJSON)
701701newtype Tiebreaker =
702− Tiebreaker Double deriving (Eq, Show, Generic)
702+ Tiebreaker Double deriving (Eq, Show, Generic, ToJSON, FromJSON)
703703newtype Boost =
704− Boost Double deriving (Eq, Show, Generic)
704+ Boost Double deriving (Eq, Show, Generic, ToJSON, FromJSON)
705705newtype BoostTerms =
706− BoostTerms Double deriving (Eq, Show, Generic)
706+ BoostTerms Double deriving (Eq, Show, Generic, ToJSON, FromJSON)
707707
708708{-| 'MinimumMatch' controls how many should clauses in the bool query should
709709 match. Can be an absolute value (2) or a percentage (30%) or a
710710 combination of both.
711711-}
712712newtype MinimumMatch =
713− MinimumMatch Int deriving (Eq, Show, Generic)
713+ MinimumMatch Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
714714newtype MinimumMatchText =
715− MinimumMatchText Text deriving (Eq, Show)
715+ MinimumMatchText Text deriving (Eq, Show, ToJSON, FromJSON)
716716newtype DisableCoord =
717− DisableCoord Bool deriving (Eq, Show, Generic)
717+ DisableCoord Bool deriving (Eq, Show, Generic, ToJSON, FromJSON)
718718newtype IgnoreTermFrequency =
719− IgnoreTermFrequency Bool deriving (Eq, Show, Generic)
719+ IgnoreTermFrequency Bool deriving (Eq, Show, Generic, ToJSON, FromJSON)
720720newtype MinimumTermFrequency =
721− MinimumTermFrequency Int deriving (Eq, Show, Generic)
721+ MinimumTermFrequency Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
722722newtype MaxQueryTerms =
723− MaxQueryTerms Int deriving (Eq, Show, Generic)
723+ MaxQueryTerms Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
724724newtype Fuzziness =
725− Fuzziness Double deriving (Eq, Show, Generic)
725+ Fuzziness Double deriving (Eq, Show, Generic, ToJSON, FromJSON)
726726
727727{-| 'PrefixLength' is the prefix length used in queries, defaults to 0. -}
728728newtype PrefixLength =
729− PrefixLength Int deriving (Eq, Show, Generic)
729+ PrefixLength Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
730730newtype TypeName =
731− TypeName Text deriving (Eq, Show, Generic)
731+ TypeName Text deriving (Eq, Show, Generic, ToJSON, FromJSON)
732732newtype PercentMatch =
733− PercentMatch Double deriving (Eq, Show, Generic)
733+ PercentMatch Double deriving (Eq, Show, Generic, ToJSON, FromJSON)
734734newtype StopWord =
735− StopWord Text deriving (Eq, Show, Generic)
735+ StopWord Text deriving (Eq, Show, Generic, ToJSON, FromJSON)
736736newtype QueryPath =
737− QueryPath Text deriving (Eq, Show, Generic)
737+ QueryPath Text deriving (Eq, Show, Generic, ToJSON, FromJSON)
738738
739739{-| Allowing a wildcard at the beginning of a word (eg "*ing") is particularly
740740 heavy, because all terms in the index need to be examined, just in case
741741 they match. Leading wildcards can be disabled by setting
742742 'AllowLeadingWildcard' to false. -}
743743newtype AllowLeadingWildcard =
744− AllowLeadingWildcard Bool deriving (Eq, Show, Generic)
744+ AllowLeadingWildcard Bool deriving (Eq, Show, Generic, ToJSON, FromJSON)
745745newtype LowercaseExpanded =
746− LowercaseExpanded Bool deriving (Eq, Show, Generic)
746+ LowercaseExpanded Bool deriving (Eq, Show, Generic, ToJSON, FromJSON)
747747newtype EnablePositionIncrements =
748− EnablePositionIncrements Bool deriving (Eq, Show, Generic)
748+ EnablePositionIncrements Bool deriving (Eq, Show, Generic, ToJSON, FromJSON)
749749
750750{-| By default, wildcard terms in a query are not analyzed.
751751 Setting 'AnalyzeWildcard' to true enables best-effort analysis.
752752-}
753−newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show, Generic)
753+newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show, Generic, ToJSON, FromJSON)
754754
755755{-| 'GeneratePhraseQueries' defaults to false.
756756-}
757757newtype GeneratePhraseQueries =
758− GeneratePhraseQueries Bool deriving (Eq, Show, Generic)
758+ GeneratePhraseQueries Bool deriving (Eq, Show, Generic, ToJSON, FromJSON)
759759
760760{-| 'Locale' is used for string conversions - defaults to ROOT.
761761-}
762−newtype Locale = Locale Text deriving (Eq, Show, Generic)
763−newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show, Generic)
764−newtype MinWordLength = MinWordLength Int deriving (Eq, Show, Generic)
762+newtype Locale = Locale Text deriving (Eq, Show, Generic, ToJSON, FromJSON)
763+newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
764+newtype MinWordLength = MinWordLength Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
765765
766766{-| 'PhraseSlop' sets the default slop for phrases, 0 means exact
767767 phrase matches. Default is 0.
768768-}
769−newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show, Generic)
770−newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show, Generic)
771−newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic)
769+newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
770+newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
771+newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic, ToJSON, FromJSON)
772772
773773{-| 'unpackId' is a silly convenience function that gets used once.
774774-}
@@ -1448,6 +1448,22 @@ mkTermsScriptAggregation t = TermsAggregation (Right t) Nothing Nothing Nothing
14481448mkDateHistogram :: FieldName -> Interval -> DateHistogramAggregation
14491449mkDateHistogram t i = DateHistogramAggregation t i Nothing Nothing Nothing Nothing Nothing Nothing
14501450
1451+instance ToJSON Version where
1452+ toJSON Version {..} = object ["number" .= number
1453+ ,"build_hash" .= build_hash
1454+ ,"build_timestamp" .= build_timestamp
1455+ ,"build_snapshot" .= build_snapshot
1456+ ,"lucene_version" .= lucene_version]
1457+
1458+instance FromJSON Version where
1459+ parseJSON = withObject "Version" parse
1460+ where parse o = Version
1461+ <$> o .: "number"
1462+ <*> o .: "build_hash"
1463+ <*> o .: "build_timestamp"
1464+ <*> o .: "build_snapshot"
1465+ <*> o .: "lucene_version"
1466+
14511467instance ToJSON TermOrder where
14521468 toJSON (TermOrder termSortField termSortOrder) = object [termSortField .= termSortOrder]
14531469
@@ -1729,13 +1745,13 @@ instance FromJSON Filter where
17291745 missingFilter o = MissingFilter <$> o .: "field"
17301746 <*> o .: "existence"
17311747 <*> o .: "null_value"
1732− prefixFilter o = fieldTagged $ \fn o' -> PrefixFilter fn <$> parseJSON (Object o')
1733− <*> o .:? "_cache" .!= defaultCache
1748+ prefixFilter o = flip fieldTagged o $ \fn o' -> PrefixFilter fn <$> parseJSON (Object o')
1749+ <*> o .:? "_cache" .!= defaultCache
17341750 queryFilter q = pure (QueryFilter q False)
17351751 fqueryFilter o = QueryFilter <$> o .: "query" <*> pure True
1736− rangeFilter o = fieldTagged $ \fn o' -> RangeFilter fn <$> parseJSON (Object o')
1737− <*> o .: "execution"
1738− <*> o .:? "_cache" .!= defaultCache
1752+ rangeFilter o = flip fieldTagged o $ \fn o' -> RangeFilter fn <$> parseJSON (Object o')
1753+ <*> o .: "execution"
1754+ <*> o .:? "_cache" .!= defaultCache
17391755 regexpFilter = fieldTagged $ \fn o -> RegexpFilter fn <$> o .: "value"
17401756 <*> o .: "flags"
17411757 <*> o .: "_name"
@@ -1744,10 +1760,11 @@ instance FromJSON Filter where
17441760 termFilter o = flip fieldTagged o $ \(FieldName fn) o' -> do
17451761 trm <- Term fn <$> parseJSON (Object o')
17461762 TermFilter trm <$> o .: "_cache" .!= defaultCache
1747− --TODO: should this enforce there only being 1 key?
1748− fieldTagged f o = case HM.toList o of
1749− [(k, Object o')] -> f (FieldName k) o'
1750− _ -> fail "Expected object with 1 field named key"
1763+
1764+fieldTagged :: Monad m => (FieldName -> Object -> m a) -> Object -> m a
1765+fieldTagged f o = case HM.toList o of
1766+ [(k, Object o')] -> f (FieldName k) o'
1767+ _ -> fail "Expected object with 1 field-named key"
17511768
17521769instance ToJSON GeoPoint where
17531770 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
@@ -1848,6 +1865,73 @@ instance ToJSON Query where
18481865 toJSON (QuerySimpleQueryStringQuery query) =
18491866 object [ "simple_query_string" .= query ]
18501867
1868+instance FromJSON Query where
1869+ parseJSON = withObject "Query" parse
1870+ where parse o = termQuery `taggedWith` "term"
1871+ <|> termsQuery `taggedWith` "terms"
1872+ <|> idsQuery `taggedWith` "ids"
1873+ <|> queryQueryStringQuery `taggedWith` "query_string"
1874+ <|> queryMatchQuery `taggedWith` "match"
1875+ <|> queryMultiMatchQuery o --TODO: is this a precedence issue?
1876+ <|> queryBoolQuery `taggedWith` "bool"
1877+ <|> queryBoostingQuery `taggedWith` "boosting"
1878+ <|> queryCommonTermsQuery `taggedWith` "common"
1879+ <|> constantScoreFilter o
1880+ <|> constantScoreQuery o
1881+ <|> queryDisMaxQuery `taggedWith` "dis_max"
1882+ <|> queryFilteredQuery `taggedWith` "filtered"
1883+ <|> queryFuzzyLikeThisQuery `taggedWith` "fuzzy_like_this"
1884+ <|> queryFuzzyLikeFieldQuery `taggedWith` "fuzzy_like_this_field"
1885+ <|> queryFuzzyQuery `taggedWith` "fuzzy"
1886+ <|> queryHasChildQuery `taggedWith` "has_child"
1887+ <|> queryHasParentQuery `taggedWith` "has_parent"
1888+ <|> queryIndicesQuery `taggedWith` "indices"
1889+ <|> matchAllQuery `taggedWith` "match_all"
1890+ <|> queryMoreLikeThisQuery `taggedWith` "more_like_this"
1891+ <|> queryMoreLikeThisFieldQuery `taggedWith` "more_like_this_field"
1892+ <|> queryNestedQuery `taggedWith` "nested"
1893+ <|> queryPrefixQuery `taggedWith` "prefix"
1894+ <|> queryRangeQuery `taggedWith` "range"
1895+ <|> queryRegexpQuery `taggedWith` "regexp"
1896+ <|> querySimpleQueryStringQuery `taggedWith` "simple_query_string"
1897+ where taggedWith parser k = parser =<< o .: k
1898+ termQuery o = TermQuery <$> parseJSON (Object o)
1899+ <*> o .:? "boost"
1900+ termsQuery o = case HM.toList o of
1901+ [(fn, vs)] -> do vals <- parseJSON vs
1902+ case vals of
1903+ x:xs -> return (TermsQuery (Term fn <$> x :| xs))
1904+ _ -> fail "Expected non empty list of values"
1905+ _ -> fail "Expected object with 1 field-named key"
1906+ idsQuery o = IdsQuery <$> o .: "type"
1907+ <*> o .: "values"
1908+ queryQueryStringQuery = pure . QueryQueryStringQuery
1909+ queryMatchQuery = pure . QueryMatchQuery
1910+ queryMultiMatchQuery = undefined
1911+ queryBoolQuery = pure . QueryBoolQuery
1912+ queryBoostingQuery = pure . QueryBoostingQuery
1913+ queryCommonTermsQuery = pure . QueryCommonTermsQuery
1914+ constantScoreFilter o = ConstantScoreFilter <$> o .: "constant_score"
1915+ <*> o .: "boost"
1916+ constantScoreQuery o = ConstantScoreQuery <$> o .: "constant_score"
1917+ <*> o .: "boost"
1918+ queryDisMaxQuery = pure . QueryDisMaxQuery
1919+ queryFilteredQuery = pure . QueryFilteredQuery
1920+ queryFuzzyLikeThisQuery = pure . QueryFuzzyLikeThisQuery
1921+ queryFuzzyLikeFieldQuery = pure . QueryFuzzyLikeFieldQuery
1922+ queryFuzzyQuery = pure . QueryFuzzyQuery
1923+ queryHasChildQuery = pure . QueryHasChildQuery
1924+ queryHasParentQuery = pure . QueryHasParentQuery
1925+ queryIndicesQuery = pure . QueryIndicesQuery
1926+ matchAllQuery o = MatchAllQuery <$> o .:? "boost"
1927+ queryMoreLikeThisQuery = pure . QueryMoreLikeThisQuery
1928+ queryMoreLikeThisFieldQuery = pure . QueryMoreLikeThisFieldQuery
1929+ queryNestedQuery = pure . QueryNestedQuery
1930+ queryPrefixQuery = pure . QueryPrefixQuery
1931+ queryRangeQuery = pure . QueryRangeQuery
1932+ queryRegexpQuery = pure . QueryRegexpQuery
1933+ querySimpleQueryStringQuery = pure . QuerySimpleQueryStringQuery
1934+
18511935
18521936omitNulls :: [(Text, Value)] -> Value
18531937omitNulls = object . filter notNull where
@@ -1867,6 +1951,15 @@ instance ToJSON SimpleQueryStringQuery where
18671951 , "lowercase_expanded_terms" .= simpleQueryStringLowercaseExpanded
18681952 , "locale" .= simpleQueryStringLocale ]
18691953
1954+instance FromJSON SimpleQueryStringQuery where
1955+ parseJSON = withObject "SimpleQueryStringQuery" parse
1956+ where parse o = SimpleQueryStringQuery <$> o .: "query"
1957+ <*> o .:? "fields"
1958+ <*> o .:? "default_operator"
1959+ <*> o .:? "analyzer"
1960+ <*> o .:? "flags"
1961+ <*> o .:? "lowercase_expanded_terms"
1962+ <*> o .:? "locale"
18701963
18711964instance ToJSON FieldOrFields where
18721965 toJSON (FofField fieldName) =
@@ -1874,6 +1967,10 @@ instance ToJSON FieldOrFields where
18741967 toJSON (FofFields fieldNames) =
18751968 toJSON fieldNames
18761969
1970+instance FromJSON FieldOrFields where
1971+ parseJSON v = FofField <$> parseJSON v
1972+ <|> FofFields <$> parseJSON v
1973+
18771974instance ToJSON SimpleQueryFlag where
18781975 toJSON SimpleQueryAll = "ALL"
18791976 toJSON SimpleQueryNone = "NONE"
@@ -1888,6 +1985,21 @@ instance ToJSON SimpleQueryFlag where
18881985 toJSON SimpleQueryNear = "NEAR"
18891986 toJSON SimpleQuerySlop = "SLOP"
18901987
1988+instance FromJSON SimpleQueryFlag where
1989+ parseJSON = withText "SimpleQueryFlag" parse
1990+ where parse "ALL" = pure SimpleQueryAll
1991+ parse "NONE" = pure SimpleQueryNone
1992+ parse "AND" = pure SimpleQueryAnd
1993+ parse "OR" = pure SimpleQueryOr
1994+ parse "PREFIX" = pure SimpleQueryPrefix
1995+ parse "PHRASE" = pure SimpleQueryPhrase
1996+ parse "PRECEDENCE" = pure SimpleQueryPrecedence
1997+ parse "ESCAPE" = pure SimpleQueryEscape
1998+ parse "WHITESPACE" = pure SimpleQueryWhitespace
1999+ parse "FUZZY" = pure SimpleQueryFuzzy
2000+ parse "NEAR" = pure SimpleQueryNear
2001+ parse "SLOP" = pure SimpleQuerySlop
2002+ parse f = fail ("Unexpected SimpleQueryFlag: " <> show f)
18912003
18922004instance ToJSON RegexpQuery where
18932005 toJSON (RegexpQuery (FieldName rqQueryField)
@@ -1898,6 +2010,13 @@ instance ToJSON RegexpQuery where
18982010 , "flags" .= rqQueryFlags
18992011 , "boost" .= rqQueryBoost ]
19002012
2013+instance FromJSON RegexpQuery where
2014+ parseJSON = withObject "RegexpQuery" parse
2015+ where parse = fieldTagged $ \fn o ->
2016+ RegexpQuery fn
2017+ <$> o .: "value"
2018+ <*> o .: "flags"
2019+ <*> o .:? "boost"
19012020
19022021instance ToJSON QueryStringQuery where
19032022 toJSON (QueryStringQuery qsQueryString
@@ -1929,15 +2048,71 @@ instance ToJSON QueryStringQuery where
19292048 , "lenient" .= qsLenient
19302049 , "locale" .= qsLocale ]
19312050
2051+instance FromJSON QueryStringQuery where
2052+ parseJSON = withObject "QueryStringQuery" parse
2053+ where parse o = QueryStringQuery
2054+ <$> o .: "query"
2055+ <*> o .:? "default_field"
2056+ <*> o .:? "default_operator"
2057+ <*> o .:? "analyzer"
2058+ <*> o .:? "allow_leading_wildcard"
2059+ <*> o .:? "lowercase_expanded_terms"
2060+ <*> o .:? "enable_position_increments"
2061+ <*> o .:? "fuzzy_max_expansions"
2062+ <*> o .:? "fuzziness"
2063+ <*> o .:? "fuzzy_prefix_length"
2064+ <*> o .:? "phrase_slop"
2065+ <*> o .:? "boost"
2066+ <*> o .:? "analyze_wildcard"
2067+ <*> o .:? "auto_generate_phrase_queries"
2068+ <*> o .:? "minimum_should_match"
2069+ <*> o .:? "lenient"
2070+ <*> o .:? "locale"
19322071
19332072instance ToJSON RangeQuery where
19342073 toJSON (RangeQuery (FieldName fieldName) range boost) =
19352074 object [ fieldName .= conjoined ]
19362075 where conjoined = [ "boost" .= boost ] ++ (rangeValueToPair range)
19372076
2077+instance FromJSON RangeQuery where
2078+ parseJSON = withObject "RangeQuery" parse
2079+ where parse = fieldTagged $ \fn o ->
2080+ RangeQuery fn
2081+ <$> parseJSON (Object o)
2082+ <*> o .: "boost"
2083+
19382084instance FromJSON RangeValue where
19392085 parseJSON = withObject "RangeValue" parse
1940− where parse o = undefined
2086+ where parse o = parseDate o
2087+ <|> parseDouble o
2088+ parseDate o = do lt <- o .:? "lt"
2089+ lte <- o .:? "lte"
2090+ gt <- o .:? "gt"
2091+ gte <- o .:? "gte"
2092+ case (lt, lte, gt, gte) of
2093+ (Just a, _, Just b, _) -> return (RangeDateGtLt (GreaterThanD a) (LessThanD b))
2094+ (Just a, _, _, Just b)-> return (RangeDateGteLt (GreaterThanEqD a) (LessThanD b))
2095+ (_, Just a, Just b, _)-> return (RangeDateGtLte (GreaterThanD a) (LessThanEqD b))
2096+ (_, Just a, _, Just b)-> return (RangeDateGteLte (GreaterThanEqD a) (LessThanEqD b))
2097+ (_, _, Just a, _)-> return (RangeDateGt (GreaterThanD a))
2098+ (Just a, _, _, _)-> return (RangeDateLt (LessThanD a))
2099+ (_, _, _, Just a)-> return (RangeDateGte (GreaterThanEqD a))
2100+ (_, Just a, _, _)-> return (RangeDateLte (LessThanEqD a))
2101+ (Nothing, Nothing, Nothing, Nothing) -> mzero
2102+ parseDouble o = do lt <- o .:? "lt"
2103+ lte <- o .:? "lte"
2104+ gt <- o .:? "gt"
2105+ gte <- o .:? "gte"
2106+ case (lt, lte, gt, gte) of
2107+ (Just a, _, Just b, _) -> return (RangeDoubleGtLt (GreaterThan a) (LessThan b))
2108+ (Just a, _, _, Just b)-> return (RangeDoubleGteLt (GreaterThanEq a) (LessThan b))
2109+ (_, Just a, Just b, _)-> return (RangeDoubleGtLte (GreaterThan a) (LessThanEq b))
2110+ (_, Just a, _, Just b)-> return (RangeDoubleGteLte (GreaterThanEq a) (LessThanEq b))
2111+ (_, _, Just a, _)-> return (RangeDoubleGt (GreaterThan a))
2112+ (Just a, _, _, _)-> return (RangeDoubleLt (LessThan a))
2113+ (_, _, _, Just a)-> return (RangeDoubleGte (GreaterThanEq a))
2114+ (_, Just a, _, _)-> return (RangeDoubleLte (LessThanEq a))
2115+ (Nothing, Nothing, Nothing, Nothing) -> mzero
19412116
19422117instance ToJSON PrefixQuery where
19432118 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
@@ -1945,6 +2120,12 @@ instance ToJSON PrefixQuery where
19452120 where base = [ "value" .= queryValue
19462121 , "boost" .= boost ]
19472122
2123+instance FromJSON PrefixQuery where
2124+ parseJSON = withObject "PrefixQuery" parse
2125+ where parse = fieldTagged $ \fn o ->
2126+ PrefixQuery fn
2127+ <$> o .: "value"
2128+ <*> o .:? "boost"
19482129
19492130instance ToJSON NestedQuery where
19502131 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
@@ -1952,6 +2133,12 @@ instance ToJSON NestedQuery where
19522133 , "score_mode" .= nqScoreType
19532134 , "query" .= nqQuery ]
19542135
2136+instance FromJSON NestedQuery where
2137+ parseJSON = withObject "NestedQuery" parse
2138+ where parse o = NestedQuery
2139+ <$> o .: "path"
2140+ <*> o .: "score_mode"
2141+ <*> o .: "query"
19552142
19562143instance ToJSON MoreLikeThisFieldQuery where
19572144 toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
@@ -1971,6 +2158,23 @@ instance ToJSON MoreLikeThisFieldQuery where
19712158 , "boost" .= boost
19722159 , "analyzer" .= analyzer ]
19732160
2161+instance FromJSON MoreLikeThisFieldQuery where
2162+ parseJSON = withObject "MoreLikeThisFieldQuery" parse
2163+ where parse = fieldTagged $ \fn o ->
2164+ MoreLikeThisFieldQuery
2165+ <$> o .: "like_text"
2166+ <*> pure fn
2167+ <*> o .:? "percent_terms_to_match"
2168+ <*> o .:? "min_term_freq"
2169+ <*> o .:? "max_query_terms"
2170+ <*> o .:? "stop_words"
2171+ <*> o .:? "min_doc_freq"
2172+ <*> o .:? "max_doc_freq"
2173+ <*> o .:? "min_word_length"
2174+ <*> o .:? "max_word_length"
2175+ <*> o .:? "boost_terms"
2176+ <*> o .:? "boost"
2177+ <*> o .:? "analyzer"
19742178
19752179instance ToJSON MoreLikeThisQuery where
19762180 toJSON (MoreLikeThisQuery text fields percent
@@ -1991,6 +2195,22 @@ instance ToJSON MoreLikeThisQuery where
19912195 , "boost" .= boost
19922196 , "analyzer" .= analyzer ]
19932197
2198+instance FromJSON MoreLikeThisQuery where
2199+ parseJSON = withObject "MoreLikeThisQuery" parse
2200+ where parse o = MoreLikeThisQuery
2201+ <$> o .: "like_text"
2202+ <*> o .:? "fields"
2203+ <*> o .:? "percent_terms_to_match"
2204+ <*> o .:? "min_term_freq"
2205+ <*> o .:? "max_query_terms"
2206+ <*> o .:? "stop_words"
2207+ <*> o .:? "min_doc_freq"
2208+ <*> o .:? "max_doc_freq"
2209+ <*> o .:? "min_word_length"
2210+ <*> o .:? "max_word_length"
2211+ <*> o .:? "boost_terms"
2212+ <*> o .:? "boost"
2213+ <*> o .:? "analyzer"
19942214
19952215instance ToJSON IndicesQuery where
19962216 toJSON (IndicesQuery indices query noMatch) =
@@ -1998,6 +2218,12 @@ instance ToJSON IndicesQuery where
19982218 , "no_match_query" .= noMatch
19992219 , "query" .= query ]
20002220
2221+instance FromJSON IndicesQuery where
2222+ parseJSON = withObject "IndicesQuery" parse
2223+ where parse o = IndicesQuery
2224+ <$> o .: "indices"
2225+ <*> o .: "query"
2226+ <*> o .:? "no_match_query"
20012227
20022228instance ToJSON HasParentQuery where
20032229 toJSON (HasParentQuery queryType query scoreType) =
@@ -2005,6 +2231,12 @@ instance ToJSON HasParentQuery where
20052231 , "score_type" .= scoreType
20062232 , "query" .= query ]
20072233
2234+instance FromJSON HasParentQuery where
2235+ parseJSON = withObject "HasParentQuery" parse
2236+ where parse o = HasParentQuery
2237+ <$> o .: "parent_type"
2238+ <*> o .: "query"
2239+ <*> o .:? "score_type"
20082240
20092241instance ToJSON HasChildQuery where
20102242 toJSON (HasChildQuery queryType query scoreType) =
@@ -2012,6 +2244,12 @@ instance ToJSON HasChildQuery where
20122244 , "score_type" .= scoreType
20132245 , "type" .= queryType ]
20142246
2247+instance FromJSON HasChildQuery where
2248+ parseJSON = withObject "HasChildQuery" parse
2249+ where parse o = HasChildQuery
2250+ <$> o .: "type"
2251+ <*> o .: "query"
2252+ <*> o .:? "score_type"
20152253
20162254instance ToJSON FuzzyQuery where
20172255 toJSON (FuzzyQuery (FieldName fieldName) queryText
@@ -2023,6 +2261,15 @@ instance ToJSON FuzzyQuery where
20232261 , "boost" .= boost
20242262 , "max_expansions" .= maxEx ]
20252263
2264+instance FromJSON FuzzyQuery where
2265+ parseJSON = withObject "FuzzyQuery" parse
2266+ where parse = fieldTagged $ \fn o ->
2267+ FuzzyQuery fn
2268+ <$> o .: "value"
2269+ <*> o .: "prefix_length"
2270+ <*> o .: "max_expansions"
2271+ <*> o .: "fuzziness"
2272+ <*> o .:? "boost"
20262273
20272274instance ToJSON FuzzyLikeFieldQuery where
20282275 toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
@@ -2037,6 +2284,17 @@ instance ToJSON FuzzyLikeFieldQuery where
20372284 , "analyzer" .= analyzer
20382285 , "boost" .= boost ]]
20392286
2287+instance FromJSON FuzzyLikeFieldQuery where
2288+ parseJSON = withObject "FuzzyLikeFieldQuery" parse
2289+ where parse = fieldTagged $ \fn o ->
2290+ FuzzyLikeFieldQuery fn
2291+ <$> o .: "like_text"
2292+ <*> o .: "max_query_terms"
2293+ <*> o .: "ignore_tf"
2294+ <*> o .: "fuzziness"
2295+ <*> o .: "prefix_length"
2296+ <*> o .: "boost"
2297+ <*> o .:? "analyzer"
20402298
20412299instance ToJSON FuzzyLikeThisQuery where
20422300 toJSON (FuzzyLikeThisQuery fields text maxTerms
@@ -2051,12 +2309,28 @@ instance ToJSON FuzzyLikeThisQuery where
20512309 , "analyzer" .= analyzer
20522310 , "boost" .= boost ]
20532311
2312+instance FromJSON FuzzyLikeThisQuery where
2313+ parseJSON = withObject "FuzzyLikeThisQuery" parse
2314+ where parse o = FuzzyLikeThisQuery
2315+ <$> o .: "fields"
2316+ <*> o .: "like_text"
2317+ <*> o .: "max_query_terms"
2318+ <*> o .: "ignore_tf"
2319+ <*> o .: "fuzziness"
2320+ <*> o .: "prefix_length"
2321+ <*> o .: "boost"
2322+ <*> o .:? "analyzer"
20542323
20552324instance ToJSON FilteredQuery where
20562325 toJSON (FilteredQuery query fFilter) =
20572326 object [ "query" .= query
20582327 , "filter" .= fFilter ]
20592328
2329+instance FromJSON FilteredQuery where
2330+ parseJSON = withObject "FilteredQuery" parse
2331+ where parse o = FilteredQuery
2332+ <$> o .: "query"
2333+ <*> o .: "filter"
20602334
20612335instance ToJSON DisMaxQuery where
20622336 toJSON (DisMaxQuery queries tiebreaker boost) =
@@ -2065,6 +2339,12 @@ instance ToJSON DisMaxQuery where
20652339 , "boost" .= boost
20662340 , "tie_breaker" .= tiebreaker ]
20672341
2342+instance FromJSON DisMaxQuery where
2343+ parseJSON = withObject "DisMaxQuery" parse
2344+ where parse o = DisMaxQuery
2345+ <$> o .: "queries"
2346+ <*> o .: "tie_breaker"
2347+ <*> o .:? "boost"
20682348
20692349instance ToJSON CommonTermsQuery where
20702350 toJSON (CommonTermsQuery (FieldName fieldName)
@@ -2080,6 +2360,18 @@ instance ToJSON CommonTermsQuery where
20802360 , "disable_coord" .= disableCoord
20812361 , "high_freq_operator" .= hfo ]
20822362
2363+instance FromJSON CommonTermsQuery where
2364+ parseJSON = withObject "CommonTermsQuery" parse
2365+ where parse = fieldTagged $ \fn o ->
2366+ CommonTermsQuery fn
2367+ <$> o .: "query"
2368+ <*> o .: "cutoff_frequency"
2369+ <*> o .: "low_freq_operator"
2370+ <*> o .: "high_freq_operator"
2371+ <*> o .:? "minimum_should_match"
2372+ <*> o .:? "boost"
2373+ <*> o .:? "analyzer"
2374+ <*> o .:? "disable_coord"
20832375
20842376instance ToJSON CommonMinimumMatch where
20852377 toJSON (CommonMinimumMatch mm) = toJSON mm
@@ -2087,12 +2379,28 @@ instance ToJSON CommonMinimumMatch where
20872379 object [ "low_freq" .= lowF
20882380 , "high_freq" .= highF ]
20892381
2382+instance FromJSON CommonMinimumMatch where
2383+ parseJSON v = parseMinimum v
2384+ <|> parseMinimumHighLow v
2385+ where parseMinimum = fmap CommonMinimumMatch . parseJSON
2386+ parseMinimumHighLow = fmap CommonMinimumMatchHighLow . withObject "CommonMinimumMatchHighLow" (\o ->
2387+ MinimumMatchHighLow
2388+ <$> o .: "low_freq"
2389+ <*> o .: "high_freq")
2390+
2391+
20902392instance ToJSON BoostingQuery where
20912393 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
20922394 object [ "positive" .= bqPositiveQuery
20932395 , "negative" .= bqNegativeQuery
20942396 , "negative_boost" .= bqNegativeBoost ]
20952397
2398+instance FromJSON BoostingQuery where
2399+ parseJSON = withObject "BoostingQuery" parse
2400+ where parse o = BoostingQuery
2401+ <$> o .: "positive"
2402+ <*> o .: "negative"
2403+ <*> o .: "negative_boost"
20962404
20972405instance ToJSON BoolQuery where
20982406 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
@@ -2104,6 +2412,15 @@ instance ToJSON BoolQuery where
21042412 , "boost" .= boost
21052413 , "disable_coord" .= disableCoord ]
21062414
2415+instance FromJSON BoolQuery where
2416+ parseJSON = withObject "BoolQuery" parse
2417+ where parse o = BoolQuery
2418+ <$> o .:? "must" .!= []
2419+ <*> o .:? "must_not" .!= []
2420+ <*> o .:? "should" .!= []
2421+ <*> o .:? "minimum_should_match"
2422+ <*> o .:? "boost"
2423+ <*> o .:? "disable_coord"
21072424
21082425instance ToJSON MatchQuery where
21092426 toJSON (MatchQuery (FieldName fieldName)
@@ -2121,6 +2438,19 @@ instance ToJSON MatchQuery where
21212438 , "lenient" .= lenient
21222439 , "boost" .= boost ]
21232440
2441+instance FromJSON MatchQuery where
2442+ parseJSON = withObject "MatchQuery" parse
2443+ where parse = fieldTagged $ \fn o ->
2444+ MatchQuery fn
2445+ <$> o .: "query"
2446+ <*> o .: "operator"
2447+ <*> o .: "zero_terms_query"
2448+ <*> o .:? "cutoff_frequency"
2449+ <*> o .:? "type"
2450+ <*> o .:? "analyzer"
2451+ <*> o .:? "max_expansions"
2452+ <*> o .:? "lenient"
2453+ <*> o .:? "boost"
21242454
21252455instance ToJSON MultiMatchQuery where
21262456 toJSON (MultiMatchQuery fields (QueryString query) boolOp
@@ -2145,106 +2475,44 @@ instance ToJSON MultiMatchQueryType where
21452475 toJSON MultiMatchPhrase = "phrase"
21462476 toJSON MultiMatchPhrasePrefix = "phrase_prefix"
21472477
2478+instance FromJSON MultiMatchQueryType where
2479+ parseJSON = withText "MultiMatchPhrasePrefix" parse
2480+ where parse "best_fields" = pure MultiMatchBestFields
2481+ parse "most_fields" = pure MultiMatchMostFields
2482+ parse "cross_fields" = pure MultiMatchCrossFields
2483+ parse "phrase" = pure MultiMatchPhrase
2484+ parse "phrase_prefix" = pure MultiMatchPhrasePrefix
2485+ parse t = fail ("Unexpected MultiMatchPhrasePrefix: " <> show t)
2486+
21482487instance ToJSON BooleanOperator where
21492488 toJSON And = String "and"
21502489 toJSON Or = String "or"
21512490
2491+instance FromJSON BooleanOperator where
2492+ parseJSON = withText "BooleanOperator" parse
2493+ where parse "and" = pure And
2494+ parse "or" = pure Or
2495+ parse o = fail ("Unexpected BooleanOperator: " <> show o)
2496+
21522497instance ToJSON ZeroTermsQuery where
21532498 toJSON ZeroTermsNone = String "none"
21542499 toJSON ZeroTermsAll = String "all"
21552500
2501+instance FromJSON ZeroTermsQuery where
2502+ parseJSON = withText "ZeroTermsQuery" parse
2503+ where parse "none" = pure ZeroTermsNone
2504+ parse "all" = pure ZeroTermsAll
2505+ parse q = fail ("Unexpected ZeroTermsQuery: " <> show q)
2506+
21562507instance ToJSON MatchQueryType where
21572508 toJSON MatchPhrase = "phrase"
21582509 toJSON MatchPhrasePrefix = "phrase_prefix"
21592510
2160−instance ToJSON FieldName where
2161− toJSON (FieldName fieldName) = String fieldName
2162−
2163−instance ToJSON ReplicaCount where
2164− toJSON = genericToJSON defaultOptions
2165−instance ToJSON ShardCount where
2166− toJSON = genericToJSON defaultOptions
2167−instance ToJSON CutoffFrequency where
2168− toJSON = genericToJSON defaultOptions
2169−instance ToJSON Analyzer where
2170− toJSON = genericToJSON defaultOptions
2171−instance ToJSON MaxExpansions where
2172− toJSON = genericToJSON defaultOptions
2173−instance ToJSON Lenient where
2174− toJSON = genericToJSON defaultOptions
2175−instance ToJSON Boost where
2176− toJSON = genericToJSON defaultOptions
2177−instance ToJSON Version where
2178− toJSON = genericToJSON defaultOptions
2179−instance ToJSON Tiebreaker where
2180− toJSON = genericToJSON defaultOptions
2181−instance ToJSON MinimumMatch where
2182− toJSON = genericToJSON defaultOptions
2183−instance ToJSON DisableCoord where
2184− toJSON = genericToJSON defaultOptions
2185−instance ToJSON PrefixLength where
2186− toJSON = genericToJSON defaultOptions
2187−instance ToJSON Fuzziness where
2188− toJSON = genericToJSON defaultOptions
2189−instance ToJSON IgnoreTermFrequency where
2190− toJSON = genericToJSON defaultOptions
2191−instance ToJSON MaxQueryTerms where
2192− toJSON = genericToJSON defaultOptions
2193−instance ToJSON TypeName where
2194− toJSON = genericToJSON defaultOptions
2195−instance ToJSON IndexName where
2196− toJSON = genericToJSON defaultOptions
2197−instance ToJSON TemplateName where
2198− toJSON = genericToJSON defaultOptions
2199−instance ToJSON TemplatePattern where
2200− toJSON = genericToJSON defaultOptions
2201−instance ToJSON BoostTerms where
2202− toJSON = genericToJSON defaultOptions
2203−instance ToJSON MaxWordLength where
2204− toJSON = genericToJSON defaultOptions
2205−instance ToJSON MinWordLength where
2206− toJSON = genericToJSON defaultOptions
2207−instance ToJSON MaxDocFrequency where
2208− toJSON = genericToJSON defaultOptions
2209−instance ToJSON MinDocFrequency where
2210− toJSON = genericToJSON defaultOptions
2211−instance ToJSON PhraseSlop where
2212− toJSON = genericToJSON defaultOptions
2213−instance ToJSON StopWord where
2214− toJSON = genericToJSON defaultOptions
2215−instance ToJSON QueryPath where
2216− toJSON = genericToJSON defaultOptions
2217−instance ToJSON MinimumTermFrequency where
2218− toJSON = genericToJSON defaultOptions
2219−instance ToJSON PercentMatch where
2220− toJSON = genericToJSON defaultOptions
2221−instance ToJSON MappingName where
2222− toJSON = genericToJSON defaultOptions
2223−instance ToJSON DocId where
2224− toJSON = genericToJSON defaultOptions
2225−instance ToJSON QueryString where
2226− toJSON = genericToJSON defaultOptions
2227−instance ToJSON AllowLeadingWildcard where
2228− toJSON = genericToJSON defaultOptions
2229−instance ToJSON LowercaseExpanded where
2230− toJSON = genericToJSON defaultOptions
2231−instance ToJSON AnalyzeWildcard where
2232− toJSON = genericToJSON defaultOptions
2233−instance ToJSON GeneratePhraseQueries where
2234− toJSON = genericToJSON defaultOptions
2235−instance ToJSON Locale where
2236− toJSON = genericToJSON defaultOptions
2237−instance ToJSON EnablePositionIncrements where
2238− toJSON = genericToJSON defaultOptions
2239−
2240−instance FromJSON Version where
2241− parseJSON = genericParseJSON defaultOptions
2242−instance FromJSON IndexName where
2243− parseJSON = genericParseJSON defaultOptions
2244−instance FromJSON MappingName where
2245− parseJSON = genericParseJSON defaultOptions
2246−instance FromJSON DocId where
2247− parseJSON = genericParseJSON defaultOptions
2511+instance FromJSON MatchQueryType where
2512+ parseJSON = withText "MatchQueryType" parse
2513+ where parse "phrase" = pure MatchPhrase
2514+ parse "phrase_prefix" = pure MatchPhrasePrefix
2515+ parse t = fail ("Unexpected MatchQueryType: " <> show t)
22482516
22492517instance FromJSON Status where
22502518 parseJSON (Object v) = Status <$>
@@ -2508,6 +2776,13 @@ instance ToJSON ScoreType where
25082776 toJSON ScoreTypeSum = "sum"
25092777 toJSON ScoreTypeNone = "none"
25102778
2779+instance FromJSON ScoreType where
2780+ parseJSON = withText "ScoreType" parse
2781+ where parse "max" = pure ScoreTypeMax
2782+ parse "avg" = pure ScoreTypeAvg
2783+ parse "sum" = pure ScoreTypeSum
2784+ parse "non" = pure ScoreTypeNone
2785+ parse t = fail ("Unexpected ScoreType: " <> show t)
25112786
25122787instance ToJSON Distance where
25132788 toJSON (Distance dCoefficient dUnit) =
@@ -2580,6 +2855,13 @@ instance ToJSON GeoBoundingBoxConstraint where
25802855 , "_cache" .= cache
25812856 , "type" .= type']
25822857
2858+instance FromJSON GeoBoundingBoxConstraint where
2859+ parseJSON = withObject "GeoBoundingBoxConstraint" parse
2860+ where parse o = flip fieldTagged o $ \fn o' ->
2861+ GeoBoundingBoxConstraint fn
2862+ <$> parseJSON (Object o')
2863+ <*> o .:? "cache" .!= defaultCache
2864+ <*> o .: "type"
25832865
25842866instance ToJSON GeoFilterType where
25852867 toJSON GeoFilterMemory = String "memory"
@@ -2596,6 +2878,11 @@ instance ToJSON GeoBoundingBox where
25962878 object ["top_left" .= gbbTopLeft
25972879 , "bottom_right" .= gbbBottomRight]
25982880
2881+instance FromJSON GeoBoundingBox where
2882+ parseJSON = withObject "GeoBoundingBox" parse
2883+ where parse o = GeoBoundingBox
2884+ <$> o .: "top_left"
2885+ <*> o .: "bottom_right"
25992886
26002887instance ToJSON LatLon where
26012888 toJSON (LatLon lLat lLon) =
@@ -2640,7 +2927,6 @@ instance FromJSON RegexpFlags where
26402927instance FromJSON RegexpFlag where
26412928 parseJSON = withText "RegexpFlag" parse
26422929 where parse "ANYSTRING" = pure AnyString
2643− parse "ANYSTRING" = pure AnyString
26442930 parse "AUTOMATON" = pure Automaton
26452931 parse "COMPLEMENT" = pure Complement
26462932 parse "EMPTY" = pure Empty
@@ -2652,6 +2938,12 @@ instance ToJSON Term where
26522938 toJSON (Term field value) = object ["term" .= object
26532939 [field .= value]]
26542940
2941+instance FromJSON Term where
2942+ parseJSON = withObject "Term" parse
2943+ where parse o = do termObj <- o .: "term"
2944+ case HM.toList termObj of
2945+ [(fn, v)] -> Term fn <$> parseJSON v
2946+ _ -> fail "Expected object with 1 field-named key"
26552947
26562948instance ToJSON BoolMatch where
26572949 toJSON (MustMatch term cache) = object ["must" .= term,
@@ -2661,6 +2953,15 @@ instance ToJSON BoolMatch where
26612953 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
26622954 "_cache" .= cache]
26632955
2956+instance FromJSON BoolMatch where
2957+ parseJSON = withObject "BoolMatch" parse
2958+ where parse o = mustMatch `taggedWith` "must"
2959+ <|> mustNotMatch `taggedWith` "must_not"
2960+ <|> shouldMatch `taggedWith` "should"
2961+ where taggedWith parser k = parser =<< o .: k
2962+ mustMatch t = MustMatch t <$> o .:? "_cache" .!= defaultCache
2963+ mustNotMatch t = MustNotMatch t <$> o .:? "_cache" .!= defaultCache
2964+ shouldMatch t = ShouldMatch t <$> o .:? "_cache" .!= defaultCache
26642965
26652966instance (FromJSON a) => FromJSON (SearchResult a) where
26662967 parseJSON (Object v) = SearchResult <$>