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) =
1363 object ["or" .= fmap toJSON filters
1364 , "_cache" .= cache]
1366 toJSON (NotFilter notFilter cache) =
1368 object ["filter" .= notFilter
1369 , "_cache" .= cache]]
1371 toJSON (IdentityFilter) =
1372 object ["match_all" .= object []]
1374 toJSON (TermFilter (Term termFilterField termFilterValue) cache) =
1375 object ["term" .= object base]
1376 where base = [termFilterField .= termFilterValue,
1379 toJSON (ExistsFilter (FieldName fieldName)) =
1380 object ["exists" .= object
1381 ["field" .= fieldName]]
1383 toJSON (BoolFilter boolMatch) =
1384 object ["bool" .= boolMatch]
1386 toJSON (GeoBoundingBoxFilter bbConstraint) =
1387 object ["geo_bounding_box" .= bbConstraint]
1389 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1390 distance distanceType optimizeBbox cache) =
1391 object ["geo_distance" .=
1392 object ["distance" .= distance
1393 , "distance_type" .= distanceType
1394 , "optimize_bbox" .= optimizeBbox
1395 , distanceGeoField .= geoDistLatLon
1396 , "_cache" .= cache]]
1398 toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1399 (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1400 object ["geo_distance_range" .=
1401 object ["from" .= geoDistRangeDistFrom
1402 , "to" .= drDistanceTo
1403 , gddrField .= drLatLon]]
1405 toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1406 object ["geo_polygon" .=
1407 object [geoPolygonFilterField .=
1408 object ["points" .= fmap toJSON latLons]]]
1410 toJSON (IdsFilter (MappingName mappingName) values) =
1412 object ["type" .= mappingName
1413 , "values" .= fmap unpackId values]]
1415 toJSON (LimitFilter limit) =
1416 object ["limit" .= object ["value" .= limit]]
1418 toJSON (MissingFilter (FieldName fieldName) (Existence existence) (NullValue nullValue)) =
1419 object ["missing" .=
1420 object ["field" .= fieldName
1421 , "existence" .= existence
1422 , "null_value" .= nullValue]]
1424 toJSON (PrefixFilter (FieldName fieldName) fieldValue cache) =
1426 object [fieldName .= fieldValue
1427 , "_cache" .= cache]]
1429 toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1431 object [ fieldName .= object (rangeValueToPair rangeValue)
1432 , "execution" .= rangeExecution
1433 , "_cache" .= cache]]
1435 toJSON (RegexpFilter (FieldName fieldName)
1436 (Regexp regexText) flags (CacheName cacheName) cache (CacheKey cacheKey)) =
1438 object [fieldName .=
1439 object ["value" .= regexText
1441 , "_name" .= cacheName
1443 , "_cache_key" .= cacheKey]]
1445instance ToJSON GeoPoint where
1446 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1447 object [ geoPointField .= geoPointLatLon ]
1450instance ToJSON Query where
1451 toJSON (TermQuery (Term termQueryField termQueryValue) boost) =
1453 object [termQueryField .= object merged]]
1455 base = [ "value" .= termQueryValue ]
1456 boosted = maybe [] (return . ("boost" .=)) boost
1457 merged = mappend base boosted
1459 toJSON (TermsQuery terms) =
1460 object [ "terms" .= object conjoined ]
1461 where conjoined = [ getTermsField terms .=
1462 fmap (toJSON . getTermValue) (toList terms)]
1463 getTermsField ((Term f _ ) :| _) = f
1464 getTermValue (Term _ v) = v
1465 toJSON (IdsQuery idsQueryMappingName docIds) =
1466 object [ "ids" .= object conjoined ]
1467 where conjoined = [ "type" .= idsQueryMappingName
1468 , "values" .= fmap toJSON docIds ]
1470 toJSON (QueryQueryStringQuery qQueryStringQuery) =
1471 object [ "query_string" .= qQueryStringQuery ]
1473 toJSON (QueryMatchQuery matchQuery) =
1474 object [ "match" .= matchQuery ]
1476 toJSON (QueryMultiMatchQuery multiMatchQuery) =
1477 toJSON multiMatchQuery
1479 toJSON (QueryBoolQuery boolQuery) =
1480 object [ "bool" .= boolQuery ]
1482 toJSON (QueryBoostingQuery boostingQuery) =
1483 object [ "boosting" .= boostingQuery ]
1485 toJSON (QueryCommonTermsQuery commonTermsQuery) =
1486 object [ "common" .= commonTermsQuery ]
1488 toJSON (ConstantScoreFilter csFilter boost) =
1489 object [ "constant_score" .= csFilter
1492 toJSON (ConstantScoreQuery query boost) =
1493 object [ "constant_score" .= query
1496 toJSON (QueryDisMaxQuery disMaxQuery) =
1497 object [ "dis_max" .= disMaxQuery ]
1499 toJSON (QueryFilteredQuery qFilteredQuery) =
1500 object [ "filtered" .= qFilteredQuery ]
1502 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1503 object [ "fuzzy_like_this" .= fuzzyQuery ]
1505 toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1506 object [ "fuzzy_like_this_field" .= fuzzyFieldQuery ]
1508 toJSON (QueryFuzzyQuery fuzzyQuery) =
1509 object [ "fuzzy" .= fuzzyQuery ]
1511 toJSON (QueryHasChildQuery childQuery) =
1512 object [ "has_child" .= childQuery ]
1514 toJSON (QueryHasParentQuery parentQuery) =
1515 object [ "has_parent" .= parentQuery ]
1517 toJSON (QueryIndicesQuery qIndicesQuery) =
1518 object [ "indices" .= qIndicesQuery ]
1520 toJSON (MatchAllQuery boost) =
1521 object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1523 toJSON (QueryMoreLikeThisQuery query) =
1524 object [ "more_like_this" .= query ]
1526 toJSON (QueryMoreLikeThisFieldQuery query) =
1527 object [ "more_like_this_field" .= query ]
1529 toJSON (QueryNestedQuery query) =
1530 object [ "nested" .= query ]
1532 toJSON (QueryPrefixQuery query) =
1533 object [ "prefix" .= query ]
1535 toJSON (QueryRangeQuery query) =
1536 object [ "range" .= query ]
1538 toJSON (QueryRegexpQuery query) =
1539 object [ "regexp" .= query ]
1541 toJSON (QuerySimpleQueryStringQuery query) =
1542 object [ "simple_query_string" .= query ]
1545omitNulls :: [(Text, Value)] -> Value
1546omitNulls = object . filter notNull where
1547 notNull (_, Null) = False
1548 notNull (_, Array a) = (not . V.null) a
1552instance ToJSON SimpleQueryStringQuery where
1553 toJSON SimpleQueryStringQuery {..} =
1554 omitNulls (base ++ maybeAdd)
1555 where base = [ "query" .= simpleQueryStringQuery ]
1556 maybeAdd = [ "fields" .= simpleQueryStringField
1557 , "default_operator" .= simpleQueryStringOperator
1558 , "analyzer" .= simpleQueryStringAnalyzer
1559 , "flags" .= simpleQueryStringFlags
1560 , "lowercase_expanded_terms" .= simpleQueryStringLowercaseExpanded
1561 , "locale" .= simpleQueryStringLocale ]
1564instance ToJSON FieldOrFields where
1565 toJSON (FofField fieldName) =
1567 toJSON (FofFields fieldNames) =
1570instance ToJSON SimpleQueryFlag where
1571 toJSON SimpleQueryAll = "ALL"
1572 toJSON SimpleQueryNone = "NONE"
1573 toJSON SimpleQueryAnd = "AND"
1574 toJSON SimpleQueryOr = "OR"
1575 toJSON SimpleQueryPrefix = "PREFIX"
1576 toJSON SimpleQueryPhrase = "PHRASE"
1577 toJSON SimpleQueryPrecedence = "PRECEDENCE"
1578 toJSON SimpleQueryEscape = "ESCAPE"
1579 toJSON SimpleQueryWhitespace = "WHITESPACE"
1580 toJSON SimpleQueryFuzzy = "FUZZY"
1581 toJSON SimpleQueryNear = "NEAR"
1582 toJSON SimpleQuerySlop = "SLOP"
1585instance ToJSON RegexpQuery where
1586 toJSON (RegexpQuery (FieldName rqQueryField)
1587 (Regexp regexpQueryQuery) rqQueryFlags
1589 object [ rqQueryField .= omitNulls base ]
1590 where base = [ "value" .= regexpQueryQuery
1591 , "flags" .= rqQueryFlags
1592 , "boost" .= rqQueryBoost ]
1595instance ToJSON QueryStringQuery where
1596 toJSON (QueryStringQuery qsQueryString
1597 qsDefaultField qsOperator
1598 qsAnalyzer qsAllowWildcard
1599 qsLowercaseExpanded qsEnablePositionIncrements
1600 qsFuzzyMaxExpansions qsFuzziness
1601 qsFuzzyPrefixLength qsPhraseSlop
1602 qsBoost qsAnalyzeWildcard
1603 qsGeneratePhraseQueries qsMinimumShouldMatch
1604 qsLenient qsLocale) =
1607 base = [ "query" .= qsQueryString
1608 , "default_field" .= qsDefaultField
1609 , "default_operator" .= qsOperator
1610 , "analyzer" .= qsAnalyzer
1611 , "allow_leading_wildcard" .= qsAllowWildcard
1612 , "lowercase_expanded_terms" .= qsLowercaseExpanded
1613 , "enable_position_increments" .= qsEnablePositionIncrements
1614 , "fuzzy_max_expansions" .= qsFuzzyMaxExpansions
1615 , "fuzziness" .= qsFuzziness
1616 , "fuzzy_prefix_length" .= qsFuzzyPrefixLength
1617 , "phrase_slop" .= qsPhraseSlop
1618 , "boost" .= qsBoost
1619 , "analyze_wildcard" .= qsAnalyzeWildcard
1620 , "auto_generate_phrase_queries" .= qsGeneratePhraseQueries
1621 , "minimum_should_match" .= qsMinimumShouldMatch
1622 , "lenient" .= qsLenient
1623 , "locale" .= qsLocale ]
1626instance ToJSON RangeQuery where
1627 toJSON (RangeQuery (FieldName fieldName) range boost) =
1628 object [ fieldName .= conjoined ]
1629 where conjoined = [ "boost" .= boost ] ++ (rangeValueToPair range)
1632instance ToJSON PrefixQuery where
1633 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1634 object [ fieldName .= omitNulls base ]
1635 where base = [ "value" .= queryValue
1636 , "boost" .= boost ]
1639instance ToJSON NestedQuery where
1640 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1641 object [ "path" .= nqPath
1642 , "score_mode" .= nqScoreType
1643 , "query" .= nqQuery ]
1646instance ToJSON MoreLikeThisFieldQuery where
1647 toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
1648 percent mtf mqt stopwords mindf maxdf
1649 minwl maxwl boostTerms boost analyzer) =
1650 object [ fieldName .= omitNulls base ]
1651 where base = [ "like_text" .= text
1652 , "percent_terms_to_match" .= percent
1653 , "min_term_freq" .= mtf
1654 , "max_query_terms" .= mqt
1655 , "stop_words" .= stopwords
1656 , "min_doc_freq" .= mindf
1657 , "max_doc_freq" .= maxdf
1658 , "min_word_length" .= minwl
1659 , "max_word_length" .= maxwl
1660 , "boost_terms" .= boostTerms
1662 , "analyzer" .= analyzer ]
1665instance ToJSON MoreLikeThisQuery where
1666 toJSON (MoreLikeThisQuery text fields percent
1667 mtf mqt stopwords mindf maxdf
1668 minwl maxwl boostTerms boost analyzer) =
1670 where base = [ "like_text" .= text
1671 , "fields" .= fields
1672 , "percent_terms_to_match" .= percent
1673 , "min_term_freq" .= mtf
1674 , "max_query_terms" .= mqt
1675 , "stop_words" .= stopwords
1676 , "min_doc_freq" .= mindf
1677 , "max_doc_freq" .= maxdf
1678 , "min_word_length" .= minwl
1679 , "max_word_length" .= maxwl
1680 , "boost_terms" .= boostTerms
1682 , "analyzer" .= analyzer ]
1685instance ToJSON IndicesQuery where
1686 toJSON (IndicesQuery indices query noMatch) =
1687 omitNulls [ "indices" .= indices
1688 , "no_match_query" .= noMatch
1689 , "query" .= query ]
1692instance ToJSON HasParentQuery where
1693 toJSON (HasParentQuery queryType query scoreType) =
1694 omitNulls [ "parent_type" .= queryType
1695 , "score_type" .= scoreType
1696 , "query" .= query ]
1699instance ToJSON HasChildQuery where
1700 toJSON (HasChildQuery queryType query scoreType) =
1701 omitNulls [ "query" .= query
1702 , "score_type" .= scoreType
1703 , "type" .= queryType ]
1706instance ToJSON FuzzyQuery where
1707 toJSON (FuzzyQuery (FieldName fieldName) queryText
1708 prefixLength maxEx fuzziness boost) =
1709 object [ fieldName .= omitNulls base ]
1710 where base = [ "value" .= queryText
1711 , "fuzziness" .= fuzziness
1712 , "prefix_length" .= prefixLength
1714 , "max_expansions" .= maxEx ]
1717instance ToJSON FuzzyLikeFieldQuery where
1718 toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
1719 fieldText maxTerms ignoreFreq fuzziness prefixLength
1721 object [ fieldName .=
1722 omitNulls [ "like_text" .= fieldText
1723 , "max_query_terms" .= maxTerms
1724 , "ignore_tf" .= ignoreFreq
1725 , "fuzziness" .= fuzziness
1726 , "prefix_length" .= prefixLength
1727 , "analyzer" .= analyzer
1728 , "boost" .= boost ]]
1731instance ToJSON FuzzyLikeThisQuery where
1732 toJSON (FuzzyLikeThisQuery fields text maxTerms
1733 ignoreFreq fuzziness prefixLength boost analyzer) =
1735 where base = [ "fields" .= fields
1736 , "like_text" .= text
1737 , "max_query_terms" .= maxTerms
1738 , "ignore_tf" .= ignoreFreq
1739 , "fuzziness" .= fuzziness
1740 , "prefix_length" .= prefixLength
1741 , "analyzer" .= analyzer
1742 , "boost" .= boost ]
1745instance ToJSON FilteredQuery where
1746 toJSON (FilteredQuery query fFilter) =
1747 object [ "query" .= query
1748 , "filter" .= fFilter ]
1751instance ToJSON DisMaxQuery where
1752 toJSON (DisMaxQuery queries tiebreaker boost) =
1754 where base = [ "queries" .= queries
1756 , "tie_breaker" .= tiebreaker ]
1759instance ToJSON CommonTermsQuery where
1760 toJSON (CommonTermsQuery (FieldName fieldName)
1761 (QueryString query) cf lfo hfo msm
1762 boost analyzer disableCoord) =
1763 object [fieldName .= omitNulls base ]
1764 where base = [ "query" .= query
1765 , "cutoff_frequency" .= cf
1766 , "low_freq_operator" .= lfo
1767 , "minimum_should_match" .= msm
1769 , "analyzer" .= analyzer
1770 , "disable_coord" .= disableCoord
1771 , "high_freq_operator" .= hfo ]
1774instance ToJSON CommonMinimumMatch where
1775 toJSON (CommonMinimumMatch mm) = toJSON mm
1776 toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1777 object [ "low_freq" .= lowF
1778 , "high_freq" .= highF ]
1780instance ToJSON BoostingQuery where
1781 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1782 object [ "positive" .= bqPositiveQuery
1783 , "negative" .= bqNegativeQuery
1784 , "negative_boost" .= bqNegativeBoost ]
1787instance ToJSON BoolQuery where
1788 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1790 where base = [ "must" .= mustM
1791 , "must_not" .= notM
1792 , "should" .= shouldM
1793 , "minimum_should_match" .= bqMin
1795 , "disable_coord" .= disableCoord ]
1798instance ToJSON MatchQuery where
1799 toJSON (MatchQuery (FieldName fieldName)
1800 (QueryString mqQueryString) booleanOperator
1801 zeroTermsQuery cutoffFrequency matchQueryType
1802 analyzer maxExpansions lenient) =
1803 object [ fieldName .= omitNulls base ]
1804 where base = [ "query" .= mqQueryString
1805 , "operator" .= booleanOperator
1806 , "zero_terms_query" .= zeroTermsQuery
1807 , "cutoff_frequency" .= cutoffFrequency
1808 , "type" .= matchQueryType
1809 , "analyzer" .= analyzer
1810 , "max_expansions" .= maxExpansions
1811 , "lenient" .= lenient ]
1814instance ToJSON MultiMatchQuery where
1815 toJSON (MultiMatchQuery fields (QueryString query) boolOp
1816 ztQ tb mmqt cf analyzer maxEx lenient) =
1817 object ["multi_match" .= omitNulls base]
1818 where base = [ "fields" .= fmap toJSON fields
1820 , "operator" .= boolOp
1821 , "zero_terms_query" .= ztQ
1822 , "tiebreaker" .= tb
1824 , "cutoff_frequency" .= cf
1825 , "analyzer" .= analyzer
1826 , "max_expansions" .= maxEx
1827 , "lenient" .= lenient ]
1830instance ToJSON MultiMatchQueryType where
1831 toJSON MultiMatchBestFields = "best_fields"
1832 toJSON MultiMatchMostFields = "most_fields"
1833 toJSON MultiMatchCrossFields = "cross_fields"
1834 toJSON MultiMatchPhrase = "phrase"
1835 toJSON MultiMatchPhrasePrefix = "phrase_prefix"
1837instance ToJSON BooleanOperator where
1838 toJSON And = String "and"
1839 toJSON Or = String "or"
1841instance ToJSON ZeroTermsQuery where
1842 toJSON ZeroTermsNone = String "none"
1843 toJSON ZeroTermsAll = String "all"
1845instance ToJSON MatchQueryType where
1846 toJSON MatchPhrase = "phrase"
1847 toJSON MatchPhrasePrefix = "phrase_prefix"
1849instance ToJSON FieldName where
1850 toJSON (FieldName fieldName) = String fieldName
1852instance ToJSON ReplicaCount
1853instance ToJSON ShardCount
1854instance ToJSON CutoffFrequency
1855instance ToJSON Analyzer
1856instance ToJSON MaxExpansions
1857instance ToJSON Lenient
1858instance ToJSON Boost
1859instance ToJSON Version
1860instance ToJSON Tiebreaker
1861instance ToJSON MinimumMatch
1862instance ToJSON DisableCoord
1863instance ToJSON PrefixLength
1864instance ToJSON Fuzziness
1865instance ToJSON IgnoreTermFrequency
1866instance ToJSON MaxQueryTerms
1867instance ToJSON TypeName
1868instance ToJSON IndexName
1869instance ToJSON BoostTerms
1870instance ToJSON MaxWordLength
1871instance ToJSON MinWordLength
1872instance ToJSON MaxDocFrequency
1873instance ToJSON MinDocFrequency
1874instance ToJSON PhraseSlop
1875instance ToJSON StopWord
1876instance ToJSON QueryPath
1877instance ToJSON MinimumTermFrequency
1878instance ToJSON PercentMatch
1879instance ToJSON MappingName
1880instance ToJSON DocId
1881instance ToJSON QueryString
1882instance ToJSON AllowLeadingWildcard
1883instance ToJSON LowercaseExpanded
1884instance ToJSON AnalyzeWildcard
1885instance ToJSON GeneratePhraseQueries
1886instance ToJSON Locale
1887instance ToJSON EnablePositionIncrements
1888instance FromJSON Version
1889instance FromJSON IndexName
1890instance FromJSON MappingName
1891instance FromJSON DocId
1894instance FromJSON Status where
1895 parseJSON (Object v) = Status <$>
1904instance ToJSON IndexSettings where
1905 toJSON (IndexSettings s r) = object ["settings" .= object ["shards" .= s, "replicas" .= r]]
1908instance (FromJSON a) => FromJSON (EsResult a) where
1909 parseJSON (Object v) = EsResult <$>
1919instance ToJSON Search where
1920 toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize) =
1921 omitNulls [ "query" .= query
1922 , "filter" .= sFilter
1924 , "aggregations" .= searchAggs
1925 , "highlight" .= highlight
1928 , "track_scores" .= sTrackSortScores]
1931instance ToJSON FieldHighlight where
1932 toJSON (FieldHighlight (FieldName fName) (Just fSettings)) =
1933 object [ fName .= fSettings ]
1934 toJSON (FieldHighlight (FieldName fName) Nothing) =
1935 object [ fName .= emptyObject ]
1937instance ToJSON Highlights where
1938 toJSON (Highlights global fields) =
1939 omitNulls (("fields" .= fields)
1940 : highlightSettingsPairs global)
1942instance ToJSON HighlightSettings where
1943 toJSON hs = omitNulls (highlightSettingsPairs (Just hs))
1945highlightSettingsPairs :: Maybe HighlightSettings -> [Pair]
1946highlightSettingsPairs Nothing = []
1947highlightSettingsPairs (Just (Plain plh)) = plainHighPairs (Just plh)
1948highlightSettingsPairs (Just (Postings ph)) = postHighPairs (Just ph)
1949highlightSettingsPairs (Just (FastVector fvh)) = fastVectorHighPairs (Just fvh)
1952plainHighPairs :: Maybe PlainHighlight -> [Pair]
1953plainHighPairs Nothing = []
1954plainHighPairs (Just (PlainHighlight plCom plNonPost)) =
1955 [ "type" .= String "plain"]
1956 ++ commonHighlightPairs plCom
1957 ++ nonPostingsToPairs plNonPost
1959postHighPairs :: Maybe PostingsHighlight -> [Pair]
1960postHighPairs Nothing = []
1961postHighPairs (Just (PostingsHighlight pCom)) =
1962 ("type" .= String "postings")
1963 : commonHighlightPairs pCom
1965fastVectorHighPairs :: Maybe FastVectorHighlight -> [Pair]
1966fastVectorHighPairs Nothing = []
1967fastVectorHighPairs (Just
1968 (FastVectorHighlight fvCom fvNonPostSettings fvBoundChars
1969 fvBoundMaxScan fvFragOff fvMatchedFields
1971 [ "type" .= String "fvh"
1972 , "boundary_chars" .= fvBoundChars
1973 , "boundary_max_scan" .= fvBoundMaxScan
1974 , "fragment_offset" .= fvFragOff
1975 , "matched_fields" .= fvMatchedFields
1976 , "phraseLimit" .= fvPhraseLim]
1977 ++ commonHighlightPairs fvCom
1978 ++ nonPostingsToPairs fvNonPostSettings
1980commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
1981commonHighlightPairs Nothing = []
1982commonHighlightPairs (Just (CommonHighlight chScore chForceSource chTag chEncoder
1983 chNoMatchSize chHighlightQuery
1984 chRequireFieldMatch)) =
1985 [ "order" .= chScore
1986 , "force_source" .= chForceSource
1987 , "encoder" .= chEncoder
1988 , "no_match_size" .= chNoMatchSize
1989 , "highlight_query" .= chHighlightQuery
1990 , "require_fieldMatch" .= chRequireFieldMatch]
1991 ++ highlightTagToPairs chTag
1994nonPostingsToPairs :: Maybe NonPostings -> [Pair]
1995nonPostingsToPairs Nothing = []
1996nonPostingsToPairs (Just (NonPostings npFragSize npNumOfFrags)) =
1997 [ "fragment_size" .= npFragSize
1998 , "number_of_fragments" .= npNumOfFrags]
2002instance ToJSON HighlightEncoder where
2003 toJSON DefaultEncoder = String "default"
2004 toJSON HTMLEncoder = String "html"
2006highlightTagToPairs :: Maybe HighlightTag -> [Pair]
2007highlightTagToPairs (Just (TagSchema _)) = [ "scheme" .= String "default"]
2008highlightTagToPairs (Just (CustomTags (pre, post))) = [ "pre_tags" .= pre
2009 , "post_tags" .= post]
2010highlightTagToPairs Nothing = []
2012instance ToJSON SortSpec where
2013 toJSON (DefaultSortSpec
2014 (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
2015 dsSortMode dsMissingSort dsNestedFilter)) =
2016 object [dsSortFieldName .= omitNulls base] where
2017 base = [ "order" .= dsSortOrder
2018 , "ignore_unmapped" .= dsIgnoreUnmapped
2019 , "mode" .= dsSortMode
2020 , "missing" .= dsMissingSort
2021 , "nested_filter" .= dsNestedFilter ]
2023 toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
2024 object [ "unit" .= units
2025 , field .= gdsLatLon
2026 , "order" .= gdsSortOrder ]
2029instance ToJSON SortOrder where
2030 toJSON Ascending = String "asc"
2031 toJSON Descending = String "desc"
2034instance ToJSON SortMode where
2035 toJSON SortMin = String "min"
2036 toJSON SortMax = String "max"
2037 toJSON SortSum = String "sum"
2038 toJSON SortAvg = String "avg"
2041instance ToJSON Missing where
2042 toJSON LastMissing = String "_last"
2043 toJSON FirstMissing = String "_first"
2044 toJSON (CustomMissing txt) = String txt
2047instance ToJSON ScoreType where
2048 toJSON ScoreTypeMax = "max"
2049 toJSON ScoreTypeAvg = "avg"
2050 toJSON ScoreTypeSum = "sum"
2051 toJSON ScoreTypeNone = "none"
2054instance ToJSON Distance where
2055 toJSON (Distance dCoefficient dUnit) =
2056 String boltedTogether where
2057 coefText = showText dCoefficient
2058 (String unitText) = toJSON dUnit
2059 boltedTogether = mappend coefText unitText
2062instance ToJSON DistanceUnit where
2063 toJSON Miles = String "mi"
2064 toJSON Yards = String "yd"
2065 toJSON Feet = String "ft"
2066 toJSON Inches = String "in"
2067 toJSON Kilometers = String "km"
2068 toJSON Meters = String "m"
2069 toJSON Centimeters = String "cm"
2070 toJSON Millimeters = String "mm"
2071 toJSON NauticalMiles = String "nmi"
2074instance ToJSON DistanceType where
2075 toJSON Arc = String "arc"
2076 toJSON SloppyArc = String "sloppy_arc"
2077 toJSON Plane = String "plane"
2080instance ToJSON OptimizeBbox where
2081 toJSON NoOptimizeBbox = String "none"
2082 toJSON (OptimizeGeoFilterType gft) = toJSON gft
2085instance ToJSON GeoBoundingBoxConstraint where
2086 toJSON (GeoBoundingBoxConstraint
2087 (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2088 object [gbbcGeoBBField .= gbbcConstraintBox
2093instance ToJSON GeoFilterType where
2094 toJSON GeoFilterMemory = String "memory"
2095 toJSON GeoFilterIndexed = String "indexed"
2098instance ToJSON GeoBoundingBox where
2099 toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2100 object ["top_left" .= gbbTopLeft
2101 , "bottom_right" .= gbbBottomRight]
2104instance ToJSON LatLon where
2105 toJSON (LatLon lLat lLon) =
2106 object ["lat" .= lLat
2110-- index for smaller ranges, fielddata for longer ranges
2111instance ToJSON RangeExecution where
2112 toJSON RangeExecutionIndex = "index"
2113 toJSON RangeExecutionFielddata = "fielddata"
2116instance ToJSON RegexpFlags where
2117 toJSON AllRegexpFlags = String "ALL"
2118 toJSON NoRegexpFlags = String "NONE"
2119 toJSON (SomeRegexpFlags (h :| fs)) = String $ T.intercalate "|" flagStrs
2120 where flagStrs = map flagStr . nub $ h:fs
2121 flagStr AnyString = "ANYSTRING"
2122 flagStr Automaton = "AUTOMATON"
2123 flagStr Complement = "COMPLEMENT"
2124 flagStr Empty = "EMPTY"
2125 flagStr Intersection = "INTERSECTION"
2126 flagStr Interval = "INTERVAL"
2128instance ToJSON Term where
2129 toJSON (Term field value) = object ["term" .= object
2133instance ToJSON BoolMatch where
2134 toJSON (MustMatch term cache) = object ["must" .= term,
2136 toJSON (MustNotMatch term cache) = object ["must_not" .= term,
2138 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2142instance (FromJSON a) => FromJSON (SearchResult a) where
2143 parseJSON (Object v) = SearchResult <$>
2145 v .: "timed_out" <*>
2148 v .:? "aggregations"
2151instance (FromJSON a) => FromJSON (SearchHits a) where
2152 parseJSON (Object v) = SearchHits <$>
2154 v .: "max_score" <*>
2158instance (FromJSON a) => FromJSON (Hit a) where
2159 parseJSON (Object v) = Hit <$>
2168instance FromJSON ShardResult where
2169 parseJSON (Object v) = ShardResult <$>
2171 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