1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
6{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE RecordWildCards #-}
8{-# LANGUAGE UndecidableInstances #-}
10-------------------------------------------------------------------------------
12-- Module : Database.Bloodhound.Types
13-- Copyright : (C) 2014 Chris Allen
14-- License : BSD-style (see the file LICENSE)
15-- Maintainer : Chris Allen <cma@bitemyapp.com
16-- Stability : provisional
17-- Portability : DeriveGeneric, RecordWildCards
19-- Data types for describing actions and data structures performed to interact
20-- with Elasticsearch. The two main buckets your queries against Elasticsearch
21-- will fall into are 'Query's and 'Filter's. 'Filter's are more like
22-- traditional database constraints and often have preferable performance
23-- properties. 'Query's support human-written textual queries, such as fuzzy
25-------------------------------------------------------------------------------
29module Database.Bloodhound.Types
31 , defaultIndexSettings
42 , mkTermsScriptAggregation
73 , GeoBoundingBoxConstraint(..)
114 , MultiMatchQuery(..)
117 , CommonTermsQuery(..)
120 , FuzzyLikeThisQuery(..)
121 , FuzzyLikeFieldQuery(..)
126 , MoreLikeThisQuery(..)
127 , MoreLikeThisFieldQuery(..)
130 , QueryStringQuery(..)
131 , SimpleQueryStringQuery(..)
135 , BooleanOperator(..)
137 , CutoffFrequency(..)
142 , MultiMatchQueryType(..)
146 , CommonMinimumMatch(..)
147 , MinimumMatchHighLow(..)
150 , IgnoreTermFrequency(..)
159 , MaxDocFrequency(..)
160 , MinDocFrequency(..)
164 , MinimumTermFrequency(..)
166 , FieldDefinition(..)
169 , AllowLeadingWildcard(..)
170 , LowercaseExpanded(..)
171 , GeneratePhraseQueries(..)
173 , AnalyzeWildcard(..)
174 , EnablePositionIncrements(..)
175 , SimpleQueryFlag(..)
190 , BucketAggregation(..)
191 , TermsAggregation(..)
192 , DateHistogramAggregation(..)
196 , HighlightSettings(..)
198 , PostingsHighlight(..)
199 , FastVectorHighlight(..)
200 , CommonHighlight(..)
202 , HighlightEncoder(..)
207 , DateHistogramResult(..)
210import Control.Applicative
211import Control.Monad.Error
212import Control.Monad.Reader
213import Control.Monad.State
214import Control.Monad.Writer
216import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
217import qualified Data.ByteString.Lazy.Char8 as L
218import Data.List (nub)
219import Data.List.NonEmpty (NonEmpty (..), toList)
220import qualified Data.Map.Strict as M
221import Data.Text (Text)
222import qualified Data.Text as T
223import Data.Time.Clock (UTCTime)
224import qualified Data.Vector as V
225import GHC.Generics (Generic)
226import Network.HTTP.Client
227import qualified Network.HTTP.Types.Method as NHTM
229import Database.Bloodhound.Types.Class
232-- >>> :set -XOverloadedStrings
233-- >>> import Database.Bloodhound
234-- >>> let testServer = (Server "http://localhost:9200")
235-- >>> let testIndex = IndexName "twitter"
236-- >>> let testMapping = MappingName "tweet"
237-- >>> let defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
239-- defaultIndexSettings is exported by Database.Bloodhound as well
240-- no trailing slashes in servers, library handles building the path.
242{-| Common environment for Elasticsearch calls. Connections will be
243 pipelined according to the provided HTTP connection manager.
245data BHEnv = BHEnv { bhServer :: Server
246 , bhManager :: Manager
249{-| All API calls to Elasticsearch operate within
250 MonadBH. The idea is that it can be easily embedded in your
251 own monad transformer stack. A default instance for a ReaderT and
252 alias 'BH' is provided for the simple case.
254class (Functor m, Applicative m, MonadIO m) => MonadBH m where
258 unBH :: ReaderT BHEnv m a
270instance MonadTrans BH where
273instance (MonadReader r m) => MonadReader r (BH m) where
275 local f (BH (ReaderT m)) = BH $ ReaderT $ \r ->
278instance (Functor m, Applicative m, MonadIO m) => MonadBH (BH m) where
279 getBHEnv = BH getBHEnv
282instance (Functor m, Applicative m, MonadIO m) => MonadBH (ReaderT BHEnv m) where
285runBH :: BHEnv -> BH m a -> m a
286runBH e f = runReaderT (unBH f) e
288{-| 'Version' is embedded in 'Status' -}
289data Version = Version { number :: Text
291 , build_timestamp :: UTCTime
292 , build_snapshot :: Bool
293 , lucene_version :: Text } deriving (Eq, Show, Generic)
295{-| 'Status' is a data type for describing the JSON body returned by
296 Elasticsearch when you query its status. This was deprecated in 1.2.0.
298 <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-status.html#indices-status>
301data Status = Status { ok :: Maybe Bool
305 , tagline :: Text } deriving (Eq, Show)
307{-| 'IndexSettings' is used to configure the shards and replicas when you create
308 an Elasticsearch Index.
310 <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html>
314 IndexSettings { indexShards :: ShardCount
315 , indexReplicas :: ReplicaCount } deriving (Eq, Show)
317{-| 'defaultIndexSettings' is an 'IndexSettings' with 3 shards and 2 replicas. -}
318defaultIndexSettings :: IndexSettings
319defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
321{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
322type Reply = Network.HTTP.Client.Response L.ByteString
323type Method = NHTM.Method
325{-| 'OpenCloseIndex' is a sum type for opening and closing indices.
327 <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
329data OpenCloseIndex = OpenIndex | CloseIndex deriving (Eq, Show)
331data FieldType = GeoPointType
337 | ByteType deriving (Eq, Show)
339data FieldDefinition =
340 FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
343 MappingField { mappingFieldName :: FieldName
344 , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
346{-| Support for type reification of 'Mapping's is currently incomplete, for
347 now the mapping API verbiage expects a 'ToJSON'able blob.
349 Indexes have mappings, mappings are schemas for the documents contained in the
350 index. I'd recommend having only one mapping per index, always having a mapping,
351 and keeping different kinds of documents separated if possible.
353data Mapping = Mapping { typeName :: TypeName
354 , mappingFields :: [MappingField] } deriving (Eq, Show)
356{-| 'BulkOperation' is a sum type for expressing the four kinds of bulk
357 operation index, create, delete, and update. 'BulkIndex' behaves like an
358 "upsert", 'BulkCreate' will fail if a document already exists at the DocId.
360 <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html#docs-bulk>
363 BulkIndex IndexName MappingName DocId Value
364 | BulkCreate IndexName MappingName DocId Value
365 | BulkDelete IndexName MappingName DocId
366 | BulkUpdate IndexName MappingName DocId Value deriving (Eq, Show)
368{-| 'EsResult' describes the standard wrapper JSON document that you see in
369 successful Elasticsearch responses.
371data EsResult a = EsResult { _index :: Text
375 , found :: Maybe Bool
376 , _source :: a } deriving (Eq, Show)
378{-| 'Sort' is a synonym for a list of 'SortSpec's. Sort behavior is order
379 dependent with later sorts acting as tie-breakers for earlier sorts.
381type Sort = [SortSpec]
383{-| The two main kinds of 'SortSpec' are 'DefaultSortSpec' and
384 'GeoDistanceSortSpec'. The latter takes a 'SortOrder', 'GeoPoint', and
385 'DistanceUnit' to express "nearness" to a single geographical point as a
388<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
390data SortSpec = DefaultSortSpec DefaultSort
391 | GeoDistanceSortSpec SortOrder GeoPoint DistanceUnit deriving (Eq, Show)
393{-| 'DefaultSort' is usually the kind of 'SortSpec' you'll want. There's a
394 'mkSort' convenience function for when you want to specify only the most
397<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
400 DefaultSort { sortFieldName :: FieldName
401 , sortOrder :: SortOrder
403 , ignoreUnmapped :: Bool
404 , sortMode :: Maybe SortMode
405 , missingSort :: Maybe Missing
406 , nestedFilter :: Maybe Filter } deriving (Eq, Show)
408{-| 'SortOrder' is 'Ascending' or 'Descending', as you might expect. These get
409 encoded into "asc" or "desc" when turned into JSON.
411<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
413data SortOrder = Ascending
414 | Descending deriving (Eq, Show)
416{-| 'Missing' prescribes how to handle missing fields. A missing field can be
417 sorted last, first, or using a custom value as a substitute.
419<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_missing_values>
421data Missing = LastMissing
423 | CustomMissing Text deriving (Eq, Show)
425{-| 'SortMode' prescribes how to handle sorting array/multi-valued fields.
427http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_sort_mode_option
429data SortMode = SortMin
432 | SortAvg deriving (Eq, Show)
434{-| 'mkSort' defaults everything but the 'FieldName' and the 'SortOrder' so
435 that you can concisely describe the usual kind of 'SortSpec's you want.
437mkSort :: FieldName -> SortOrder -> DefaultSort
438mkSort fieldName sOrder = DefaultSort fieldName sOrder False Nothing Nothing Nothing
440{-| 'Cache' is for telling ES whether it should cache a 'Filter' not.
441 'Query's cannot be cached.
443type Cache = Bool -- caching on/off
447{-| 'PrefixValue' is used in 'PrefixQuery' as the main query component.
449type PrefixValue = Text
451{-| 'BooleanOperator' is the usual And/Or operators with an ES compatible
452 JSON encoding baked in. Used all over the place.
454data BooleanOperator = And | Or deriving (Eq, Show)
456{-| 'ShardCount' is part of 'IndexSettings'
458newtype ShardCount = ShardCount Int deriving (Eq, Show, Generic)
460{-| 'ReplicaCount' is part of 'IndexSettings'
462newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic)
464{-| 'Server' is used with the client functions to point at the ES instance
466newtype Server = Server Text deriving (Eq, Show)
468{-| 'IndexName' is used to describe which index to query/create/delete
470newtype IndexName = IndexName Text deriving (Eq, Generic, Show)
472{-| 'MappingName' is part of mappings which are how ES describes and schematizes
473 the data in the indices.
475newtype MappingName = MappingName Text deriving (Eq, Generic, Show)
477{-| 'DocId' is a generic wrapper value for expressing unique Document IDs.
478 Can be set by the user or created by ES itself. Often used in client
479 functions for poking at specific documents.
481newtype DocId = DocId Text deriving (Eq, Generic, Show)
483{-| 'QueryString' is used to wrap query text bodies, be they human written or not.
485newtype QueryString = QueryString Text deriving (Eq, Generic, Show)
487{-| 'FieldName' is used all over the place wherever a specific field within
488 a document needs to be specified, usually in 'Query's or 'Filter's.
490newtype FieldName = FieldName Text deriving (Eq, Show)
492{-| 'CacheName' is used in 'RegexpFilter' for describing the
493 'CacheKey' keyed caching behavior.
495newtype CacheName = CacheName Text deriving (Eq, Show)
497{-| 'CacheKey' is used in 'RegexpFilter' to key regex caching.
500 CacheKey Text deriving (Eq, Show)
502 Existence Bool deriving (Eq, Show)
504 NullValue Bool deriving (Eq, Show)
505newtype CutoffFrequency =
506 CutoffFrequency Double deriving (Eq, Show, Generic)
508 Analyzer Text deriving (Eq, Show, Generic)
509newtype MaxExpansions =
510 MaxExpansions Int deriving (Eq, Show, Generic)
512{-| 'Lenient', if set to true, will cause format based failures to be
513 ignored. I don't know what the bloody default is, Elasticsearch
514 documentation didn't say what it was. Let me know if you figure it out.
517 Lenient Bool deriving (Eq, Show, Generic)
519 Tiebreaker Double deriving (Eq, Show, Generic)
521 Boost Double deriving (Eq, Show, Generic)
523 BoostTerms Double deriving (Eq, Show, Generic)
525{-| 'MinimumMatch' controls how many should clauses in the bool query should
526 match. Can be an absolute value (2) or a percentage (30%) or a
529newtype MinimumMatch =
530 MinimumMatch Int deriving (Eq, Show, Generic)
531newtype MinimumMatchText =
532 MinimumMatchText Text deriving (Eq, Show)
533newtype DisableCoord =
534 DisableCoord Bool deriving (Eq, Show, Generic)
535newtype IgnoreTermFrequency =
536 IgnoreTermFrequency Bool deriving (Eq, Show, Generic)
537newtype MinimumTermFrequency =
538 MinimumTermFrequency Int deriving (Eq, Show, Generic)
539newtype MaxQueryTerms =
540 MaxQueryTerms Int deriving (Eq, Show, Generic)
542 Fuzziness Double deriving (Eq, Show, Generic)
544{-| 'PrefixLength' is the prefix length used in queries, defaults to 0. -}
545newtype PrefixLength =
546 PrefixLength Int deriving (Eq, Show, Generic)
548 TypeName Text deriving (Eq, Show, Generic)
549newtype PercentMatch =
550 PercentMatch Double deriving (Eq, Show, Generic)
552 StopWord Text deriving (Eq, Show, Generic)
554 QueryPath Text deriving (Eq, Show, Generic)
556{-| Allowing a wildcard at the beginning of a word (eg "*ing") is particularly
557 heavy, because all terms in the index need to be examined, just in case
558 they match. Leading wildcards can be disabled by setting
559 'AllowLeadingWildcard' to false. -}
560newtype AllowLeadingWildcard =
561 AllowLeadingWildcard Bool deriving (Eq, Show, Generic)
562newtype LowercaseExpanded =
563 LowercaseExpanded Bool deriving (Eq, Show, Generic)
564newtype EnablePositionIncrements =
565 EnablePositionIncrements Bool deriving (Eq, Show, Generic)
567{-| By default, wildcard terms in a query are not analyzed.
568 Setting 'AnalyzeWildcard' to true enables best-effort analysis.
570newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show, Generic)
572{-| 'GeneratePhraseQueries' defaults to false.
574newtype GeneratePhraseQueries =
575 GeneratePhraseQueries Bool deriving (Eq, Show, Generic)
577{-| 'Locale' is used for string conversions - defaults to ROOT.
579newtype Locale = Locale Text deriving (Eq, Show, Generic)
580newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show, Generic)
581newtype MinWordLength = MinWordLength Int deriving (Eq, Show, Generic)
583{-| 'PhraseSlop' sets the default slop for phrases, 0 means exact
584 phrase matches. Default is 0.
586newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show, Generic)
587newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show, Generic)
588newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic)
590{-| 'unpackId' is a silly convenience function that gets used once.
592unpackId :: DocId -> Text
593unpackId (DocId docId) = docId
595type TrackSortScores = Bool
596newtype From = From Int deriving (Eq, Show, ToJSON)
597newtype Size = Size Int deriving (Eq, Show, ToJSON)
599data Search = Search { queryBody :: Maybe Query
600 , filterBody :: Maybe Filter
601 , sortBody :: Maybe Sort
602 , aggBody :: Maybe Aggregations
603 , highlight :: Maybe Highlights
605 , trackSortScores :: TrackSortScores
607 , size :: Size } deriving (Eq, Show)
609data Highlights = Highlights { globalsettings :: Maybe HighlightSettings
610 , highlightFields :: [FieldHighlight]
611 } deriving (Show, Eq)
613data FieldHighlight = FieldHighlight FieldName (Maybe HighlightSettings)
617data HighlightSettings = Plain PlainHighlight
618 | Postings PostingsHighlight
619 | FastVector FastVectorHighlight
622 PlainHighlight { plainCommon :: Maybe CommonHighlight
623 , plainNonPost :: Maybe NonPostings } deriving (Show, Eq)
625 -- This requires that index_options are set to 'offset' in the mapping.
626data PostingsHighlight = PostingsHighlight (Maybe CommonHighlight) deriving (Show, Eq)
628-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
629data FastVectorHighlight =
630 FastVectorHighlight { fvCommon :: Maybe CommonHighlight
631 , fvNonPostSettings :: Maybe NonPostings
632 , boundaryChars :: Maybe Text
633 , boundaryMaxScan :: Maybe Int
634 , fragmentOffset :: Maybe Int
635 , matchedFields :: [Text]
636 , phraseLimit :: Maybe Int
637 } deriving (Show, Eq)
639data CommonHighlight =
640 CommonHighlight { order :: Maybe Text
641 , forceSource :: Maybe Bool
642 , tag :: Maybe HighlightTag
643 , encoder :: Maybe HighlightEncoder
644 , noMatchSize :: Maybe Int
645 , highlightQuery :: Maybe Query
646 , requireFieldMatch :: Maybe Bool
647 } deriving (Show, Eq)
649-- Settings that are only applicable to FastVector and Plain highlighters.
651 NonPostings { fragmentSize :: Maybe Int
652 , numberOfFragments :: Maybe Int} deriving (Show, Eq)
654data HighlightEncoder = DefaultEncoder
658-- NOTE: Should the tags use some kind of HTML type, rather than Text?
659data HighlightTag = TagSchema Text
660 | CustomTags ([Text], [Text]) -- Only uses more than the first value in the lists if fvh
665 TermQuery Term (Maybe Boost)
666 | TermsQuery (NonEmpty Term)
667 | QueryMatchQuery MatchQuery
668 | QueryMultiMatchQuery MultiMatchQuery
669 | QueryBoolQuery BoolQuery
670 | QueryBoostingQuery BoostingQuery
671 | QueryCommonTermsQuery CommonTermsQuery
672 | ConstantScoreFilter Filter Boost
673 | ConstantScoreQuery Query Boost
674 | QueryDisMaxQuery DisMaxQuery
675 | QueryFilteredQuery FilteredQuery
676 | QueryFuzzyLikeThisQuery FuzzyLikeThisQuery
677 | QueryFuzzyLikeFieldQuery FuzzyLikeFieldQuery
678 | QueryFuzzyQuery FuzzyQuery
679 | QueryHasChildQuery HasChildQuery
680 | QueryHasParentQuery HasParentQuery
681 | IdsQuery MappingName [DocId]
682 | QueryIndicesQuery IndicesQuery
683 | MatchAllQuery (Maybe Boost)
684 | QueryMoreLikeThisQuery MoreLikeThisQuery
685 | QueryMoreLikeThisFieldQuery MoreLikeThisFieldQuery
686 | QueryNestedQuery NestedQuery
687 | QueryPrefixQuery PrefixQuery
688 | QueryQueryStringQuery QueryStringQuery
689 | QuerySimpleQueryStringQuery SimpleQueryStringQuery
690 | QueryRangeQuery RangeQuery
691 | QueryRegexpQuery RegexpQuery
695 RegexpQuery { regexpQueryField :: FieldName
696 , regexpQuery :: Regexp
697 , regexpQueryFlags :: RegexpFlags
698 , regexpQueryBoost :: Maybe Boost
699 } deriving (Eq, Show)
702 RangeQuery { rangeQueryField :: FieldName
703 , rangeQueryRange :: RangeValue
704 , rangeQueryBoost :: Boost } deriving (Eq, Show)
706mkRangeQuery :: FieldName -> RangeValue -> RangeQuery
707mkRangeQuery f r = RangeQuery f r (Boost 1.0)
709data SimpleQueryStringQuery =
710 SimpleQueryStringQuery
711 { simpleQueryStringQuery :: QueryString
712 , simpleQueryStringField :: Maybe FieldOrFields
713 , simpleQueryStringOperator :: Maybe BooleanOperator
714 , simpleQueryStringAnalyzer :: Maybe Analyzer
715 , simpleQueryStringFlags :: Maybe [SimpleQueryFlag]
716 , simpleQueryStringLowercaseExpanded :: Maybe LowercaseExpanded
717 , simpleQueryStringLocale :: Maybe Locale
718 } deriving (Eq, Show)
720data SimpleQueryFlag =
727 | SimpleQueryPrecedence
729 | SimpleQueryWhitespace
732 | SimpleQuerySlop deriving (Eq, Show)
734-- use_dis_max and tie_breaker when fields are plural?
735data QueryStringQuery =
737 { queryStringQuery :: QueryString
738 , queryStringDefaultField :: Maybe FieldName
739 , queryStringOperator :: Maybe BooleanOperator
740 , queryStringAnalyzer :: Maybe Analyzer
741 , queryStringAllowLeadingWildcard :: Maybe AllowLeadingWildcard
742 , queryStringLowercaseExpanded :: Maybe LowercaseExpanded
743 , queryStringEnablePositionIncrements :: Maybe EnablePositionIncrements
744 , queryStringFuzzyMaxExpansions :: Maybe MaxExpansions
745 , queryStringFuzziness :: Maybe Fuzziness
746 , queryStringFuzzyPrefixLength :: Maybe PrefixLength
747 , queryStringPhraseSlop :: Maybe PhraseSlop
748 , queryStringBoost :: Maybe Boost
749 , queryStringAnalyzeWildcard :: Maybe AnalyzeWildcard
750 , queryStringGeneratePhraseQueries :: Maybe GeneratePhraseQueries
751 , queryStringMinimumShouldMatch :: Maybe MinimumMatch
752 , queryStringLenient :: Maybe Lenient
753 , queryStringLocale :: Maybe Locale
754 } deriving (Eq, Show)
756mkQueryStringQuery :: QueryString -> QueryStringQuery
757mkQueryStringQuery qs =
758 QueryStringQuery qs Nothing Nothing
759 Nothing Nothing Nothing Nothing
760 Nothing Nothing Nothing Nothing
761 Nothing Nothing Nothing Nothing
764data FieldOrFields = FofField FieldName
765 | FofFields [FieldName] deriving (Eq, Show)
769 { prefixQueryField :: FieldName
770 , prefixQueryPrefixValue :: Text
771 , prefixQueryBoost :: Maybe Boost } deriving (Eq, Show)
775 { nestedQueryPath :: QueryPath
776 , nestedQueryScoreType :: ScoreType
777 , nestedQuery :: Query } deriving (Eq, Show)
779data MoreLikeThisFieldQuery =
780 MoreLikeThisFieldQuery
781 { moreLikeThisFieldText :: Text
782 , moreLikeThisFieldFields :: FieldName
784 , moreLikeThisFieldPercentMatch :: Maybe PercentMatch
785 , moreLikeThisFieldMinimumTermFreq :: Maybe MinimumTermFrequency
786 , moreLikeThisFieldMaxQueryTerms :: Maybe MaxQueryTerms
787 , moreLikeThisFieldStopWords :: Maybe [StopWord]
788 , moreLikeThisFieldMinDocFrequency :: Maybe MinDocFrequency
789 , moreLikeThisFieldMaxDocFrequency :: Maybe MaxDocFrequency
790 , moreLikeThisFieldMinWordLength :: Maybe MinWordLength
791 , moreLikeThisFieldMaxWordLength :: Maybe MaxWordLength
792 , moreLikeThisFieldBoostTerms :: Maybe BoostTerms
793 , moreLikeThisFieldBoost :: Maybe Boost
794 , moreLikeThisFieldAnalyzer :: Maybe Analyzer
795 } deriving (Eq, Show)
797data MoreLikeThisQuery =
799 { moreLikeThisText :: Text
800 , moreLikeThisFields :: Maybe [FieldName]
802 , moreLikeThisPercentMatch :: Maybe PercentMatch
803 , moreLikeThisMinimumTermFreq :: Maybe MinimumTermFrequency
804 , moreLikeThisMaxQueryTerms :: Maybe MaxQueryTerms
805 , moreLikeThisStopWords :: Maybe [StopWord]
806 , moreLikeThisMinDocFrequency :: Maybe MinDocFrequency
807 , moreLikeThisMaxDocFrequency :: Maybe MaxDocFrequency
808 , moreLikeThisMinWordLength :: Maybe MinWordLength
809 , moreLikeThisMaxWordLength :: Maybe MaxWordLength
810 , moreLikeThisBoostTerms :: Maybe BoostTerms
811 , moreLikeThisBoost :: Maybe Boost
812 , moreLikeThisAnalyzer :: Maybe Analyzer
813 } deriving (Eq, Show)
817 { indicesQueryIndices :: [IndexName]
818 , indicesQuery :: Query
820 , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
824 { hasParentQueryType :: TypeName
825 , hasParentQuery :: Query
826 , hasParentQueryScoreType :: Maybe ScoreType } deriving (Eq, Show)
830 { hasChildQueryType :: TypeName
831 , hasChildQuery :: Query
832 , hasChildQueryScoreType :: Maybe ScoreType } deriving (Eq, Show)
838 | ScoreTypeNone deriving (Eq, Show)
841 FuzzyQuery { fuzzyQueryField :: FieldName
842 , fuzzyQueryValue :: Text
843 , fuzzyQueryPrefixLength :: PrefixLength
844 , fuzzyQueryMaxExpansions :: MaxExpansions
845 , fuzzyQueryFuzziness :: Fuzziness
846 , fuzzyQueryBoost :: Maybe Boost
847 } deriving (Eq, Show)
849data FuzzyLikeFieldQuery =
851 { fuzzyLikeField :: FieldName
852 -- anaphora is good for the soul.
853 , fuzzyLikeFieldText :: Text
854 , fuzzyLikeFieldMaxQueryTerms :: MaxQueryTerms
855 , fuzzyLikeFieldIgnoreTermFrequency :: IgnoreTermFrequency
856 , fuzzyLikeFieldFuzziness :: Fuzziness
857 , fuzzyLikeFieldPrefixLength :: PrefixLength
858 , fuzzyLikeFieldBoost :: Boost
859 , fuzzyLikeFieldAnalyzer :: Maybe Analyzer
860 } deriving (Eq, Show)
862data FuzzyLikeThisQuery =
864 { fuzzyLikeFields :: [FieldName]
865 , fuzzyLikeText :: Text
866 , fuzzyLikeMaxQueryTerms :: MaxQueryTerms
867 , fuzzyLikeIgnoreTermFrequency :: IgnoreTermFrequency
868 , fuzzyLikeFuzziness :: Fuzziness
869 , fuzzyLikePrefixLength :: PrefixLength
870 , fuzzyLikeBoost :: Boost
871 , fuzzyLikeAnalyzer :: Maybe Analyzer
872 } deriving (Eq, Show)
876 { filteredQuery :: Query
877 , filteredFilter :: Filter } deriving (Eq, Show)
880 DisMaxQuery { disMaxQueries :: [Query]
882 , disMaxTiebreaker :: Tiebreaker
883 , disMaxBoost :: Maybe Boost
884 } deriving (Eq, Show)
887 MatchQuery { matchQueryField :: FieldName
888 , matchQueryQueryString :: QueryString
889 , matchQueryOperator :: BooleanOperator
890 , matchQueryZeroTerms :: ZeroTermsQuery
891 , matchQueryCutoffFrequency :: Maybe CutoffFrequency
892 , matchQueryMatchType :: Maybe MatchQueryType
893 , matchQueryAnalyzer :: Maybe Analyzer
894 , matchQueryMaxExpansions :: Maybe MaxExpansions
895 , matchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
897{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
898 enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
900mkMatchQuery :: FieldName -> QueryString -> MatchQuery
901mkMatchQuery field query = MatchQuery field query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing
905 | MatchPhrasePrefix deriving (Eq, Show)
907data MultiMatchQuery =
908 MultiMatchQuery { multiMatchQueryFields :: [FieldName]
909 , multiMatchQueryString :: QueryString
910 , multiMatchQueryOperator :: BooleanOperator
911 , multiMatchQueryZeroTerms :: ZeroTermsQuery
912 , multiMatchQueryTiebreaker :: Maybe Tiebreaker
913 , multiMatchQueryType :: Maybe MultiMatchQueryType
914 , multiMatchQueryCutoffFrequency :: Maybe CutoffFrequency
915 , multiMatchQueryAnalyzer :: Maybe Analyzer
916 , multiMatchQueryMaxExpansions :: Maybe MaxExpansions
917 , multiMatchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
919{-| 'mkMultiMatchQuery' is a convenience function that defaults the less common parameters,
920 enabling you to provide only the list of 'FieldName's and 'QueryString' to
921 make a 'MultiMatchQuery'.
924mkMultiMatchQuery :: [FieldName] -> QueryString -> MultiMatchQuery
925mkMultiMatchQuery matchFields query =
926 MultiMatchQuery matchFields query
927 Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
929data MultiMatchQueryType =
931 | MultiMatchMostFields
932 | MultiMatchCrossFields
934 | MultiMatchPhrasePrefix deriving (Eq, Show)
937 BoolQuery { boolQueryMustMatch :: [Query]
938 , boolQueryMustNotMatch :: [Query]
939 , boolQueryShouldMatch :: [Query]
940 , boolQueryMinimumShouldMatch :: Maybe MinimumMatch
941 , boolQueryBoost :: Maybe Boost
942 , boolQueryDisableCoord :: Maybe DisableCoord
943 } deriving (Eq, Show)
945mkBoolQuery :: [Query] -> [Query] -> [Query] -> BoolQuery
946mkBoolQuery must mustNot should =
947 BoolQuery must mustNot should Nothing Nothing Nothing
950 BoostingQuery { positiveQuery :: Query
951 , negativeQuery :: Query
952 , negativeBoost :: Boost } deriving (Eq, Show)
954data CommonTermsQuery =
955 CommonTermsQuery { commonField :: FieldName
956 , commonQuery :: QueryString
957 , commonCutoffFrequency :: CutoffFrequency
958 , commonLowFreqOperator :: BooleanOperator
959 , commonHighFreqOperator :: BooleanOperator
960 , commonMinimumShouldMatch :: Maybe CommonMinimumMatch
961 , commonBoost :: Maybe Boost
962 , commonAnalyzer :: Maybe Analyzer
963 , commonDisableCoord :: Maybe DisableCoord
964 } deriving (Eq, Show)
966data CommonMinimumMatch =
967 CommonMinimumMatchHighLow MinimumMatchHighLow
968 | CommonMinimumMatch MinimumMatch
971data MinimumMatchHighLow =
972 MinimumMatchHighLow { lowFreq :: MinimumMatch
973 , highFreq :: MinimumMatch } deriving (Eq, Show)
975data Filter = AndFilter [Filter] Cache
976 | OrFilter [Filter] Cache
977 | NotFilter Filter Cache
979 | BoolFilter BoolMatch
980 | ExistsFilter FieldName -- always cached
981 | GeoBoundingBoxFilter GeoBoundingBoxConstraint
982 | GeoDistanceFilter GeoPoint Distance DistanceType OptimizeBbox Cache
983 | GeoDistanceRangeFilter GeoPoint DistanceRange
984 | GeoPolygonFilter FieldName [LatLon]
985 | IdsFilter MappingName [DocId]
987 | MissingFilter FieldName Existence NullValue
988 | PrefixFilter FieldName PrefixValue Cache
989 | RangeFilter FieldName RangeValue RangeExecution Cache
990 | RegexpFilter FieldName Regexp RegexpFlags CacheName Cache CacheKey
991 | TermFilter Term Cache
994data ZeroTermsQuery = ZeroTermsNone
995 | ZeroTermsAll deriving (Eq, Show)
997data RangeExecution = RangeExecutionIndex
998 | RangeExecutionFielddata deriving (Eq, Show)
1000newtype Regexp = Regexp Text deriving (Eq, Show)
1002data RegexpFlags = AllRegexpFlags
1004 | SomeRegexpFlags (NonEmpty RegexpFlag) deriving (Eq, Show)
1006data RegexpFlag = AnyString
1011 | Interval deriving (Eq, Show)
1013newtype LessThan = LessThan Double deriving (Eq, Show)
1014newtype LessThanEq = LessThanEq Double deriving (Eq, Show)
1015newtype GreaterThan = GreaterThan Double deriving (Eq, Show)
1016newtype GreaterThanEq = GreaterThanEq Double deriving (Eq, Show)
1018newtype LessThanD = LessThanD UTCTime deriving (Eq, Show)
1019newtype LessThanEqD = LessThanEqD UTCTime deriving (Eq, Show)
1020newtype GreaterThanD = GreaterThanD UTCTime deriving (Eq, Show)
1021newtype GreaterThanEqD = GreaterThanEqD UTCTime deriving (Eq, Show)
1023data RangeValue = RangeDateLte LessThanEqD
1024 | RangeDateLt LessThanD
1025 | RangeDateGte GreaterThanEqD
1026 | RangeDateGt GreaterThanD
1027 | RangeDateGtLt GreaterThanD LessThanD
1028 | RangeDateGteLte GreaterThanEqD LessThanEqD
1029 | RangeDateGteLt GreaterThanEqD LessThanD
1030 | RangeDateGtLte GreaterThanD LessThanEqD
1031 | RangeDoubleLte LessThanEq
1032 | RangeDoubleLt LessThan
1033 | RangeDoubleGte GreaterThanEq
1034 | RangeDoubleGt GreaterThan
1035 | RangeDoubleGtLt GreaterThan LessThan
1036 | RangeDoubleGteLte GreaterThanEq LessThanEq
1037 | RangeDoubleGteLt GreaterThanEq LessThan
1038 | RangeDoubleGtLte GreaterThan LessThanEq
1041rangeValueToPair :: RangeValue -> [Pair]
1042rangeValueToPair rv = case rv of
1043 RangeDateLte (LessThanEqD t) -> ["lte" .= t]
1044 RangeDateGte (GreaterThanEqD t) -> ["gte" .= t]
1045 RangeDateLt (LessThanD t) -> ["lt" .= t]
1046 RangeDateGt (GreaterThanD t) -> ["gt" .= t]
1047 RangeDateGteLte (GreaterThanEqD l) (LessThanEqD g) -> ["gte" .= l, "lte" .= g]
1048 RangeDateGtLte (GreaterThanD l) (LessThanEqD g) -> ["gt" .= l, "lte" .= g]
1049 RangeDateGteLt (GreaterThanEqD l) (LessThanD g) -> ["gte" .= l, "lt" .= g]
1050 RangeDateGtLt (GreaterThanD l) (LessThanD g) -> ["gt" .= l, "lt" .= g]
1051 RangeDoubleLte (LessThanEq t) -> ["lte" .= t]
1052 RangeDoubleGte (GreaterThanEq t) -> ["gte" .= t]
1053 RangeDoubleLt (LessThan t) -> ["lt" .= t]
1054 RangeDoubleGt (GreaterThan t) -> ["gt" .= t]
1055 RangeDoubleGteLte (GreaterThanEq l) (LessThanEq g) -> ["gte" .= l, "lte" .= g]
1056 RangeDoubleGtLte (GreaterThan l) (LessThanEq g) -> ["gt" .= l, "lte" .= g]
1057 RangeDoubleGteLt (GreaterThanEq l) (LessThan g) -> ["gte" .= l, "lt" .= g]
1058 RangeDoubleGtLt (GreaterThan l) (LessThan g) -> ["gt" .= l, "lt" .= g]
1060data Term = Term { termField :: Text
1061 , termValue :: Text } deriving (Eq, Show)
1063data BoolMatch = MustMatch Term Cache
1064 | MustNotMatch Term Cache
1065 | ShouldMatch [Term] Cache deriving (Eq, Show)
1067-- "memory" or "indexed"
1068data GeoFilterType = GeoFilterMemory
1069 | GeoFilterIndexed deriving (Eq, Show)
1071data LatLon = LatLon { lat :: Double
1072 , lon :: Double } deriving (Eq, Show)
1074data GeoBoundingBox =
1075 GeoBoundingBox { topLeft :: LatLon
1076 , bottomRight :: LatLon } deriving (Eq, Show)
1078data GeoBoundingBoxConstraint =
1079 GeoBoundingBoxConstraint { geoBBField :: FieldName
1080 , constraintBox :: GeoBoundingBox
1081 , bbConstraintcache :: Cache
1082 , geoType :: GeoFilterType
1083 } deriving (Eq, Show)
1086 GeoPoint { geoField :: FieldName
1087 , latLon :: LatLon} deriving (Eq, Show)
1089data DistanceUnit = Miles
1097 | NauticalMiles deriving (Eq, Show)
1099data DistanceType = Arc
1100 | SloppyArc -- doesn't exist <1.0
1101 | Plane deriving (Eq, Show)
1103data OptimizeBbox = OptimizeGeoFilterType GeoFilterType
1104 | NoOptimizeBbox deriving (Eq, Show)
1107 Distance { coefficient :: Double
1108 , unit :: DistanceUnit } deriving (Eq, Show)
1111 DistanceRange { distanceFrom :: Distance
1112 , distanceTo :: Distance } deriving (Eq, Show)
1114data SearchResult a =
1115 SearchResult { took :: Int
1117 , shards :: ShardResult
1118 , searchHits :: SearchHits a
1119 , aggregations :: Maybe AggregationResults } deriving (Eq, Show)
1121type Score = Maybe Double
1124 SearchHits { hitsTotal :: Int
1126 , hits :: [Hit a] } deriving (Eq, Show)
1129instance Monoid (SearchHits a) where
1130 mempty = SearchHits 0 Nothing mempty
1131 mappend (SearchHits ta ma ha) (SearchHits tb mb hb) =
1132 SearchHits (ta + tb) (max ma mb) (ha <> hb)
1136 Hit { hitIndex :: IndexName
1137 , hitType :: MappingName
1141 , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show)
1144 ShardResult { shardTotal :: Int
1145 , shardsSuccessful :: Int
1146 , shardsFailed :: Int } deriving (Eq, Show, Generic)
1148type HitHighlight = M.Map Text [Text]
1150showText :: Show a => a -> Text
1151showText = T.pack . show
1153type Aggregations = M.Map Text Aggregation
1155emptyAggregations :: Aggregations
1156emptyAggregations = M.empty
1158mkAggregations :: Text -> Aggregation -> Aggregations
1159mkAggregations name aggregation = M.insert name aggregation emptyAggregations
1161data TermOrder = TermOrder{ termSortField :: Text
1162 , termSortOrder :: SortOrder } deriving (Eq, Show)
1164data TermInclusion = TermInclusion Text
1165 | TermPattern Text Text deriving (Eq, Show)
1167data CollectionMode = BreadthFirst
1168 | DepthFirst deriving (Eq, Show)
1170data ExecutionHint = Ordinals
1172 | GlobalOrdinalsHash
1173 | GlobalOrdinalsLowCardinality
1174 | Map deriving (Eq, Show)
1176data TimeInterval = Weeks
1180 | Seconds deriving (Eq)
1190 | FractionalInterval Float TimeInterval deriving (Eq, Show)
1192data Aggregation = TermsAgg TermsAggregation
1193 | DateHistogramAgg DateHistogramAggregation deriving (Eq, Show)
1196data TermsAggregation = TermsAggregation { term :: Either Text Text
1197 , termInclude :: Maybe TermInclusion
1198 , termExclude :: Maybe TermInclusion
1199 , termOrder :: Maybe TermOrder
1200 , termMinDocCount :: Maybe Int
1201 , termSize :: Maybe Int
1202 , termShardSize :: Maybe Int
1203 , termCollectMode :: Maybe CollectionMode
1204 , termExecutionHint :: Maybe ExecutionHint
1205 , termAggs :: Maybe Aggregations
1206 } deriving (Eq, Show)
1208data DateHistogramAggregation = DateHistogramAggregation { dateField :: FieldName
1209 , dateInterval :: Interval
1210 , dateFormat :: Maybe Text
1211 , datePreZone :: Maybe Text
1212 , datePostZone :: Maybe Text
1213 , datePreOffset :: Maybe Text
1214 , datePostOffset :: Maybe Text
1215 , dateAggs :: Maybe Aggregations
1216 } deriving (Eq, Show)
1219mkTermsAggregation :: Text -> TermsAggregation
1220mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1222mkTermsScriptAggregation :: Text -> TermsAggregation
1223mkTermsScriptAggregation t = TermsAggregation (Right t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1225mkDateHistogram :: FieldName -> Interval -> DateHistogramAggregation
1226mkDateHistogram t i = DateHistogramAggregation t i Nothing Nothing Nothing Nothing Nothing Nothing
1228instance ToJSON TermOrder where
1229 toJSON (TermOrder termSortField termSortOrder) = object [termSortField .= termSortOrder]
1231instance ToJSON TermInclusion where
1232 toJSON (TermInclusion x) = toJSON x
1233 toJSON (TermPattern pattern flags) = omitNulls [ "pattern" .= pattern,
1236instance ToJSON CollectionMode where
1237 toJSON BreadthFirst = "breadth_first"
1238 toJSON DepthFirst = "depth_first"
1240instance ToJSON ExecutionHint where
1241 toJSON Ordinals = "ordinals"
1242 toJSON GlobalOrdinals = "global_ordinals"
1243 toJSON GlobalOrdinalsHash = "global_ordinals_hash"
1244 toJSON GlobalOrdinalsLowCardinality = "global_ordinals_low_cardinality"
1247instance ToJSON Interval where
1248 toJSON Year = "year"
1249 toJSON Quarter = "quarter"
1250 toJSON Month = "month"
1251 toJSON Week = "week"
1253 toJSON Hour = "hour"
1254 toJSON Minute = "minute"
1255 toJSON Second = "second"
1256 toJSON (FractionalInterval fraction interval) = toJSON $ show fraction ++ show interval
1258instance Show TimeInterval where
1265instance ToJSON Aggregation where
1266 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1267 omitNulls ["terms" .= omitNulls [ toJSON' term,
1268 "include" .= include,
1269 "exclude" .= exclude,
1271 "min_doc_count" .= minDocCount,
1273 "shard_size" .= shardSize,
1274 "collect_mode" .= collectMode,
1275 "execution_hint" .= executionHint
1277 "aggs" .= termAggs ]
1279 toJSON' x = case x of { Left y -> "field" .= y; Right y -> "script" .= y }
1281 toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
1282 omitNulls ["date_histogram" .= omitNulls [ "field" .= field,
1283 "interval" .= interval,
1285 "pre_zone" .= preZone,
1286 "post_zone" .= postZone,
1287 "pre_offset" .= preOffset,
1288 "post_offset" .= postOffset
1290 "aggs" .= dateHistoAggs ]
1292type AggregationResults = M.Map Text Value
1294class BucketAggregation a where
1296 docCount :: a -> Int
1297 aggs :: a -> Maybe AggregationResults
1300data Bucket a = Bucket { buckets :: [a]} deriving (Show)
1302data TermsResult = TermsResult { termKey :: Text
1303 , termsDocCount :: Int
1304 , termsAggs :: Maybe AggregationResults } deriving (Show)
1306data DateHistogramResult = DateHistogramResult { dateKey :: Int
1307 , dateKeyStr :: Maybe Text
1308 , dateDocCount :: Int
1309 , dateHistogramAggs :: Maybe AggregationResults } deriving (Show)
1311toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1312toTerms t a = M.lookup t a >>= deserialize
1313 where deserialize = parseMaybe parseJSON
1315toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1316toDateHistogram t a = M.lookup t a >>= deserialize
1317 where deserialize = parseMaybe parseJSON
1319instance BucketAggregation TermsResult where
1321 docCount = termsDocCount
1324instance BucketAggregation DateHistogramResult where
1325 key = showText . dateKey
1326 docCount = dateDocCount
1327 aggs = dateHistogramAggs
1329instance (FromJSON a, BucketAggregation a) => FromJSON (Bucket a) where
1330 parseJSON (Object v) = Bucket <$>
1332 parseJSON _ = mempty
1334instance FromJSON TermsResult where
1335 parseJSON (Object v) = TermsResult <$>
1337 v .: "doc_count" <*>
1338 v .:? "aggregations"
1339 parseJSON _ = mempty
1341instance FromJSON DateHistogramResult where
1342 parseJSON (Object v) = DateHistogramResult <$>
1344 v .:? "key_as_string" <*>
1345 v .: "doc_count" <*>
1346 v .:? "aggregations"
1347 parseJSON _ = mempty
1349instance Monoid Filter where
1350 mempty = IdentityFilter
1351 mappend a b = AndFilter [a, b] defaultCache
1353instance Seminearring Filter where
1354 a <||> b = OrFilter [a, b] defaultCache
1356instance ToJSON Filter where
1357 toJSON (AndFilter filters cache) =
1359 object [ "filters" .= fmap toJSON filters
1360 , "_cache" .= cache]]
1362 toJSON (OrFilter filters cache) =
1364 object [ "filters" .= fmap toJSON filters
1365 , "_cache" .= cache]]
1367 toJSON (NotFilter notFilter cache) =
1369 object ["filter" .= notFilter
1370 , "_cache" .= cache]]
1372 toJSON (IdentityFilter) =
1373 object ["match_all" .= object []]
1375 toJSON (TermFilter (Term termFilterField termFilterValue) cache) =
1376 object ["term" .= object base]
1377 where base = [termFilterField .= termFilterValue,
1380 toJSON (ExistsFilter (FieldName fieldName)) =
1381 object ["exists" .= object
1382 ["field" .= fieldName]]
1384 toJSON (BoolFilter boolMatch) =
1385 object ["bool" .= boolMatch]
1387 toJSON (GeoBoundingBoxFilter bbConstraint) =
1388 object ["geo_bounding_box" .= bbConstraint]
1390 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1391 distance distanceType optimizeBbox cache) =
1392 object ["geo_distance" .=
1393 object ["distance" .= distance
1394 , "distance_type" .= distanceType
1395 , "optimize_bbox" .= optimizeBbox
1396 , distanceGeoField .= geoDistLatLon
1397 , "_cache" .= cache]]
1399 toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1400 (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1401 object ["geo_distance_range" .=
1402 object ["from" .= geoDistRangeDistFrom
1403 , "to" .= drDistanceTo
1404 , gddrField .= drLatLon]]
1406 toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1407 object ["geo_polygon" .=
1408 object [geoPolygonFilterField .=
1409 object ["points" .= fmap toJSON latLons]]]
1411 toJSON (IdsFilter (MappingName mappingName) values) =
1413 object ["type" .= mappingName
1414 , "values" .= fmap unpackId values]]
1416 toJSON (LimitFilter limit) =
1417 object ["limit" .= object ["value" .= limit]]
1419 toJSON (MissingFilter (FieldName fieldName) (Existence existence) (NullValue nullValue)) =
1420 object ["missing" .=
1421 object ["field" .= fieldName
1422 , "existence" .= existence
1423 , "null_value" .= nullValue]]
1425 toJSON (PrefixFilter (FieldName fieldName) fieldValue cache) =
1427 object [fieldName .= fieldValue
1428 , "_cache" .= cache]]
1430 toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1432 object [ fieldName .= object (rangeValueToPair rangeValue)
1433 , "execution" .= rangeExecution
1434 , "_cache" .= cache]]
1436 toJSON (RegexpFilter (FieldName fieldName)
1437 (Regexp regexText) flags (CacheName cacheName) cache (CacheKey cacheKey)) =
1439 object [fieldName .=
1440 object ["value" .= regexText
1442 , "_name" .= cacheName
1444 , "_cache_key" .= cacheKey]]
1446instance ToJSON GeoPoint where
1447 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1448 object [ geoPointField .= geoPointLatLon ]
1451instance ToJSON Query where
1452 toJSON (TermQuery (Term termQueryField termQueryValue) boost) =
1454 object [termQueryField .= object merged]]
1456 base = [ "value" .= termQueryValue ]
1457 boosted = maybe [] (return . ("boost" .=)) boost
1458 merged = mappend base boosted
1460 toJSON (TermsQuery terms) =
1461 object [ "terms" .= object conjoined ]
1462 where conjoined = [ getTermsField terms .=
1463 fmap (toJSON . getTermValue) (toList terms)]
1464 getTermsField ((Term f _ ) :| _) = f
1465 getTermValue (Term _ v) = v
1466 toJSON (IdsQuery idsQueryMappingName docIds) =
1467 object [ "ids" .= object conjoined ]
1468 where conjoined = [ "type" .= idsQueryMappingName
1469 , "values" .= fmap toJSON docIds ]
1471 toJSON (QueryQueryStringQuery qQueryStringQuery) =
1472 object [ "query_string" .= qQueryStringQuery ]
1474 toJSON (QueryMatchQuery matchQuery) =
1475 object [ "match" .= matchQuery ]
1477 toJSON (QueryMultiMatchQuery multiMatchQuery) =
1478 toJSON multiMatchQuery
1480 toJSON (QueryBoolQuery boolQuery) =
1481 object [ "bool" .= boolQuery ]
1483 toJSON (QueryBoostingQuery boostingQuery) =
1484 object [ "boosting" .= boostingQuery ]
1486 toJSON (QueryCommonTermsQuery commonTermsQuery) =
1487 object [ "common" .= commonTermsQuery ]
1489 toJSON (ConstantScoreFilter csFilter boost) =
1490 object [ "constant_score" .= csFilter
1493 toJSON (ConstantScoreQuery query boost) =
1494 object [ "constant_score" .= query
1497 toJSON (QueryDisMaxQuery disMaxQuery) =
1498 object [ "dis_max" .= disMaxQuery ]
1500 toJSON (QueryFilteredQuery qFilteredQuery) =
1501 object [ "filtered" .= qFilteredQuery ]
1503 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1504 object [ "fuzzy_like_this" .= fuzzyQuery ]
1506 toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1507 object [ "fuzzy_like_this_field" .= fuzzyFieldQuery ]
1509 toJSON (QueryFuzzyQuery fuzzyQuery) =
1510 object [ "fuzzy" .= fuzzyQuery ]
1512 toJSON (QueryHasChildQuery childQuery) =
1513 object [ "has_child" .= childQuery ]
1515 toJSON (QueryHasParentQuery parentQuery) =
1516 object [ "has_parent" .= parentQuery ]
1518 toJSON (QueryIndicesQuery qIndicesQuery) =
1519 object [ "indices" .= qIndicesQuery ]
1521 toJSON (MatchAllQuery boost) =
1522 object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1524 toJSON (QueryMoreLikeThisQuery query) =
1525 object [ "more_like_this" .= query ]
1527 toJSON (QueryMoreLikeThisFieldQuery query) =
1528 object [ "more_like_this_field" .= query ]
1530 toJSON (QueryNestedQuery query) =
1531 object [ "nested" .= query ]
1533 toJSON (QueryPrefixQuery query) =
1534 object [ "prefix" .= query ]
1536 toJSON (QueryRangeQuery query) =
1537 object [ "range" .= query ]
1539 toJSON (QueryRegexpQuery query) =
1540 object [ "regexp" .= query ]
1542 toJSON (QuerySimpleQueryStringQuery query) =
1543 object [ "simple_query_string" .= query ]
1546omitNulls :: [(Text, Value)] -> Value
1547omitNulls = object . filter notNull where
1548 notNull (_, Null) = False
1549 notNull (_, Array a) = (not . V.null) a
1553instance ToJSON SimpleQueryStringQuery where
1554 toJSON SimpleQueryStringQuery {..} =
1555 omitNulls (base ++ maybeAdd)
1556 where base = [ "query" .= simpleQueryStringQuery ]
1557 maybeAdd = [ "fields" .= simpleQueryStringField
1558 , "default_operator" .= simpleQueryStringOperator
1559 , "analyzer" .= simpleQueryStringAnalyzer
1560 , "flags" .= simpleQueryStringFlags
1561 , "lowercase_expanded_terms" .= simpleQueryStringLowercaseExpanded
1562 , "locale" .= simpleQueryStringLocale ]
1565instance ToJSON FieldOrFields where
1566 toJSON (FofField fieldName) =
1568 toJSON (FofFields fieldNames) =
1571instance ToJSON SimpleQueryFlag where
1572 toJSON SimpleQueryAll = "ALL"
1573 toJSON SimpleQueryNone = "NONE"
1574 toJSON SimpleQueryAnd = "AND"
1575 toJSON SimpleQueryOr = "OR"
1576 toJSON SimpleQueryPrefix = "PREFIX"
1577 toJSON SimpleQueryPhrase = "PHRASE"
1578 toJSON SimpleQueryPrecedence = "PRECEDENCE"
1579 toJSON SimpleQueryEscape = "ESCAPE"
1580 toJSON SimpleQueryWhitespace = "WHITESPACE"
1581 toJSON SimpleQueryFuzzy = "FUZZY"
1582 toJSON SimpleQueryNear = "NEAR"
1583 toJSON SimpleQuerySlop = "SLOP"
1586instance ToJSON RegexpQuery where
1587 toJSON (RegexpQuery (FieldName rqQueryField)
1588 (Regexp regexpQueryQuery) rqQueryFlags
1590 object [ rqQueryField .= omitNulls base ]
1591 where base = [ "value" .= regexpQueryQuery
1592 , "flags" .= rqQueryFlags
1593 , "boost" .= rqQueryBoost ]
1596instance ToJSON QueryStringQuery where
1597 toJSON (QueryStringQuery qsQueryString
1598 qsDefaultField qsOperator
1599 qsAnalyzer qsAllowWildcard
1600 qsLowercaseExpanded qsEnablePositionIncrements
1601 qsFuzzyMaxExpansions qsFuzziness
1602 qsFuzzyPrefixLength qsPhraseSlop
1603 qsBoost qsAnalyzeWildcard
1604 qsGeneratePhraseQueries qsMinimumShouldMatch
1605 qsLenient qsLocale) =
1608 base = [ "query" .= qsQueryString
1609 , "default_field" .= qsDefaultField
1610 , "default_operator" .= qsOperator
1611 , "analyzer" .= qsAnalyzer
1612 , "allow_leading_wildcard" .= qsAllowWildcard
1613 , "lowercase_expanded_terms" .= qsLowercaseExpanded
1614 , "enable_position_increments" .= qsEnablePositionIncrements
1615 , "fuzzy_max_expansions" .= qsFuzzyMaxExpansions
1616 , "fuzziness" .= qsFuzziness
1617 , "fuzzy_prefix_length" .= qsFuzzyPrefixLength
1618 , "phrase_slop" .= qsPhraseSlop
1619 , "boost" .= qsBoost
1620 , "analyze_wildcard" .= qsAnalyzeWildcard
1621 , "auto_generate_phrase_queries" .= qsGeneratePhraseQueries
1622 , "minimum_should_match" .= qsMinimumShouldMatch
1623 , "lenient" .= qsLenient
1624 , "locale" .= qsLocale ]
1627instance ToJSON RangeQuery where
1628 toJSON (RangeQuery (FieldName fieldName) range boost) =
1629 object [ fieldName .= conjoined ]
1630 where conjoined = [ "boost" .= boost ] ++ (rangeValueToPair range)
1633instance ToJSON PrefixQuery where
1634 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1635 object [ fieldName .= omitNulls base ]
1636 where base = [ "value" .= queryValue
1637 , "boost" .= boost ]
1640instance ToJSON NestedQuery where
1641 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1642 object [ "path" .= nqPath
1643 , "score_mode" .= nqScoreType
1644 , "query" .= nqQuery ]
1647instance ToJSON MoreLikeThisFieldQuery where
1648 toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
1649 percent mtf mqt stopwords mindf maxdf
1650 minwl maxwl boostTerms boost analyzer) =
1651 object [ fieldName .= omitNulls base ]
1652 where base = [ "like_text" .= text
1653 , "percent_terms_to_match" .= percent
1654 , "min_term_freq" .= mtf
1655 , "max_query_terms" .= mqt
1656 , "stop_words" .= stopwords
1657 , "min_doc_freq" .= mindf
1658 , "max_doc_freq" .= maxdf
1659 , "min_word_length" .= minwl
1660 , "max_word_length" .= maxwl
1661 , "boost_terms" .= boostTerms
1663 , "analyzer" .= analyzer ]
1666instance ToJSON MoreLikeThisQuery where
1667 toJSON (MoreLikeThisQuery text fields percent
1668 mtf mqt stopwords mindf maxdf
1669 minwl maxwl boostTerms boost analyzer) =
1671 where base = [ "like_text" .= text
1672 , "fields" .= fields
1673 , "percent_terms_to_match" .= percent
1674 , "min_term_freq" .= mtf
1675 , "max_query_terms" .= mqt
1676 , "stop_words" .= stopwords
1677 , "min_doc_freq" .= mindf
1678 , "max_doc_freq" .= maxdf
1679 , "min_word_length" .= minwl
1680 , "max_word_length" .= maxwl
1681 , "boost_terms" .= boostTerms
1683 , "analyzer" .= analyzer ]
1686instance ToJSON IndicesQuery where
1687 toJSON (IndicesQuery indices query noMatch) =
1688 omitNulls [ "indices" .= indices
1689 , "no_match_query" .= noMatch
1690 , "query" .= query ]
1693instance ToJSON HasParentQuery where
1694 toJSON (HasParentQuery queryType query scoreType) =
1695 omitNulls [ "parent_type" .= queryType
1696 , "score_type" .= scoreType
1697 , "query" .= query ]
1700instance ToJSON HasChildQuery where
1701 toJSON (HasChildQuery queryType query scoreType) =
1702 omitNulls [ "query" .= query
1703 , "score_type" .= scoreType
1704 , "type" .= queryType ]
1707instance ToJSON FuzzyQuery where
1708 toJSON (FuzzyQuery (FieldName fieldName) queryText
1709 prefixLength maxEx fuzziness boost) =
1710 object [ fieldName .= omitNulls base ]
1711 where base = [ "value" .= queryText
1712 , "fuzziness" .= fuzziness
1713 , "prefix_length" .= prefixLength
1715 , "max_expansions" .= maxEx ]
1718instance ToJSON FuzzyLikeFieldQuery where
1719 toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
1720 fieldText maxTerms ignoreFreq fuzziness prefixLength
1722 object [ fieldName .=
1723 omitNulls [ "like_text" .= fieldText
1724 , "max_query_terms" .= maxTerms
1725 , "ignore_tf" .= ignoreFreq
1726 , "fuzziness" .= fuzziness
1727 , "prefix_length" .= prefixLength
1728 , "analyzer" .= analyzer
1729 , "boost" .= boost ]]
1732instance ToJSON FuzzyLikeThisQuery where
1733 toJSON (FuzzyLikeThisQuery fields text maxTerms
1734 ignoreFreq fuzziness prefixLength boost analyzer) =
1736 where base = [ "fields" .= fields
1737 , "like_text" .= text
1738 , "max_query_terms" .= maxTerms
1739 , "ignore_tf" .= ignoreFreq
1740 , "fuzziness" .= fuzziness
1741 , "prefix_length" .= prefixLength
1742 , "analyzer" .= analyzer
1743 , "boost" .= boost ]
1746instance ToJSON FilteredQuery where
1747 toJSON (FilteredQuery query fFilter) =
1748 object [ "query" .= query
1749 , "filter" .= fFilter ]
1752instance ToJSON DisMaxQuery where
1753 toJSON (DisMaxQuery queries tiebreaker boost) =
1755 where base = [ "queries" .= queries
1757 , "tie_breaker" .= tiebreaker ]
1760instance ToJSON CommonTermsQuery where
1761 toJSON (CommonTermsQuery (FieldName fieldName)
1762 (QueryString query) cf lfo hfo msm
1763 boost analyzer disableCoord) =
1764 object [fieldName .= omitNulls base ]
1765 where base = [ "query" .= query
1766 , "cutoff_frequency" .= cf
1767 , "low_freq_operator" .= lfo
1768 , "minimum_should_match" .= msm
1770 , "analyzer" .= analyzer
1771 , "disable_coord" .= disableCoord
1772 , "high_freq_operator" .= hfo ]
1775instance ToJSON CommonMinimumMatch where
1776 toJSON (CommonMinimumMatch mm) = toJSON mm
1777 toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1778 object [ "low_freq" .= lowF
1779 , "high_freq" .= highF ]
1781instance ToJSON BoostingQuery where
1782 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1783 object [ "positive" .= bqPositiveQuery
1784 , "negative" .= bqNegativeQuery
1785 , "negative_boost" .= bqNegativeBoost ]
1788instance ToJSON BoolQuery where
1789 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1791 where base = [ "must" .= mustM
1792 , "must_not" .= notM
1793 , "should" .= shouldM
1794 , "minimum_should_match" .= bqMin
1796 , "disable_coord" .= disableCoord ]
1799instance ToJSON MatchQuery where
1800 toJSON (MatchQuery (FieldName fieldName)
1801 (QueryString mqQueryString) booleanOperator
1802 zeroTermsQuery cutoffFrequency matchQueryType
1803 analyzer maxExpansions lenient) =
1804 object [ fieldName .= omitNulls base ]
1805 where base = [ "query" .= mqQueryString
1806 , "operator" .= booleanOperator
1807 , "zero_terms_query" .= zeroTermsQuery
1808 , "cutoff_frequency" .= cutoffFrequency
1809 , "type" .= matchQueryType
1810 , "analyzer" .= analyzer
1811 , "max_expansions" .= maxExpansions
1812 , "lenient" .= lenient ]
1815instance ToJSON MultiMatchQuery where
1816 toJSON (MultiMatchQuery fields (QueryString query) boolOp
1817 ztQ tb mmqt cf analyzer maxEx lenient) =
1818 object ["multi_match" .= omitNulls base]
1819 where base = [ "fields" .= fmap toJSON fields
1821 , "operator" .= boolOp
1822 , "zero_terms_query" .= ztQ
1823 , "tiebreaker" .= tb
1825 , "cutoff_frequency" .= cf
1826 , "analyzer" .= analyzer
1827 , "max_expansions" .= maxEx
1828 , "lenient" .= lenient ]
1831instance ToJSON MultiMatchQueryType where
1832 toJSON MultiMatchBestFields = "best_fields"
1833 toJSON MultiMatchMostFields = "most_fields"
1834 toJSON MultiMatchCrossFields = "cross_fields"
1835 toJSON MultiMatchPhrase = "phrase"
1836 toJSON MultiMatchPhrasePrefix = "phrase_prefix"
1838instance ToJSON BooleanOperator where
1839 toJSON And = String "and"
1840 toJSON Or = String "or"
1842instance ToJSON ZeroTermsQuery where
1843 toJSON ZeroTermsNone = String "none"
1844 toJSON ZeroTermsAll = String "all"
1846instance ToJSON MatchQueryType where
1847 toJSON MatchPhrase = "phrase"
1848 toJSON MatchPhrasePrefix = "phrase_prefix"
1850instance ToJSON FieldName where
1851 toJSON (FieldName fieldName) = String fieldName
1853instance ToJSON ReplicaCount
1854instance ToJSON ShardCount
1855instance ToJSON CutoffFrequency
1856instance ToJSON Analyzer
1857instance ToJSON MaxExpansions
1858instance ToJSON Lenient
1859instance ToJSON Boost
1860instance ToJSON Version
1861instance ToJSON Tiebreaker
1862instance ToJSON MinimumMatch
1863instance ToJSON DisableCoord
1864instance ToJSON PrefixLength
1865instance ToJSON Fuzziness
1866instance ToJSON IgnoreTermFrequency
1867instance ToJSON MaxQueryTerms
1868instance ToJSON TypeName
1869instance ToJSON IndexName
1870instance ToJSON BoostTerms
1871instance ToJSON MaxWordLength
1872instance ToJSON MinWordLength
1873instance ToJSON MaxDocFrequency
1874instance ToJSON MinDocFrequency
1875instance ToJSON PhraseSlop
1876instance ToJSON StopWord
1877instance ToJSON QueryPath
1878instance ToJSON MinimumTermFrequency
1879instance ToJSON PercentMatch
1880instance ToJSON MappingName
1881instance ToJSON DocId
1882instance ToJSON QueryString
1883instance ToJSON AllowLeadingWildcard
1884instance ToJSON LowercaseExpanded
1885instance ToJSON AnalyzeWildcard
1886instance ToJSON GeneratePhraseQueries
1887instance ToJSON Locale
1888instance ToJSON EnablePositionIncrements
1889instance FromJSON Version
1890instance FromJSON IndexName
1891instance FromJSON MappingName
1892instance FromJSON DocId
1895instance FromJSON Status where
1896 parseJSON (Object v) = Status <$>
1905instance ToJSON IndexSettings where
1906 toJSON (IndexSettings s r) = object ["settings" .= object ["shards" .= s, "replicas" .= r]]
1909instance (FromJSON a) => FromJSON (EsResult a) where
1910 parseJSON (Object v) = EsResult <$>
1920instance ToJSON Search where
1921 toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize) =
1922 omitNulls [ "query" .= query
1923 , "filter" .= sFilter
1925 , "aggregations" .= searchAggs
1926 , "highlight" .= highlight
1929 , "track_scores" .= sTrackSortScores]
1932instance ToJSON FieldHighlight where
1933 toJSON (FieldHighlight (FieldName fName) (Just fSettings)) =
1934 object [ fName .= fSettings ]
1935 toJSON (FieldHighlight (FieldName fName) Nothing) =
1936 object [ fName .= emptyObject ]
1938instance ToJSON Highlights where
1939 toJSON (Highlights global fields) =
1940 omitNulls (("fields" .= fields)
1941 : highlightSettingsPairs global)
1943instance ToJSON HighlightSettings where
1944 toJSON hs = omitNulls (highlightSettingsPairs (Just hs))
1946highlightSettingsPairs :: Maybe HighlightSettings -> [Pair]
1947highlightSettingsPairs Nothing = []
1948highlightSettingsPairs (Just (Plain plh)) = plainHighPairs (Just plh)
1949highlightSettingsPairs (Just (Postings ph)) = postHighPairs (Just ph)
1950highlightSettingsPairs (Just (FastVector fvh)) = fastVectorHighPairs (Just fvh)
1953plainHighPairs :: Maybe PlainHighlight -> [Pair]
1954plainHighPairs Nothing = []
1955plainHighPairs (Just (PlainHighlight plCom plNonPost)) =
1956 [ "type" .= String "plain"]
1957 ++ commonHighlightPairs plCom
1958 ++ nonPostingsToPairs plNonPost
1960postHighPairs :: Maybe PostingsHighlight -> [Pair]
1961postHighPairs Nothing = []
1962postHighPairs (Just (PostingsHighlight pCom)) =
1963 ("type" .= String "postings")
1964 : commonHighlightPairs pCom
1966fastVectorHighPairs :: Maybe FastVectorHighlight -> [Pair]
1967fastVectorHighPairs Nothing = []
1968fastVectorHighPairs (Just
1969 (FastVectorHighlight fvCom fvNonPostSettings fvBoundChars
1970 fvBoundMaxScan fvFragOff fvMatchedFields
1972 [ "type" .= String "fvh"
1973 , "boundary_chars" .= fvBoundChars
1974 , "boundary_max_scan" .= fvBoundMaxScan
1975 , "fragment_offset" .= fvFragOff
1976 , "matched_fields" .= fvMatchedFields
1977 , "phraseLimit" .= fvPhraseLim]
1978 ++ commonHighlightPairs fvCom
1979 ++ nonPostingsToPairs fvNonPostSettings
1981commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
1982commonHighlightPairs Nothing = []
1983commonHighlightPairs (Just (CommonHighlight chScore chForceSource chTag chEncoder
1984 chNoMatchSize chHighlightQuery
1985 chRequireFieldMatch)) =
1986 [ "order" .= chScore
1987 , "force_source" .= chForceSource
1988 , "encoder" .= chEncoder
1989 , "no_match_size" .= chNoMatchSize
1990 , "highlight_query" .= chHighlightQuery
1991 , "require_fieldMatch" .= chRequireFieldMatch]
1992 ++ highlightTagToPairs chTag
1995nonPostingsToPairs :: Maybe NonPostings -> [Pair]
1996nonPostingsToPairs Nothing = []
1997nonPostingsToPairs (Just (NonPostings npFragSize npNumOfFrags)) =
1998 [ "fragment_size" .= npFragSize
1999 , "number_of_fragments" .= npNumOfFrags]
2003instance ToJSON HighlightEncoder where
2004 toJSON DefaultEncoder = String "default"
2005 toJSON HTMLEncoder = String "html"
2007highlightTagToPairs :: Maybe HighlightTag -> [Pair]
2008highlightTagToPairs (Just (TagSchema _)) = [ "scheme" .= String "default"]
2009highlightTagToPairs (Just (CustomTags (pre, post))) = [ "pre_tags" .= pre
2010 , "post_tags" .= post]
2011highlightTagToPairs Nothing = []
2013instance ToJSON SortSpec where
2014 toJSON (DefaultSortSpec
2015 (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
2016 dsSortMode dsMissingSort dsNestedFilter)) =
2017 object [dsSortFieldName .= omitNulls base] where
2018 base = [ "order" .= dsSortOrder
2019 , "ignore_unmapped" .= dsIgnoreUnmapped
2020 , "mode" .= dsSortMode
2021 , "missing" .= dsMissingSort
2022 , "nested_filter" .= dsNestedFilter ]
2024 toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
2025 object [ "unit" .= units
2026 , field .= gdsLatLon
2027 , "order" .= gdsSortOrder ]
2030instance ToJSON SortOrder where
2031 toJSON Ascending = String "asc"
2032 toJSON Descending = String "desc"
2035instance ToJSON SortMode where
2036 toJSON SortMin = String "min"
2037 toJSON SortMax = String "max"
2038 toJSON SortSum = String "sum"
2039 toJSON SortAvg = String "avg"
2042instance ToJSON Missing where
2043 toJSON LastMissing = String "_last"
2044 toJSON FirstMissing = String "_first"
2045 toJSON (CustomMissing txt) = String txt
2048instance ToJSON ScoreType where
2049 toJSON ScoreTypeMax = "max"
2050 toJSON ScoreTypeAvg = "avg"
2051 toJSON ScoreTypeSum = "sum"
2052 toJSON ScoreTypeNone = "none"
2055instance ToJSON Distance where
2056 toJSON (Distance dCoefficient dUnit) =
2057 String boltedTogether where
2058 coefText = showText dCoefficient
2059 (String unitText) = toJSON dUnit
2060 boltedTogether = mappend coefText unitText
2063instance ToJSON DistanceUnit where
2064 toJSON Miles = String "mi"
2065 toJSON Yards = String "yd"
2066 toJSON Feet = String "ft"
2067 toJSON Inches = String "in"
2068 toJSON Kilometers = String "km"
2069 toJSON Meters = String "m"
2070 toJSON Centimeters = String "cm"
2071 toJSON Millimeters = String "mm"
2072 toJSON NauticalMiles = String "nmi"
2075instance ToJSON DistanceType where
2076 toJSON Arc = String "arc"
2077 toJSON SloppyArc = String "sloppy_arc"
2078 toJSON Plane = String "plane"
2081instance ToJSON OptimizeBbox where
2082 toJSON NoOptimizeBbox = String "none"
2083 toJSON (OptimizeGeoFilterType gft) = toJSON gft
2086instance ToJSON GeoBoundingBoxConstraint where
2087 toJSON (GeoBoundingBoxConstraint
2088 (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2089 object [gbbcGeoBBField .= gbbcConstraintBox
2094instance ToJSON GeoFilterType where
2095 toJSON GeoFilterMemory = String "memory"
2096 toJSON GeoFilterIndexed = String "indexed"
2099instance ToJSON GeoBoundingBox where
2100 toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2101 object ["top_left" .= gbbTopLeft
2102 , "bottom_right" .= gbbBottomRight]
2105instance ToJSON LatLon where
2106 toJSON (LatLon lLat lLon) =
2107 object ["lat" .= lLat
2111-- index for smaller ranges, fielddata for longer ranges
2112instance ToJSON RangeExecution where
2113 toJSON RangeExecutionIndex = "index"
2114 toJSON RangeExecutionFielddata = "fielddata"
2117instance ToJSON RegexpFlags where
2118 toJSON AllRegexpFlags = String "ALL"
2119 toJSON NoRegexpFlags = String "NONE"
2120 toJSON (SomeRegexpFlags (h :| fs)) = String $ T.intercalate "|" flagStrs
2121 where flagStrs = map flagStr . nub $ h:fs
2122 flagStr AnyString = "ANYSTRING"
2123 flagStr Automaton = "AUTOMATON"
2124 flagStr Complement = "COMPLEMENT"
2125 flagStr Empty = "EMPTY"
2126 flagStr Intersection = "INTERSECTION"
2127 flagStr Interval = "INTERVAL"
2129instance ToJSON Term where
2130 toJSON (Term field value) = object ["term" .= object
2134instance ToJSON BoolMatch where
2135 toJSON (MustMatch term cache) = object ["must" .= term,
2137 toJSON (MustNotMatch term cache) = object ["must_not" .= term,
2139 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2143instance (FromJSON a) => FromJSON (SearchResult a) where
2144 parseJSON (Object v) = SearchResult <$>
2146 v .: "timed_out" <*>
2149 v .:? "aggregations"
2152instance (FromJSON a) => FromJSON (SearchHits a) where
2153 parseJSON (Object v) = SearchHits <$>
2155 v .: "max_score" <*>
2159instance (FromJSON a) => FromJSON (Hit a) where
2160 parseJSON (Object v) = Hit <$>
2169instance FromJSON ShardResult where
2170 parseJSON (Object v) = ShardResult <$>
2172 v .: "successful" <*>
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list