@@ -1,8 +1,8 @@
1−{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
3{-# LANGUAGE FlexibleInstances #-}
2{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5{-# LANGUAGE MultiParamTypeClasses #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
5+{-# LANGUAGE NamedFieldPuns #-}
6{-# LANGUAGE OverloadedStrings #-}
6{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE RecordWildCards #-}
7{-# LANGUAGE RecordWildCards #-}
8{-# LANGUAGE UndecidableInstances #-}
8{-# LANGUAGE UndecidableInstances #-}
@@ -10,11 +10,11 @@
10-------------------------------------------------------------------------------
10-------------------------------------------------------------------------------
12-- Module : Database.Bloodhound.Types
12-- Module : Database.Bloodhound.Types
13−-- Copyright : (C) 2014 Chris Allen
13+-- Copyright : (C) 2014, 2018 Chris Allen
14-- License : BSD-style (see the file LICENSE)
14-- License : BSD-style (see the file LICENSE)
15-- Maintainer : Chris Allen <cma@bitemyapp.com
15-- Maintainer : Chris Allen <cma@bitemyapp.com
16-- Stability : provisional
16-- Stability : provisional
17−-- Portability : DeriveGeneric, RecordWildCards
17+-- Portability : RecordWildCards
19-- Data types for describing actions and data structures performed to interact
19-- Data types for describing actions and data structures performed to interact
20-- with Elasticsearch. The two main buckets your queries against Elasticsearch
20-- with Elasticsearch. The two main buckets your queries against Elasticsearch
@@ -42,25 +42,63 @@ module Database.Bloodhound.Types
42 , mkTermsAggregation
42 , mkTermsAggregation
43 , mkTermsScriptAggregation
43 , mkTermsScriptAggregation
44 , mkDateHistogram
44 , mkDateHistogram
45+ , mkCardinalityAggregation
45 , mkDocVersion
46 , mkDocVersion
48+ , mkExtendedStatsAggregation
46 , docVersionNumber
49 , docVersionNumber
48 , toDateHistogram
52 , toDateHistogram
49 , omitNulls
54 , omitNulls
52− , BHEnv(..)
57+ , BHEnv
53 , MonadBH(..)
62 , MonadBH(..)
54 , Version(..)
63 , Version(..)
55 , Status(..)
67 , Status(..)
56 , Existence(..)
68 , Existence(..)
57 , NullValue(..)
69 , NullValue(..)
58 , IndexSettings(..)
70 , IndexSettings(..)
71+ , UpdatableIndexSetting(..)
72+ , IndexSettingsSummary(..)
73+ , AllocationPolicy(..)
81+ , InitialShardCount(..)
59 , IndexTemplate(..)
85 , IndexTemplate(..)
60 , Server(..)
86 , Server(..)
62 , EsResult(..)
88 , EsResult(..)
63 , EsResultFound(..)
89 , EsResultFound(..)
91+ , EsProtocolException(..)
94+ , IndexAliasAction(..)
95+ , IndexAliasCreate(..)
96+ , IndexAliasSummary(..)
97+ , IndexAliasesSummary(..)
99+ , SearchAliasRouting(..)
100+ , IndexAliasRouting(..)
64 , DocVersion
102 , DocVersion
65 , ExternalDocVersion(..)
103 , ExternalDocVersion(..)
66 , VersionControl(..)
104 , VersionControl(..)
@@ -68,15 +106,22 @@ module Database.Bloodhound.Types
68 , IndexDocumentSettings(..)
106 , IndexDocumentSettings(..)
69 , Query(..)
107 , Query(..)
70 , Search(..)
108 , Search(..)
71 , SearchResult(..)
110 , SearchResult(..)
72 , SearchHits(..)
112 , SearchHits(..)
73 , TrackSortScores
113 , TrackSortScores
74 , From(..)
114 , From(..)
75 , Size(..)
115 , Size(..)
117+ , PatternOrPatterns(..)
76 , ShardResult(..)
121 , ShardResult(..)
77 , Hit(..)
122 , Hit(..)
78 , Filter(..)
124 , Filter(..)
80 , BoolMatch(..)
125 , BoolMatch(..)
81 , Term(..)
126 , Term(..)
82 , GeoPoint(..)
127 , GeoPoint(..)
@@ -103,8 +148,22 @@ module Database.Bloodhound.Types
103 , RegexpFlags(..)
148 , RegexpFlags(..)
104 , RegexpFlag(..)
149 , RegexpFlag(..)
105 , FieldName(..)
150 , FieldName(..)
106 , Script(..)
154 , Script(..)
155+ , ScriptLanguage(..)
107 , IndexName(..)
161 , IndexName(..)
162+ , IndexSelection(..)
165+ , ForceMergeIndexSettings(..)
166+ , defaultForceMergeIndexSettings
108 , TemplateName(..)
167 , TemplateName(..)
109 , TemplatePattern(..)
168 , TemplatePattern(..)
110 , MappingName(..)
169 , MappingName(..)
@@ -128,8 +187,19 @@ module Database.Bloodhound.Types
128 , BoolQuery(..)
187 , BoolQuery(..)
129 , BoostingQuery(..)
188 , BoostingQuery(..)
130 , CommonTermsQuery(..)
189 , CommonTermsQuery(..)
190+ , FunctionScoreQuery(..)
193+ , FunctionScoreFunctions(..)
194+ , ComponentFunctionScoreFunction(..)
195+ , FunctionScoreFunction(..)
198+ , FieldValueFactor(..)
200+ , FactorModifier(..)
201+ , FactorMissingFieldValue(..)
131 , DisMaxQuery(..)
202 , DisMaxQuery(..)
133 , FuzzyLikeThisQuery(..)
203 , FuzzyLikeThisQuery(..)
134 , FuzzyLikeFieldQuery(..)
204 , FuzzyLikeFieldQuery(..)
135 , FuzzyQuery(..)
205 , FuzzyQuery(..)
@@ -145,10 +215,16 @@ module Database.Bloodhound.Types
145 , RangeQuery(..)
215 , RangeQuery(..)
146 , RegexpQuery(..)
216 , RegexpQuery(..)
147 , QueryString(..)
217 , QueryString(..)
218+ , TemplateQueryInline(..)
219+ , TemplateQueryKeyValuePairs(..)
148 , BooleanOperator(..)
221 , BooleanOperator(..)
149 , ZeroTermsQuery(..)
222 , ZeroTermsQuery(..)
150 , CutoffFrequency(..)
223 , CutoffFrequency(..)
151 , Analyzer(..)
224 , Analyzer(..)
152 , MaxExpansions(..)
228 , MaxExpansions(..)
153 , Lenient(..)
229 , Lenient(..)
154 , MatchQueryType(..)
230 , MatchQueryType(..)
@@ -195,16 +271,118 @@ module Database.Bloodhound.Types
195 , CollectionMode(..)
271 , CollectionMode(..)
196 , TermOrder(..)
272 , TermOrder(..)
197 , TermInclusion(..)
273 , TermInclusion(..)
274+ , SnapshotRepoSelection(..)
275+ , GenericSnapshotRepo(..)
277+ , SnapshotRepoConversionError(..)
278+ , SnapshotRepoType(..)
279+ , GenericSnapshotRepoSettings(..)
280+ , SnapshotRepoUpdateSettings(..)
281+ , defaultSnapshotRepoUpdateSettings
282+ , SnapshotRepoName(..)
283+ , SnapshotRepoPattern(..)
284+ , SnapshotVerification(..)
285+ , SnapshotNodeVerification(..)
292+ , NodeBreakersStats(..)
293+ , NodeBreakerStats(..)
295+ , NodeTransportStats(..)
297+ , NodeDataPathStats(..)
298+ , NodeFSTotalStats(..)
299+ , NodeNetworkStats(..)
300+ , NodeThreadPoolsStats(..)
301+ , NodeThreadPoolStats(..)
303+ , JVMBufferPoolStats(..)
306+ , NodeProcessStats(..)
309+ , NodeIndicesStats(..)
313+ , NodePluginInfo(..)
315+ , NodeTransportInfo(..)
316+ , BoundTransportAddress(..)
317+ , NodeNetworkInfo(..)
319+ , NetworkInterfaceName(..)
320+ , NodeNetworkInterface(..)
321+ , NodeThreadPoolsInfo(..)
322+ , NodeThreadPoolInfo(..)
323+ , ThreadPoolSize(..)
324+ , ThreadPoolType(..)
327+ , JVMGCCollector(..)
332+ , NodeProcessInfo(..)
333+ , FsSnapshotRepo(..)
334+ , SnapshotCreateSettings(..)
335+ , defaultSnapshotCreateSettings
336+ , SnapshotSelection(..)
337+ , SnapshotPattern(..)
339+ , SnapshotShardFailure(..)
343+ , SnapshotRestoreSettings(..)
344+ , defaultSnapshotRestoreSettings
345+ , RestoreRenamePattern(..)
346+ , RestoreRenameToken(..)
350+ , RestoreIndexSettings(..)
353+ , PhraseSuggester(..)
354+ , PhraseSuggesterHighlighter(..)
355+ , PhraseSuggesterCollate(..)
357+ , SuggestOptions(..)
358+ , SuggestResponse(..)
359+ , NamedSuggestionResponse(..)
360+ , DirectGenerators(..)
361+ , mkDirectGenerators
362+ , DirectGeneratorSuggestModeTypes (..)
199 , Aggregation(..)
364 , Aggregation(..)
200 , Aggregations
365 , Aggregations
201 , AggregationResults
366 , AggregationResults
202 , Bucket(..)
368 , Bucket(..)
203 , BucketAggregation(..)
369 , BucketAggregation(..)
204 , TermsAggregation(..)
370 , TermsAggregation(..)
371+ , MissingAggregation(..)
205 , ValueCountAggregation(..)
372 , ValueCountAggregation(..)
206 , FilterAggregation(..)
373 , FilterAggregation(..)
374+ , CardinalityAggregation(..)
375+ , MaxAggregation(..)
207 , DateHistogramAggregation(..)
376 , DateHistogramAggregation(..)
377+ , DateRangeAggregation(..)
378+ , DateRangeAggRange(..)
380+ , DateMathAnchor(..)
381+ , DateMathModifier(..)
383+ , TopHitsAggregation(..)
384+ , StatisticsAggregation(..)
209 , Highlights(..)
387 , Highlights(..)
210 , FieldHighlight(..)
388 , FieldHighlight(..)
@@ -218,501 +396,36 @@ module Database.Bloodhound.Types
218 , HighlightTag(..)
396 , HighlightTag(..)
219 , HitHighlight
397 , HitHighlight
221 , TermsResult(..)
400 , TermsResult(..)
222 , DateHistogramResult(..)
401 , DateHistogramResult(..)
223− ) where
402+ , DateRangeResult(..)
224−
403+ , TopHitResult(..)
225−import Control.Applicative
404+
226−import Control.Monad.Error
405+ , EsUsername(..)
227−import Control.Monad.Reader
406+ , EsPassword(..)
228−import Control.Monad.State
407+
229−import Control.Monad.Writer
408+ , Analysis(..)
230−import Data.Aeson
409+ , AnalyzerDefinition(..)
231−import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
410+ , TokenizerDefinition(..)
232−import qualified Data.ByteString.Lazy.Char8 as L
411+ , TokenFilterDefinition(..)
233−import Data.List (nub, foldl')
412+ , CharFilterDefinition(..)
234−import Data.List.NonEmpty (NonEmpty (..), toList)
413+ , Ngram(..)
235−import qualified Data.HashMap.Strict as HM (union)
414+ , TokenChar(..)
236−import qualified Data.Map.Strict as M
415+ , Shingle(..)
237−import Data.Maybe
416+ , Language(..)
238−import Data.Text (Text)
417+ ) where
239−import qualified Data.Text as T
418+
240−import Data.Time.Clock (UTCTime)
419+import Bloodhound.Import
241−import qualified Data.Vector as V
420+
242−import GHC.Enum
421+import Database.Bloodhound.Internal.Aggregation
243−import GHC.Generics (Generic)
422+import Database.Bloodhound.Internal.Analysis
244−import Network.HTTP.Client
423+import Database.Bloodhound.Internal.Client
245−import qualified Network.HTTP.Types.Method as NHTM
424+import Database.Bloodhound.Internal.Highlight
246−
425+import Database.Bloodhound.Internal.Newtypes
247−import Database.Bloodhound.Types.Class
426+import Database.Bloodhound.Internal.Query
248−
427+import Database.Bloodhound.Internal.Sort
249−-- $setup
428+import Database.Bloodhound.Internal.Suggest
250−-- >>> :set -XOverloadedStrings
251−-- >>> import Database.Bloodhound
252−-- >>> let testServer = (Server "http://localhost:9200")
253−-- >>> let testIndex = IndexName "twitter"
254−-- >>> let testMapping = MappingName "tweet"
255−-- >>> let defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
257−-- defaultIndexSettings is exported by Database.Bloodhound as well
258−-- no trailing slashes in servers, library handles building the path.
260−{-| Common environment for Elasticsearch calls. Connections will be
261− pipelined according to the provided HTTP connection manager.
263−data BHEnv = BHEnv { bhServer :: Server
264− , bhManager :: Manager
267−{-| All API calls to Elasticsearch operate within
268− MonadBH. The idea is that it can be easily embedded in your
269− own monad transformer stack. A default instance for a ReaderT and
270− alias 'BH' is provided for the simple case.
272−class (Functor m, Applicative m, MonadIO m) => MonadBH m where
275−newtype BH m a = BH {
276− unBH :: ReaderT BHEnv m a
277− } deriving ( Functor
288−instance MonadTrans BH where
291−instance (MonadReader r m) => MonadReader r (BH m) where
293− local f (BH (ReaderT m)) = BH $ ReaderT $ \r ->
296−instance (Functor m, Applicative m, MonadIO m) => MonadBH (BH m) where
297− getBHEnv = BH getBHEnv
300−instance (Functor m, Applicative m, MonadIO m) => MonadBH (ReaderT BHEnv m) where
303−runBH :: BHEnv -> BH m a -> m a
304−runBH e f = runReaderT (unBH f) e
306−{-| 'Version' is embedded in 'Status' -}
307−data Version = Version { number :: Text
308− , build_hash :: Text
309− , build_timestamp :: UTCTime
310− , build_snapshot :: Bool
311− , lucene_version :: Text } deriving (Eq, Show, Generic)
313−{-| 'Status' is a data type for describing the JSON body returned by
314− Elasticsearch when you query its status. This was deprecated in 1.2.0.
316− <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-status.html#indices-status>
319−data Status = Status { ok :: Maybe Bool
322− , version :: Version
323− , tagline :: Text } deriving (Eq, Show)
325−{-| 'IndexSettings' is used to configure the shards and replicas when you create
326− an Elasticsearch Index.
328− <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html>
332− IndexSettings { indexShards :: ShardCount
333− , indexReplicas :: ReplicaCount } deriving (Eq, Show)
335−{-| 'defaultIndexSettings' is an 'IndexSettings' with 3 shards and 2 replicas. -}
336−defaultIndexSettings :: IndexSettings
337−defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
339−{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
340−type Reply = Network.HTTP.Client.Response L.ByteString
341−type Method = NHTM.Method
343−{-| 'OpenCloseIndex' is a sum type for opening and closing indices.
345− <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
347−data OpenCloseIndex = OpenIndex | CloseIndex deriving (Eq, Show)
349−data FieldType = GeoPointType
355− | ByteType deriving (Eq, Show)
357−data FieldDefinition =
358− FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
360−{-| An 'IndexTemplate' defines a template that will automatically be
361− applied to new indices created. The templates include both
362− 'IndexSettings' and mappings, and a simple 'TemplatePattern' that
363− controls if the template will be applied to the index created.
364− Specify mappings as follows: @[toJSON TweetMapping, ...]@
366− https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices-templates.html
369− IndexTemplate { templatePattern :: TemplatePattern
370− , templateSettings :: Maybe IndexSettings
371− , templateMappings :: [Value]
375− MappingField { mappingFieldName :: FieldName
376− , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
378−{-| Support for type reification of 'Mapping's is currently incomplete, for
379− now the mapping API verbiage expects a 'ToJSON'able blob.
381− Indexes have mappings, mappings are schemas for the documents contained in the
382− index. I'd recommend having only one mapping per index, always having a mapping,
383− and keeping different kinds of documents separated if possible.
385−data Mapping = Mapping { typeName :: TypeName
386− , mappingFields :: [MappingField] } deriving (Eq, Show)
388−{-| 'BulkOperation' is a sum type for expressing the four kinds of bulk
389− operation index, create, delete, and update. 'BulkIndex' behaves like an
390− "upsert", 'BulkCreate' will fail if a document already exists at the DocId.
392− <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html#docs-bulk>
395− BulkIndex IndexName MappingName DocId Value
396− | BulkCreate IndexName MappingName DocId Value
397− | BulkDelete IndexName MappingName DocId
398− | BulkUpdate IndexName MappingName DocId Value deriving (Eq, Show)
400−{-| 'EsResult' describes the standard wrapper JSON document that you see in
401− successful Elasticsearch lookups or lookups that couldn't find the document.
403−data EsResult a = EsResult { _index :: Text
406− , foundResult :: Maybe (EsResultFound a)} deriving (Eq, Show)
409−{-| 'EsResultFound' contains the document and its metadata inside of an
410− 'EsResult' when the document was successfully found.
412−data EsResultFound a = EsResultFound { _version :: DocVersion
413− , _source :: a } deriving (Eq, Show)
417−{-| 'DocVersion' is an integer version number for a document between 1
418−and 9.2e+18 used for <<https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html optimistic concurrency control>>.
420−newtype DocVersion = DocVersion {
421− docVersionNumber :: Int
422− } deriving (Eq, Show, Ord, ToJSON)
424−-- | Smart constructor for in-range doc version
425−mkDocVersion :: Int -> Maybe DocVersion
427− | i >= (docVersionNumber minBound) && i <= (docVersionNumber maxBound) =
429− | otherwise = Nothing
432−{-| 'ExternalDocVersion' is a convenience wrapper if your code uses its
433−own version numbers instead of ones from ES.
435−newtype ExternalDocVersion = ExternalDocVersion DocVersion
436− deriving (Eq, Show, Ord, Bounded, Enum, ToJSON)
438−{-| 'VersionControl' is specified when indexing documents as a
439−optimistic concurrency control.
441−data VersionControl = NoVersionControl
442− -- ^ Don't send a version. This is a pure overwrite.
443− | InternalVersion DocVersion
444− -- ^ Use the default ES versioning scheme. Only
445− -- index the document if the version is the same
446− -- as the one specified. Only applicable to
447− -- updates, as you should be getting Version from
449− | ExternalGT ExternalDocVersion
450− -- ^ Use your own version numbering. Only index
451− -- the document if the version is strictly higher
452− -- OR the document doesn't exist. The given
453− -- version will be used as the new version number
454− -- for the stored document. N.B. All updates must
455− -- increment this number, meaning there is some
456− -- global, external ordering of updates.
457− | ExternalGTE ExternalDocVersion
458− -- ^ Use your own version numbering. Only index
459− -- the document if the version is equal or higher
460− -- than the stored version. Will succeed if there
461− -- is no existing document. The given version will
462− -- be used as the new version number for the
463− -- stored document. Use with care, as this could
464− -- result in data loss.
465− | ForceVersion ExternalDocVersion
466− -- ^ The document will always be indexed and the
467− -- given version will be the new version. This is
468− -- typically used for correcting errors. Use with
469− -- care, as this could result in data loss.
470− deriving (Show, Eq, Ord)
472−{-| 'DocumentParent' is used to specify a parent document.
474−newtype DocumentParent = DocumentParent DocId
477−{-| 'IndexDocumentSettings' are special settings supplied when indexing
478−a document. For the best backwards compatiblity when new fields are
479−added, you should probably prefer to start with 'defaultIndexDocumentSettings'
481−data IndexDocumentSettings =
482− IndexDocumentSettings { idsVersionControl :: VersionControl
483− , idsParent :: Maybe DocumentParent
484− } deriving (Eq, Show)
486−{-| Reasonable default settings. Chooses no version control and no parent.
488−defaultIndexDocumentSettings :: IndexDocumentSettings
489−defaultIndexDocumentSettings = IndexDocumentSettings NoVersionControl Nothing
491−{-| 'Sort' is a synonym for a list of 'SortSpec's. Sort behavior is order
492− dependent with later sorts acting as tie-breakers for earlier sorts.
494−type Sort = [SortSpec]
496−{-| The two main kinds of 'SortSpec' are 'DefaultSortSpec' and
497− 'GeoDistanceSortSpec'. The latter takes a 'SortOrder', 'GeoPoint', and
498− 'DistanceUnit' to express "nearness" to a single geographical point as a
501−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
503−data SortSpec = DefaultSortSpec DefaultSort
504− | GeoDistanceSortSpec SortOrder GeoPoint DistanceUnit deriving (Eq, Show)
506−{-| 'DefaultSort' is usually the kind of 'SortSpec' you'll want. There's a
507− 'mkSort' convenience function for when you want to specify only the most
510−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
513− DefaultSort { sortFieldName :: FieldName
514− , sortOrder :: SortOrder
516− , ignoreUnmapped :: Bool
517− , sortMode :: Maybe SortMode
518− , missingSort :: Maybe Missing
519− , nestedFilter :: Maybe Filter } deriving (Eq, Show)
521−{-| 'SortOrder' is 'Ascending' or 'Descending', as you might expect. These get
522− encoded into "asc" or "desc" when turned into JSON.
524−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
526−data SortOrder = Ascending
527− | Descending deriving (Eq, Show)
529−{-| 'Missing' prescribes how to handle missing fields. A missing field can be
530− sorted last, first, or using a custom value as a substitute.
532−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_missing_values>
534−data Missing = LastMissing
536− | CustomMissing Text deriving (Eq, Show)
538−{-| 'SortMode' prescribes how to handle sorting array/multi-valued fields.
540−http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_sort_mode_option
542−data SortMode = SortMin
545− | SortAvg deriving (Eq, Show)
547−{-| 'mkSort' defaults everything but the 'FieldName' and the 'SortOrder' so
548− that you can concisely describe the usual kind of 'SortSpec's you want.
550−mkSort :: FieldName -> SortOrder -> DefaultSort
551−mkSort fieldName sOrder = DefaultSort fieldName sOrder False Nothing Nothing Nothing
553−{-| 'Cache' is for telling ES whether it should cache a 'Filter' not.
554− 'Query's cannot be cached.
556−type Cache = Bool -- caching on/off
557−defaultCache :: Cache
560−{-| 'PrefixValue' is used in 'PrefixQuery' as the main query component.
562−type PrefixValue = Text
564−{-| 'BooleanOperator' is the usual And/Or operators with an ES compatible
565− JSON encoding baked in. Used all over the place.
567−data BooleanOperator = And | Or deriving (Eq, Show)
569−{-| 'ShardCount' is part of 'IndexSettings'
571−newtype ShardCount = ShardCount Int deriving (Eq, Show, Generic)
573−{-| 'ReplicaCount' is part of 'IndexSettings'
575−newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic)
577−{-| 'Server' is used with the client functions to point at the ES instance
579−newtype Server = Server Text deriving (Eq, Show)
581−{-| 'IndexName' is used to describe which index to query/create/delete
583−newtype IndexName = IndexName Text deriving (Eq, Generic, Show)
585−{-| 'TemplateName' is used to describe which template to query/create/delete
587−newtype TemplateName = TemplateName Text deriving (Eq, Show, Generic)
589−{-| 'TemplatePattern' represents a pattern which is matched against index names
591−newtype TemplatePattern = TemplatePattern Text deriving (Eq, Show, Generic)
593−{-| 'MappingName' is part of mappings which are how ES describes and schematizes
594− the data in the indices.
596−newtype MappingName = MappingName Text deriving (Eq, Generic, Show)
598−{-| 'DocId' is a generic wrapper value for expressing unique Document IDs.
599− Can be set by the user or created by ES itself. Often used in client
600− functions for poking at specific documents.
602−newtype DocId = DocId Text deriving (Eq, Generic, Show)
604−{-| 'QueryString' is used to wrap query text bodies, be they human written or not.
606−newtype QueryString = QueryString Text deriving (Eq, Generic, Show)
608−{-| 'FieldName' is used all over the place wherever a specific field within
609− a document needs to be specified, usually in 'Query's or 'Filter's.
611−newtype FieldName = FieldName Text deriving (Eq, Show)
614−{-| 'Script' is often used in place of 'FieldName' to specify more
615−complex ways of extracting a value from a document.
617−newtype Script = Script { scriptText :: Text } deriving (Eq, Show)
619−{-| 'CacheName' is used in 'RegexpFilter' for describing the
620− 'CacheKey' keyed caching behavior.
622−newtype CacheName = CacheName Text deriving (Eq, Show)
624−{-| 'CacheKey' is used in 'RegexpFilter' to key regex caching.
627− CacheKey Text deriving (Eq, Show)
629− Existence Bool deriving (Eq, Show)
631− NullValue Bool deriving (Eq, Show)
632−newtype CutoffFrequency =
633− CutoffFrequency Double deriving (Eq, Show, Generic)
635− Analyzer Text deriving (Eq, Show, Generic)
636−newtype MaxExpansions =
637− MaxExpansions Int deriving (Eq, Show, Generic)
639−{-| 'Lenient', if set to true, will cause format based failures to be
640− ignored. I don't know what the bloody default is, Elasticsearch
641− documentation didn't say what it was. Let me know if you figure it out.
644− Lenient Bool deriving (Eq, Show, Generic)
646− Tiebreaker Double deriving (Eq, Show, Generic)
648− Boost Double deriving (Eq, Show, Generic)
650− BoostTerms Double deriving (Eq, Show, Generic)
652−{-| 'MinimumMatch' controls how many should clauses in the bool query should
653− match. Can be an absolute value (2) or a percentage (30%) or a
654− combination of both.
656−newtype MinimumMatch =
657− MinimumMatch Int deriving (Eq, Show, Generic)
658−newtype MinimumMatchText =
659− MinimumMatchText Text deriving (Eq, Show)
660−newtype DisableCoord =
661− DisableCoord Bool deriving (Eq, Show, Generic)
662−newtype IgnoreTermFrequency =
663− IgnoreTermFrequency Bool deriving (Eq, Show, Generic)
664−newtype MinimumTermFrequency =
665− MinimumTermFrequency Int deriving (Eq, Show, Generic)
666−newtype MaxQueryTerms =
667− MaxQueryTerms Int deriving (Eq, Show, Generic)
669− Fuzziness Double deriving (Eq, Show, Generic)
671−{-| 'PrefixLength' is the prefix length used in queries, defaults to 0. -}
672−newtype PrefixLength =
673− PrefixLength Int deriving (Eq, Show, Generic)
675− TypeName Text deriving (Eq, Show, Generic)
676−newtype PercentMatch =
677− PercentMatch Double deriving (Eq, Show, Generic)
679− StopWord Text deriving (Eq, Show, Generic)
681− QueryPath Text deriving (Eq, Show, Generic)
683−{-| Allowing a wildcard at the beginning of a word (eg "*ing") is particularly
684− heavy, because all terms in the index need to be examined, just in case
685− they match. Leading wildcards can be disabled by setting
686− 'AllowLeadingWildcard' to false. -}
687−newtype AllowLeadingWildcard =
688− AllowLeadingWildcard Bool deriving (Eq, Show, Generic)
689−newtype LowercaseExpanded =
690− LowercaseExpanded Bool deriving (Eq, Show, Generic)
691−newtype EnablePositionIncrements =
692− EnablePositionIncrements Bool deriving (Eq, Show, Generic)
694−{-| By default, wildcard terms in a query are not analyzed.
695− Setting 'AnalyzeWildcard' to true enables best-effort analysis.
697−newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show, Generic)
699−{-| 'GeneratePhraseQueries' defaults to false.
701−newtype GeneratePhraseQueries =
702− GeneratePhraseQueries Bool deriving (Eq, Show, Generic)
704−{-| 'Locale' is used for string conversions - defaults to ROOT.
706−newtype Locale = Locale Text deriving (Eq, Show, Generic)
707−newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show, Generic)
708−newtype MinWordLength = MinWordLength Int deriving (Eq, Show, Generic)
710−{-| 'PhraseSlop' sets the default slop for phrases, 0 means exact
711− phrase matches. Default is 0.
713−newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show, Generic)
714−newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show, Generic)
715−newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic)
717{-| 'unpackId' is a silly convenience function that gets used once.
430{-| 'unpackId' is a silly convenience function that gets used once.
@@ -720,8 +433,6 @@ unpackId :: DocId -> Text
720unpackId (DocId docId) = docId
433unpackId (DocId docId) = docId
722type TrackSortScores = Bool
435type TrackSortScores = Bool
723−newtype From = From Int deriving (Eq, Show, ToJSON)
724−newtype Size = Size Int deriving (Eq, Show, ToJSON)
726data Search = Search { queryBody :: Maybe Query
437data Search = Search { queryBody :: Maybe Query
727 , filterBody :: Maybe Filter
438 , filterBody :: Maybe Filter
@@ -732,1590 +443,88 @@ data Search = Search { queryBody :: Maybe Query
732 , trackSortScores :: TrackSortScores
443 , trackSortScores :: TrackSortScores
733 , from :: From
444 , from :: From
734 , size :: Size
445 , size :: Size
735− , fields :: Maybe [FieldName] } deriving (Eq, Show)
446+ , searchType :: SearchType
736−
447+ , searchAfterKey :: Maybe SearchAfterKey
737−data Highlights = Highlights { globalsettings :: Maybe HighlightSettings
448+ , fields :: Maybe [FieldName]
738− , highlightFields :: [FieldHighlight]
449+ , scriptFields :: Maybe ScriptFields
739− } deriving (Show, Eq)
450+ , source :: Maybe Source
740−
451+ , suggestBody :: Maybe Suggest -- ^ Only one Suggestion request / response per Search is supported.
741−data FieldHighlight = FieldHighlight FieldName (Maybe HighlightSettings)
745−data HighlightSettings = Plain PlainHighlight
746− | Postings PostingsHighlight
747− | FastVector FastVectorHighlight
749−data PlainHighlight =
750− PlainHighlight { plainCommon :: Maybe CommonHighlight
751− , plainNonPost :: Maybe NonPostings } deriving (Show, Eq)
753− -- This requires that index_options are set to 'offset' in the mapping.
754−data PostingsHighlight = PostingsHighlight (Maybe CommonHighlight) deriving (Show, Eq)
756−-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
757−data FastVectorHighlight =
758− FastVectorHighlight { fvCommon :: Maybe CommonHighlight
759− , fvNonPostSettings :: Maybe NonPostings
760− , boundaryChars :: Maybe Text
761− , boundaryMaxScan :: Maybe Int
762− , fragmentOffset :: Maybe Int
763− , matchedFields :: [Text]
764− , phraseLimit :: Maybe Int
765− } deriving (Show, Eq)
767−data CommonHighlight =
768− CommonHighlight { order :: Maybe Text
769− , forceSource :: Maybe Bool
770− , tag :: Maybe HighlightTag
771− , encoder :: Maybe HighlightEncoder
772− , noMatchSize :: Maybe Int
773− , highlightQuery :: Maybe Query
774− , requireFieldMatch :: Maybe Bool
775− } deriving (Show, Eq)
777−-- Settings that are only applicable to FastVector and Plain highlighters.
779− NonPostings { fragmentSize :: Maybe Int
780− , numberOfFragments :: Maybe Int} deriving (Show, Eq)
782−data HighlightEncoder = DefaultEncoder
786−-- NOTE: Should the tags use some kind of HTML type, rather than Text?
787−data HighlightTag = TagSchema Text
788− | CustomTags ([Text], [Text]) -- Only uses more than the first value in the lists if fvh
793− TermQuery Term (Maybe Boost)
794− | TermsQuery (NonEmpty Term)
795− | QueryMatchQuery MatchQuery
796− | QueryMultiMatchQuery MultiMatchQuery
797− | QueryBoolQuery BoolQuery
798− | QueryBoostingQuery BoostingQuery
799− | QueryCommonTermsQuery CommonTermsQuery
800− | ConstantScoreFilter Filter Boost
801− | ConstantScoreQuery Query Boost
802− | QueryDisMaxQuery DisMaxQuery
803− | QueryFilteredQuery FilteredQuery
804− | QueryFuzzyLikeThisQuery FuzzyLikeThisQuery
805− | QueryFuzzyLikeFieldQuery FuzzyLikeFieldQuery
806− | QueryFuzzyQuery FuzzyQuery
807− | QueryHasChildQuery HasChildQuery
808− | QueryHasParentQuery HasParentQuery
809− | IdsQuery MappingName [DocId]
810− | QueryIndicesQuery IndicesQuery
811− | MatchAllQuery (Maybe Boost)
812− | QueryMoreLikeThisQuery MoreLikeThisQuery
813− | QueryMoreLikeThisFieldQuery MoreLikeThisFieldQuery
814− | QueryNestedQuery NestedQuery
815− | QueryPrefixQuery PrefixQuery
816− | QueryQueryStringQuery QueryStringQuery
817− | QuerySimpleQueryStringQuery SimpleQueryStringQuery
818− | QueryRangeQuery RangeQuery
819− | QueryRegexpQuery RegexpQuery
823− RegexpQuery { regexpQueryField :: FieldName
824− , regexpQuery :: Regexp
825− , regexpQueryFlags :: RegexpFlags
826− , regexpQueryBoost :: Maybe Boost
827− } deriving (Eq, Show)
830− RangeQuery { rangeQueryField :: FieldName
831− , rangeQueryRange :: RangeValue
832− , rangeQueryBoost :: Boost } deriving (Eq, Show)
834−mkRangeQuery :: FieldName -> RangeValue -> RangeQuery
835−mkRangeQuery f r = RangeQuery f r (Boost 1.0)
837−data SimpleQueryStringQuery =
838− SimpleQueryStringQuery
839− { simpleQueryStringQuery :: QueryString
840− , simpleQueryStringField :: Maybe FieldOrFields
841− , simpleQueryStringOperator :: Maybe BooleanOperator
842− , simpleQueryStringAnalyzer :: Maybe Analyzer
843− , simpleQueryStringFlags :: Maybe [SimpleQueryFlag]
844− , simpleQueryStringLowercaseExpanded :: Maybe LowercaseExpanded
845− , simpleQueryStringLocale :: Maybe Locale
846− } deriving (Eq, Show)
848−data SimpleQueryFlag =
855− | SimpleQueryPrecedence
857− | SimpleQueryWhitespace
860− | SimpleQuerySlop deriving (Eq, Show)
862−-- use_dis_max and tie_breaker when fields are plural?
863−data QueryStringQuery =
865− { queryStringQuery :: QueryString
866− , queryStringDefaultField :: Maybe FieldName
867− , queryStringOperator :: Maybe BooleanOperator
868− , queryStringAnalyzer :: Maybe Analyzer
869− , queryStringAllowLeadingWildcard :: Maybe AllowLeadingWildcard
870− , queryStringLowercaseExpanded :: Maybe LowercaseExpanded
871− , queryStringEnablePositionIncrements :: Maybe EnablePositionIncrements
872− , queryStringFuzzyMaxExpansions :: Maybe MaxExpansions
873− , queryStringFuzziness :: Maybe Fuzziness
874− , queryStringFuzzyPrefixLength :: Maybe PrefixLength
875− , queryStringPhraseSlop :: Maybe PhraseSlop
876− , queryStringBoost :: Maybe Boost
877− , queryStringAnalyzeWildcard :: Maybe AnalyzeWildcard
878− , queryStringGeneratePhraseQueries :: Maybe GeneratePhraseQueries
879− , queryStringMinimumShouldMatch :: Maybe MinimumMatch
880− , queryStringLenient :: Maybe Lenient
881− , queryStringLocale :: Maybe Locale
882− } deriving (Eq, Show)
884−mkQueryStringQuery :: QueryString -> QueryStringQuery
885−mkQueryStringQuery qs =
886− QueryStringQuery qs Nothing Nothing
887− Nothing Nothing Nothing Nothing
888− Nothing Nothing Nothing Nothing
889− Nothing Nothing Nothing Nothing
892−data FieldOrFields = FofField FieldName
893− | FofFields [FieldName] deriving (Eq, Show)
897− { prefixQueryField :: FieldName
898− , prefixQueryPrefixValue :: Text
899− , prefixQueryBoost :: Maybe Boost } deriving (Eq, Show)
903− { nestedQueryPath :: QueryPath
904− , nestedQueryScoreType :: ScoreType
905− , nestedQuery :: Query } deriving (Eq, Show)
907−data MoreLikeThisFieldQuery =
908− MoreLikeThisFieldQuery
909− { moreLikeThisFieldText :: Text
910− , moreLikeThisFieldFields :: FieldName
911− -- default 0.3 (30%)
912− , moreLikeThisFieldPercentMatch :: Maybe PercentMatch
913− , moreLikeThisFieldMinimumTermFreq :: Maybe MinimumTermFrequency
914− , moreLikeThisFieldMaxQueryTerms :: Maybe MaxQueryTerms
915− , moreLikeThisFieldStopWords :: Maybe [StopWord]
916− , moreLikeThisFieldMinDocFrequency :: Maybe MinDocFrequency
917− , moreLikeThisFieldMaxDocFrequency :: Maybe MaxDocFrequency
918− , moreLikeThisFieldMinWordLength :: Maybe MinWordLength
919− , moreLikeThisFieldMaxWordLength :: Maybe MaxWordLength
920− , moreLikeThisFieldBoostTerms :: Maybe BoostTerms
921− , moreLikeThisFieldBoost :: Maybe Boost
922− , moreLikeThisFieldAnalyzer :: Maybe Analyzer
923− } deriving (Eq, Show)
925−data MoreLikeThisQuery =
927− { moreLikeThisText :: Text
928− , moreLikeThisFields :: Maybe [FieldName]
929− -- default 0.3 (30%)
930− , moreLikeThisPercentMatch :: Maybe PercentMatch
931− , moreLikeThisMinimumTermFreq :: Maybe MinimumTermFrequency
932− , moreLikeThisMaxQueryTerms :: Maybe MaxQueryTerms
933− , moreLikeThisStopWords :: Maybe [StopWord]
934− , moreLikeThisMinDocFrequency :: Maybe MinDocFrequency
935− , moreLikeThisMaxDocFrequency :: Maybe MaxDocFrequency
936− , moreLikeThisMinWordLength :: Maybe MinWordLength
937− , moreLikeThisMaxWordLength :: Maybe MaxWordLength
938− , moreLikeThisBoostTerms :: Maybe BoostTerms
939− , moreLikeThisBoost :: Maybe Boost
940− , moreLikeThisAnalyzer :: Maybe Analyzer
941− } deriving (Eq, Show)
945− { indicesQueryIndices :: [IndexName]
946− , indicesQuery :: Query
948− , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
950−data HasParentQuery =
952− { hasParentQueryType :: TypeName
953− , hasParentQuery :: Query
954− , hasParentQueryScoreType :: Maybe ScoreType } deriving (Eq, Show)
452+ } deriving (Eq, Show)
958− { hasChildQueryType :: TypeName
959− , hasChildQuery :: Query
960− , hasChildQueryScoreType :: Maybe ScoreType } deriving (Eq, Show)
962−data ScoreType =
455+instance ToJSON Search where
963− ScoreTypeMax
456+ toJSON (Search mquery sFilter sort searchAggs
964− | ScoreTypeSum
457+ highlight sTrackSortScores sFrom sSize _ sAfter sFields
965− | ScoreTypeAvg
458+ sScriptFields sSource sSuggest) =
966− | ScoreTypeNone deriving (Eq, Show)
459+ omitNulls [ "query" .= query'
967−
460+ , "sort" .= sort
968−data FuzzyQuery =
461+ , "aggregations" .= searchAggs
969− FuzzyQuery { fuzzyQueryField :: FieldName
462+ , "highlight" .= highlight
970− , fuzzyQueryValue :: Text
463+ , "from" .= sFrom
971− , fuzzyQueryPrefixLength :: PrefixLength
464+ , "size" .= sSize
972− , fuzzyQueryMaxExpansions :: MaxExpansions
465+ , "track_scores" .= sTrackSortScores
973− , fuzzyQueryFuzziness :: Fuzziness
466+ , "search_after" .= sAfter
974− , fuzzyQueryBoost :: Maybe Boost
467+ , "fields" .= sFields
975− } deriving (Eq, Show)
468+ , "script_fields" .= sScriptFields
976−
469+ , "_source" .= sSource
977−data FuzzyLikeFieldQuery =
470+ , "suggest" .= sSuggest]
978− FuzzyLikeFieldQuery
471+
979− { fuzzyLikeField :: FieldName
472+ where query' = case sFilter of
980− -- anaphora is good for the soul.
473+ Nothing -> mquery
981− , fuzzyLikeFieldText :: Text
474+ Just x ->
982− , fuzzyLikeFieldMaxQueryTerms :: MaxQueryTerms
475+ Just
983− , fuzzyLikeFieldIgnoreTermFrequency :: IgnoreTermFrequency
476+ . QueryBoolQuery
984− , fuzzyLikeFieldFuzziness :: Fuzziness
477+ $ mkBoolQuery (maybeToList mquery)
985− , fuzzyLikeFieldPrefixLength :: PrefixLength
478+ [x] [] []
986− , fuzzyLikeFieldBoost :: Boost
479+
987− , fuzzyLikeFieldAnalyzer :: Maybe Analyzer
480+data SearchType = SearchTypeQueryThenFetch
988− } deriving (Eq, Show)
481+ | SearchTypeDfsQueryThenFetch
990−data FuzzyLikeThisQuery =
992− { fuzzyLikeFields :: [FieldName]
993− , fuzzyLikeText :: Text
994− , fuzzyLikeMaxQueryTerms :: MaxQueryTerms
995− , fuzzyLikeIgnoreTermFrequency :: IgnoreTermFrequency
996− , fuzzyLikeFuzziness :: Fuzziness
997− , fuzzyLikePrefixLength :: PrefixLength
998− , fuzzyLikeBoost :: Boost
999− , fuzzyLikeAnalyzer :: Maybe Analyzer
1000− } deriving (Eq, Show)
1002−data FilteredQuery =
1004− { filteredQuery :: Query
1005− , filteredFilter :: Filter } deriving (Eq, Show)
1008− DisMaxQuery { disMaxQueries :: [Query]
1010− , disMaxTiebreaker :: Tiebreaker
1011− , disMaxBoost :: Maybe Boost
1012− } deriving (Eq, Show)
1015− MatchQuery { matchQueryField :: FieldName
1016− , matchQueryQueryString :: QueryString
1017− , matchQueryOperator :: BooleanOperator
1018− , matchQueryZeroTerms :: ZeroTermsQuery
1019− , matchQueryCutoffFrequency :: Maybe CutoffFrequency
1020− , matchQueryMatchType :: Maybe MatchQueryType
1021− , matchQueryAnalyzer :: Maybe Analyzer
1022− , matchQueryMaxExpansions :: Maybe MaxExpansions
1023− , matchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
1025−{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
1026− enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
1028−mkMatchQuery :: FieldName -> QueryString -> MatchQuery
1029−mkMatchQuery field query = MatchQuery field query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing
1031−data MatchQueryType =
1033− | MatchPhrasePrefix deriving (Eq, Show)
1035−data MultiMatchQuery =
1036− MultiMatchQuery { multiMatchQueryFields :: [FieldName]
1037− , multiMatchQueryString :: QueryString
1038− , multiMatchQueryOperator :: BooleanOperator
1039− , multiMatchQueryZeroTerms :: ZeroTermsQuery
1040− , multiMatchQueryTiebreaker :: Maybe Tiebreaker
1041− , multiMatchQueryType :: Maybe MultiMatchQueryType
1042− , multiMatchQueryCutoffFrequency :: Maybe CutoffFrequency
1043− , multiMatchQueryAnalyzer :: Maybe Analyzer
1044− , multiMatchQueryMaxExpansions :: Maybe MaxExpansions
1045− , multiMatchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
1047−{-| 'mkMultiMatchQuery' is a convenience function that defaults the less common parameters,
1048− enabling you to provide only the list of 'FieldName's and 'QueryString' to
1049− make a 'MultiMatchQuery'.
1052−mkMultiMatchQuery :: [FieldName] -> QueryString -> MultiMatchQuery
1053−mkMultiMatchQuery matchFields query =
1054− MultiMatchQuery matchFields query
1055− Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
1057−data MultiMatchQueryType =
1058− MultiMatchBestFields
1059− | MultiMatchMostFields
1060− | MultiMatchCrossFields
1062− | MultiMatchPhrasePrefix deriving (Eq, Show)
1065− BoolQuery { boolQueryMustMatch :: [Query]
1066− , boolQueryMustNotMatch :: [Query]
1067− , boolQueryShouldMatch :: [Query]
1068− , boolQueryMinimumShouldMatch :: Maybe MinimumMatch
1069− , boolQueryBoost :: Maybe Boost
1070− , boolQueryDisableCoord :: Maybe DisableCoord
1071− } deriving (Eq, Show)
1073−mkBoolQuery :: [Query] -> [Query] -> [Query] -> BoolQuery
1074−mkBoolQuery must mustNot should =
1075− BoolQuery must mustNot should Nothing Nothing Nothing
1077−data BoostingQuery =
1078− BoostingQuery { positiveQuery :: Query
1079− , negativeQuery :: Query
1080− , negativeBoost :: Boost } deriving (Eq, Show)
1082−data CommonTermsQuery =
1083− CommonTermsQuery { commonField :: FieldName
1084− , commonQuery :: QueryString
1085− , commonCutoffFrequency :: CutoffFrequency
1086− , commonLowFreqOperator :: BooleanOperator
1087− , commonHighFreqOperator :: BooleanOperator
1088− , commonMinimumShouldMatch :: Maybe CommonMinimumMatch
1089− , commonBoost :: Maybe Boost
1090− , commonAnalyzer :: Maybe Analyzer
1091− , commonDisableCoord :: Maybe DisableCoord
1092− } deriving (Eq, Show)
1094−data CommonMinimumMatch =
1095− CommonMinimumMatchHighLow MinimumMatchHighLow
1096− | CommonMinimumMatch MinimumMatch
1097 deriving (Eq, Show)
482 deriving (Eq, Show)
1099−data MinimumMatchHighLow =
484+data Source =
1100− MinimumMatchHighLow { lowFreq :: MinimumMatch
485+ NoSource
1101− , highFreq :: MinimumMatch } deriving (Eq, Show)
486+ | SourcePatterns PatternOrPatterns
1102−
487+ | SourceIncludeExclude Include Exclude
1103−data Filter = AndFilter [Filter] Cache
1104− | OrFilter [Filter] Cache
1105− | NotFilter Filter Cache
1107− | BoolFilter BoolMatch
1108− | ExistsFilter FieldName -- always cached
1109− | GeoBoundingBoxFilter GeoBoundingBoxConstraint
1110− | GeoDistanceFilter GeoPoint Distance DistanceType OptimizeBbox Cache
1111− | GeoDistanceRangeFilter GeoPoint DistanceRange
1112− | GeoPolygonFilter FieldName [LatLon]
1113− | IdsFilter MappingName [DocId]
1115− | MissingFilter FieldName Existence NullValue
1116− | PrefixFilter FieldName PrefixValue Cache
1117− | QueryFilter Query Cache
1118− | RangeFilter FieldName RangeValue RangeExecution Cache
1119− | RegexpFilter FieldName Regexp RegexpFlags CacheName Cache CacheKey
1120− | TermFilter Term Cache
1121− deriving (Eq, Show)
1123−data ZeroTermsQuery = ZeroTermsNone
1124− | ZeroTermsAll deriving (Eq, Show)
1126−data RangeExecution = RangeExecutionIndex
1127− | RangeExecutionFielddata deriving (Eq, Show)
1129−newtype Regexp = Regexp Text deriving (Eq, Show)
1131−data RegexpFlags = AllRegexpFlags
1133− | SomeRegexpFlags (NonEmpty RegexpFlag) deriving (Eq, Show)
1135−data RegexpFlag = AnyString
1140− | Interval deriving (Eq, Show)
488+ deriving (Eq, Show)
1142−newtype LessThan = LessThan Double deriving (Eq, Show)
490+instance ToJSON Source where
1143−newtype LessThanEq = LessThanEq Double deriving (Eq, Show)
491+ toJSON NoSource = toJSON False
1144−newtype GreaterThan = GreaterThan Double deriving (Eq, Show)
492+ toJSON (SourcePatterns patterns) = toJSON patterns
1145−newtype GreaterThanEq = GreaterThanEq Double deriving (Eq, Show)
493+ toJSON (SourceIncludeExclude incl excl) = object [ "includes" .= incl, "excludes" .= excl ]
1147−newtype LessThanD = LessThanD UTCTime deriving (Eq, Show)
495+data PatternOrPatterns = PopPattern Pattern
1148−newtype LessThanEqD = LessThanEqD UTCTime deriving (Eq, Show)
496+ | PopPatterns [Pattern] deriving (Eq, Read, Show)
1149−newtype GreaterThanD = GreaterThanD UTCTime deriving (Eq, Show)
1150−newtype GreaterThanEqD = GreaterThanEqD UTCTime deriving (Eq, Show)
1152−data RangeValue = RangeDateLte LessThanEqD
498+instance ToJSON PatternOrPatterns where
1153− | RangeDateLt LessThanD
499+ toJSON (PopPattern pattern) = toJSON pattern
1154− | RangeDateGte GreaterThanEqD
500+ toJSON (PopPatterns patterns) = toJSON patterns
1155− | RangeDateGt GreaterThanD
1156− | RangeDateGtLt GreaterThanD LessThanD
1157− | RangeDateGteLte GreaterThanEqD LessThanEqD
1158− | RangeDateGteLt GreaterThanEqD LessThanD
1159− | RangeDateGtLte GreaterThanD LessThanEqD
1160− | RangeDoubleLte LessThanEq
1161− | RangeDoubleLt LessThan
1162− | RangeDoubleGte GreaterThanEq
1163− | RangeDoubleGt GreaterThan
1164− | RangeDoubleGtLt GreaterThan LessThan
1165− | RangeDoubleGteLte GreaterThanEq LessThanEq
1166− | RangeDoubleGteLt GreaterThanEq LessThan
1167− | RangeDoubleGtLte GreaterThan LessThanEq
1168− deriving (Eq, Show)
1170−rangeValueToPair :: RangeValue -> [Pair]
502+data Include = Include [Pattern] deriving (Eq, Read, Show)
1171−rangeValueToPair rv = case rv of
503+data Exclude = Exclude [Pattern] deriving (Eq, Read, Show)
1172− RangeDateLte (LessThanEqD t) -> ["lte" .= t]
1173− RangeDateGte (GreaterThanEqD t) -> ["gte" .= t]
1174− RangeDateLt (LessThanD t) -> ["lt" .= t]
1175− RangeDateGt (GreaterThanD t) -> ["gt" .= t]
1176− RangeDateGteLte (GreaterThanEqD l) (LessThanEqD g) -> ["gte" .= l, "lte" .= g]
1177− RangeDateGtLte (GreaterThanD l) (LessThanEqD g) -> ["gt" .= l, "lte" .= g]
1178− RangeDateGteLt (GreaterThanEqD l) (LessThanD g) -> ["gte" .= l, "lt" .= g]
1179− RangeDateGtLt (GreaterThanD l) (LessThanD g) -> ["gt" .= l, "lt" .= g]
1180− RangeDoubleLte (LessThanEq t) -> ["lte" .= t]
1181− RangeDoubleGte (GreaterThanEq t) -> ["gte" .= t]
1182− RangeDoubleLt (LessThan t) -> ["lt" .= t]
1183− RangeDoubleGt (GreaterThan t) -> ["gt" .= t]
1184− RangeDoubleGteLte (GreaterThanEq l) (LessThanEq g) -> ["gte" .= l, "lte" .= g]
1185− RangeDoubleGtLte (GreaterThan l) (LessThanEq g) -> ["gt" .= l, "lte" .= g]
1186− RangeDoubleGteLt (GreaterThanEq l) (LessThan g) -> ["gte" .= l, "lt" .= g]
1187− RangeDoubleGtLt (GreaterThan l) (LessThan g) -> ["gt" .= l, "lt" .= g]
1189−data Term = Term { termField :: Text
505+instance ToJSON Include where
1190− , termValue :: Text } deriving (Eq, Show)
506+ toJSON (Include patterns) = toJSON patterns
1192−data BoolMatch = MustMatch Term Cache
508+instance ToJSON Exclude where
1193− | MustNotMatch Term Cache
509+ toJSON (Exclude patterns) = toJSON patterns
1194− | ShouldMatch [Term] Cache deriving (Eq, Show)
1196−-- "memory" or "indexed"
511+newtype Pattern = Pattern Text deriving (Eq, Read, Show)
1197−data GeoFilterType = GeoFilterMemory
1198− | GeoFilterIndexed deriving (Eq, Show)
1200−data LatLon = LatLon { lat :: Double
513+instance ToJSON Pattern where
1201− , lon :: Double } deriving (Eq, Show)
514+ toJSON (Pattern pattern) = toJSON pattern
1203−data GeoBoundingBox =
1204− GeoBoundingBox { topLeft :: LatLon
1205− , bottomRight :: LatLon } deriving (Eq, Show)
1207−data GeoBoundingBoxConstraint =
1208− GeoBoundingBoxConstraint { geoBBField :: FieldName
1209− , constraintBox :: GeoBoundingBox
1210− , bbConstraintcache :: Cache
1211− , geoType :: GeoFilterType
1212− } deriving (Eq, Show)
1215− GeoPoint { geoField :: FieldName
1216− , latLon :: LatLon} deriving (Eq, Show)
1218−data DistanceUnit = Miles
1226− | NauticalMiles deriving (Eq, Show)
1228−data DistanceType = Arc
1229− | SloppyArc -- doesn't exist <1.0
1230− | Plane deriving (Eq, Show)
1232−data OptimizeBbox = OptimizeGeoFilterType GeoFilterType
1233− | NoOptimizeBbox deriving (Eq, Show)
1236− Distance { coefficient :: Double
1237− , unit :: DistanceUnit } deriving (Eq, Show)
1239−data DistanceRange =
1240− DistanceRange { distanceFrom :: Distance
1241− , distanceTo :: Distance } deriving (Eq, Show)
1243data SearchResult a =
516data SearchResult a =
1244 SearchResult { took :: Int
517 SearchResult { took :: Int
1245 , timedOut :: Bool
518 , timedOut :: Bool
1246 , shards :: ShardResult
519 , shards :: ShardResult
1247 , searchHits :: SearchHits a
520 , searchHits :: SearchHits a
1248− , aggregations :: Maybe AggregationResults } deriving (Eq, Show)
521+ , aggregations :: Maybe AggregationResults
1249−
522+ , scrollId :: Maybe ScrollId
1250−type Score = Maybe Double
523+ -- ^ Only one Suggestion request / response per
1251−
524+ -- Search is supported.
1252−data SearchHits a =
525+ , suggest :: Maybe NamedSuggestionResponse
1253− SearchHits { hitsTotal :: Int
526+ }
1254− , maxScore :: Score
527+ deriving (Eq, Show)
1255− , hits :: [Hit a] } deriving (Eq, Show)
1258−instance Monoid (SearchHits a) where
1259− mempty = SearchHits 0 Nothing mempty
1260− mappend (SearchHits ta ma ha) (SearchHits tb mb hb) =
1261− SearchHits (ta + tb) (max ma mb) (ha <> hb)
1265− Hit { hitIndex :: IndexName
1266− , hitType :: MappingName
1267− , hitDocId :: DocId
1268− , hitScore :: Score
1270− , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show)
1273− ShardResult { shardTotal :: Int
1274− , shardsSuccessful :: Int
1275− , shardsFailed :: Int } deriving (Eq, Show, Generic)
1277−type HitHighlight = M.Map Text [Text]
1279−showText :: Show a => a -> Text
1280−showText = T.pack . show
1282−type Aggregations = M.Map Text Aggregation
1284−emptyAggregations :: Aggregations
1285−emptyAggregations = M.empty
1287−mkAggregations :: Text -> Aggregation -> Aggregations
1288−mkAggregations name aggregation = M.insert name aggregation emptyAggregations
1290−data TermOrder = TermOrder{ termSortField :: Text
1291− , termSortOrder :: SortOrder } deriving (Eq, Show)
1293−data TermInclusion = TermInclusion Text
1294− | TermPattern Text Text deriving (Eq, Show)
1296−data CollectionMode = BreadthFirst
1297− | DepthFirst deriving (Eq, Show)
1299−data ExecutionHint = Ordinals
1301− | GlobalOrdinalsHash
1302− | GlobalOrdinalsLowCardinality
1303− | Map deriving (Eq, Show)
1305−data TimeInterval = Weeks
1309− | Seconds deriving (Eq)
1311−data Interval = Year
1319− | FractionalInterval Float TimeInterval deriving (Eq, Show)
1321−data Aggregation = TermsAgg TermsAggregation
1322− | DateHistogramAgg DateHistogramAggregation
1323− | ValueCountAgg ValueCountAggregation
1324− | FilterAgg FilterAggregation deriving (Eq, Show)
1327−data TermsAggregation = TermsAggregation { term :: Either Text Text
1328− , termInclude :: Maybe TermInclusion
1329− , termExclude :: Maybe TermInclusion
1330− , termOrder :: Maybe TermOrder
1331− , termMinDocCount :: Maybe Int
1332− , termSize :: Maybe Int
1333− , termShardSize :: Maybe Int
1334− , termCollectMode :: Maybe CollectionMode
1335− , termExecutionHint :: Maybe ExecutionHint
1336− , termAggs :: Maybe Aggregations
1337− } deriving (Eq, Show)
1339−data DateHistogramAggregation = DateHistogramAggregation { dateField :: FieldName
1340− , dateInterval :: Interval
1341− , dateFormat :: Maybe Text
1342− -- pre and post deprecated in 1.5
1343− , datePreZone :: Maybe Text
1344− , datePostZone :: Maybe Text
1345− , datePreOffset :: Maybe Text
1346− , datePostOffset :: Maybe Text
1347− , dateAggs :: Maybe Aggregations
1348− } deriving (Eq, Show)
1350−-- | See <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html> for more information.
1351−data ValueCountAggregation = FieldValueCount FieldName
1352− | ScriptValueCount Script deriving (Eq, Show)
1354−-- | Single-bucket filter aggregations. See <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html#search-aggregations-bucket-filter-aggregation> for more information.
1355−data FilterAggregation = FilterAggregation { faFilter :: Filter
1356− , faAggs :: Maybe Aggregations} deriving (Eq, Show)
1358−mkTermsAggregation :: Text -> TermsAggregation
1359−mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1361−mkTermsScriptAggregation :: Text -> TermsAggregation
1362−mkTermsScriptAggregation t = TermsAggregation (Right t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1364−mkDateHistogram :: FieldName -> Interval -> DateHistogramAggregation
1365−mkDateHistogram t i = DateHistogramAggregation t i Nothing Nothing Nothing Nothing Nothing Nothing
1367−instance ToJSON TermOrder where
1368− toJSON (TermOrder termSortField termSortOrder) = object [termSortField .= termSortOrder]
1370−instance ToJSON TermInclusion where
1371− toJSON (TermInclusion x) = toJSON x
1372− toJSON (TermPattern pattern flags) = omitNulls [ "pattern" .= pattern,
1375−instance ToJSON CollectionMode where
1376− toJSON BreadthFirst = "breadth_first"
1377− toJSON DepthFirst = "depth_first"
1379−instance ToJSON ExecutionHint where
1380− toJSON Ordinals = "ordinals"
1381− toJSON GlobalOrdinals = "global_ordinals"
1382− toJSON GlobalOrdinalsHash = "global_ordinals_hash"
1383− toJSON GlobalOrdinalsLowCardinality = "global_ordinals_low_cardinality"
1386−instance ToJSON Interval where
1387− toJSON Year = "year"
1388− toJSON Quarter = "quarter"
1389− toJSON Month = "month"
1390− toJSON Week = "week"
1392− toJSON Hour = "hour"
1393− toJSON Minute = "minute"
1394− toJSON Second = "second"
1395− toJSON (FractionalInterval fraction interval) = toJSON $ show fraction ++ show interval
1397−instance Show TimeInterval where
1404−instance ToJSON Aggregation where
1405− toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1406− omitNulls ["terms" .= omitNulls [ toJSON' term,
1407− "include" .= include,
1408− "exclude" .= exclude,
1410− "min_doc_count" .= minDocCount,
1412− "shard_size" .= shardSize,
1413− "collect_mode" .= collectMode,
1414− "execution_hint" .= executionHint
1416− "aggs" .= termAggs ]
1418− toJSON' x = case x of { Left y -> "field" .= y; Right y -> "script" .= y }
1420− toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
1421− omitNulls ["date_histogram" .= omitNulls [ "field" .= field,
1422− "interval" .= interval,
1423− "format" .= format,
1424− "pre_zone" .= preZone,
1425− "post_zone" .= postZone,
1426− "pre_offset" .= preOffset,
1427− "post_offset" .= postOffset
1429− "aggs" .= dateHistoAggs ]
1430− toJSON (ValueCountAgg a) = object ["value_count" .= v]
1431− where v = case a of
1432− (FieldValueCount (FieldName n)) -> object ["field" .= n]
1433− (ScriptValueCount (Script s)) -> object ["script" .= s]
1434− toJSON (FilterAgg (FilterAggregation filt ags)) =
1435− omitNulls [ "filter" .= filt
1438−type AggregationResults = M.Map Text Value
1440−class BucketAggregation a where
1442− docCount :: a -> Int
1443− aggs :: a -> Maybe AggregationResults
1446−data Bucket a = Bucket { buckets :: [a]} deriving (Show)
1448−data TermsResult = TermsResult { termKey :: Text
1449− , termsDocCount :: Int
1450− , termsAggs :: Maybe AggregationResults } deriving (Show)
1452−data DateHistogramResult = DateHistogramResult { dateKey :: Int
1453− , dateKeyStr :: Maybe Text
1454− , dateDocCount :: Int
1455− , dateHistogramAggs :: Maybe AggregationResults } deriving (Show)
1457−toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1458−toTerms t a = M.lookup t a >>= deserialize
1459− where deserialize = parseMaybe parseJSON
1461−toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1462−toDateHistogram t a = M.lookup t a >>= deserialize
1463− where deserialize = parseMaybe parseJSON
1465−instance BucketAggregation TermsResult where
1467− docCount = termsDocCount
1470−instance BucketAggregation DateHistogramResult where
1471− key = showText . dateKey
1472− docCount = dateDocCount
1473− aggs = dateHistogramAggs
1475−instance (FromJSON a, BucketAggregation a) => FromJSON (Bucket a) where
1476− parseJSON (Object v) = Bucket <$>
1478− parseJSON _ = mempty
1480−instance FromJSON TermsResult where
1481− parseJSON (Object v) = TermsResult <$>
1483− v .: "doc_count" <*>
1484− v .:? "aggregations"
1485− parseJSON _ = mempty
1487−instance FromJSON DateHistogramResult where
1488− parseJSON (Object v) = DateHistogramResult <$>
1490− v .:? "key_as_string" <*>
1491− v .: "doc_count" <*>
1492− v .:? "aggregations"
1493− parseJSON _ = mempty
1495−instance Monoid Filter where
1496− mempty = IdentityFilter
1497− mappend a b = AndFilter [a, b] defaultCache
1499−instance Seminearring Filter where
1500− a <||> b = OrFilter [a, b] defaultCache
1502−instance ToJSON Filter where
1503− toJSON (AndFilter filters cache) =
1505− object [ "filters" .= fmap toJSON filters
1506− , "_cache" .= cache]]
1508− toJSON (OrFilter filters cache) =
1510− object [ "filters" .= fmap toJSON filters
1511− , "_cache" .= cache]]
1513− toJSON (NotFilter notFilter cache) =
1515− object ["filter" .= notFilter
1516− , "_cache" .= cache]]
1518− toJSON (IdentityFilter) =
1519− object ["match_all" .= object []]
1521− toJSON (TermFilter (Term termFilterField termFilterValue) cache) =
1522− object ["term" .= object base]
1523− where base = [termFilterField .= termFilterValue,
1526− toJSON (ExistsFilter (FieldName fieldName)) =
1527− object ["exists" .= object
1528− ["field" .= fieldName]]
1530− toJSON (BoolFilter boolMatch) =
1531− object ["bool" .= boolMatch]
1533− toJSON (GeoBoundingBoxFilter bbConstraint) =
1534− object ["geo_bounding_box" .= bbConstraint]
1536− toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1537− distance distanceType optimizeBbox cache) =
1538− object ["geo_distance" .=
1539− object ["distance" .= distance
1540− , "distance_type" .= distanceType
1541− , "optimize_bbox" .= optimizeBbox
1542− , distanceGeoField .= geoDistLatLon
1543− , "_cache" .= cache]]
1545− toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1546− (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1547− object ["geo_distance_range" .=
1548− object ["from" .= geoDistRangeDistFrom
1549− , "to" .= drDistanceTo
1550− , gddrField .= drLatLon]]
1552− toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1553− object ["geo_polygon" .=
1554− object [geoPolygonFilterField .=
1555− object ["points" .= fmap toJSON latLons]]]
1557− toJSON (IdsFilter (MappingName mappingName) values) =
1559− object ["type" .= mappingName
1560− , "values" .= fmap unpackId values]]
1562− toJSON (LimitFilter limit) =
1563− object ["limit" .= object ["value" .= limit]]
1565− toJSON (MissingFilter (FieldName fieldName) (Existence existence) (NullValue nullValue)) =
1566− object ["missing" .=
1567− object ["field" .= fieldName
1568− , "existence" .= existence
1569− , "null_value" .= nullValue]]
1571− toJSON (PrefixFilter (FieldName fieldName) fieldValue cache) =
1572− object ["prefix" .=
1573− object [fieldName .= fieldValue
1574− , "_cache" .= cache]]
1576− toJSON (QueryFilter query False) =
1577− object ["query" .= toJSON query ]
1578− toJSON (QueryFilter query True) =
1579− object ["fquery" .=
1580− object [ "query" .= toJSON query
1581− , "_cache" .= True ]]
1583− toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1585− object [ fieldName .= object (rangeValueToPair rangeValue)
1586− , "execution" .= rangeExecution
1587− , "_cache" .= cache]]
1589− toJSON (RegexpFilter (FieldName fieldName)
1590− (Regexp regexText) flags (CacheName cacheName) cache (CacheKey cacheKey)) =
1591− object ["regexp" .=
1592− object [fieldName .=
1593− object ["value" .= regexText
1594− , "flags" .= flags]
1595− , "_name" .= cacheName
1596− , "_cache" .= cache
1597− , "_cache_key" .= cacheKey]]
1599−instance ToJSON GeoPoint where
1600− toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1601− object [ geoPointField .= geoPointLatLon ]
1604−instance ToJSON Query where
1605− toJSON (TermQuery (Term termQueryField termQueryValue) boost) =
1607− object [termQueryField .= object merged]]
1609− base = [ "value" .= termQueryValue ]
1610− boosted = maybe [] (return . ("boost" .=)) boost
1611− merged = mappend base boosted
1613− toJSON (TermsQuery terms) =
1614− object [ "terms" .= object conjoined ]
1615− where conjoined = [ getTermsField terms .=
1616− fmap (toJSON . getTermValue) (toList terms)]
1617− getTermsField ((Term f _ ) :| _) = f
1618− getTermValue (Term _ v) = v
1619− toJSON (IdsQuery idsQueryMappingName docIds) =
1620− object [ "ids" .= object conjoined ]
1621− where conjoined = [ "type" .= idsQueryMappingName
1622− , "values" .= fmap toJSON docIds ]
1624− toJSON (QueryQueryStringQuery qQueryStringQuery) =
1625− object [ "query_string" .= qQueryStringQuery ]
1627− toJSON (QueryMatchQuery matchQuery) =
1628− object [ "match" .= matchQuery ]
1630− toJSON (QueryMultiMatchQuery multiMatchQuery) =
1631− toJSON multiMatchQuery
1633− toJSON (QueryBoolQuery boolQuery) =
1634− object [ "bool" .= boolQuery ]
1636− toJSON (QueryBoostingQuery boostingQuery) =
1637− object [ "boosting" .= boostingQuery ]
1639− toJSON (QueryCommonTermsQuery commonTermsQuery) =
1640− object [ "common" .= commonTermsQuery ]
1642− toJSON (ConstantScoreFilter csFilter boost) =
1643− object [ "constant_score" .= csFilter
1644− , "boost" .= boost]
1646− toJSON (ConstantScoreQuery query boost) =
1647− object [ "constant_score" .= query
1648− , "boost" .= boost]
1650− toJSON (QueryDisMaxQuery disMaxQuery) =
1651− object [ "dis_max" .= disMaxQuery ]
1653− toJSON (QueryFilteredQuery qFilteredQuery) =
1654− object [ "filtered" .= qFilteredQuery ]
1656− toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1657− object [ "fuzzy_like_this" .= fuzzyQuery ]
1659− toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1660− object [ "fuzzy_like_this_field" .= fuzzyFieldQuery ]
1662− toJSON (QueryFuzzyQuery fuzzyQuery) =
1663− object [ "fuzzy" .= fuzzyQuery ]
1665− toJSON (QueryHasChildQuery childQuery) =
1666− object [ "has_child" .= childQuery ]
1668− toJSON (QueryHasParentQuery parentQuery) =
1669− object [ "has_parent" .= parentQuery ]
1671− toJSON (QueryIndicesQuery qIndicesQuery) =
1672− object [ "indices" .= qIndicesQuery ]
1674− toJSON (MatchAllQuery boost) =
1675− object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1677− toJSON (QueryMoreLikeThisQuery query) =
1678− object [ "more_like_this" .= query ]
1680− toJSON (QueryMoreLikeThisFieldQuery query) =
1681− object [ "more_like_this_field" .= query ]
1683− toJSON (QueryNestedQuery query) =
1684− object [ "nested" .= query ]
1686− toJSON (QueryPrefixQuery query) =
1687− object [ "prefix" .= query ]
1689− toJSON (QueryRangeQuery query) =
1690− object [ "range" .= query ]
1692− toJSON (QueryRegexpQuery query) =
1693− object [ "regexp" .= query ]
1695− toJSON (QuerySimpleQueryStringQuery query) =
1696− object [ "simple_query_string" .= query ]
1699−omitNulls :: [(Text, Value)] -> Value
1700−omitNulls = object . filter notNull where
1701− notNull (_, Null) = False
1702− notNull (_, Array a) = (not . V.null) a
1706−instance ToJSON SimpleQueryStringQuery where
1707− toJSON SimpleQueryStringQuery {..} =
1708− omitNulls (base ++ maybeAdd)
1709− where base = [ "query" .= simpleQueryStringQuery ]
1710− maybeAdd = [ "fields" .= simpleQueryStringField
1711− , "default_operator" .= simpleQueryStringOperator
1712− , "analyzer" .= simpleQueryStringAnalyzer
1713− , "flags" .= simpleQueryStringFlags
1714− , "lowercase_expanded_terms" .= simpleQueryStringLowercaseExpanded
1715− , "locale" .= simpleQueryStringLocale ]
1718−instance ToJSON FieldOrFields where
1719− toJSON (FofField fieldName) =
1721− toJSON (FofFields fieldNames) =
1724−instance ToJSON SimpleQueryFlag where
1725− toJSON SimpleQueryAll = "ALL"
1726− toJSON SimpleQueryNone = "NONE"
1727− toJSON SimpleQueryAnd = "AND"
1728− toJSON SimpleQueryOr = "OR"
1729− toJSON SimpleQueryPrefix = "PREFIX"
1730− toJSON SimpleQueryPhrase = "PHRASE"
1731− toJSON SimpleQueryPrecedence = "PRECEDENCE"
1732− toJSON SimpleQueryEscape = "ESCAPE"
1733− toJSON SimpleQueryWhitespace = "WHITESPACE"
1734− toJSON SimpleQueryFuzzy = "FUZZY"
1735− toJSON SimpleQueryNear = "NEAR"
1736− toJSON SimpleQuerySlop = "SLOP"
1739−instance ToJSON RegexpQuery where
1740− toJSON (RegexpQuery (FieldName rqQueryField)
1741− (Regexp regexpQueryQuery) rqQueryFlags
1743− object [ rqQueryField .= omitNulls base ]
1744− where base = [ "value" .= regexpQueryQuery
1745− , "flags" .= rqQueryFlags
1746− , "boost" .= rqQueryBoost ]
1749−instance ToJSON QueryStringQuery where
1750− toJSON (QueryStringQuery qsQueryString
1751− qsDefaultField qsOperator
1752− qsAnalyzer qsAllowWildcard
1753− qsLowercaseExpanded qsEnablePositionIncrements
1754− qsFuzzyMaxExpansions qsFuzziness
1755− qsFuzzyPrefixLength qsPhraseSlop
1756− qsBoost qsAnalyzeWildcard
1757− qsGeneratePhraseQueries qsMinimumShouldMatch
1758− qsLenient qsLocale) =
1761− base = [ "query" .= qsQueryString
1762− , "default_field" .= qsDefaultField
1763− , "default_operator" .= qsOperator
1764− , "analyzer" .= qsAnalyzer
1765− , "allow_leading_wildcard" .= qsAllowWildcard
1766− , "lowercase_expanded_terms" .= qsLowercaseExpanded
1767− , "enable_position_increments" .= qsEnablePositionIncrements
1768− , "fuzzy_max_expansions" .= qsFuzzyMaxExpansions
1769− , "fuzziness" .= qsFuzziness
1770− , "fuzzy_prefix_length" .= qsFuzzyPrefixLength
1771− , "phrase_slop" .= qsPhraseSlop
1772− , "boost" .= qsBoost
1773− , "analyze_wildcard" .= qsAnalyzeWildcard
1774− , "auto_generate_phrase_queries" .= qsGeneratePhraseQueries
1775− , "minimum_should_match" .= qsMinimumShouldMatch
1776− , "lenient" .= qsLenient
1777− , "locale" .= qsLocale ]
1780−instance ToJSON RangeQuery where
1781− toJSON (RangeQuery (FieldName fieldName) range boost) =
1782− object [ fieldName .= conjoined ]
1783− where conjoined = [ "boost" .= boost ] ++ (rangeValueToPair range)
1786−instance ToJSON PrefixQuery where
1787− toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1788− object [ fieldName .= omitNulls base ]
1789− where base = [ "value" .= queryValue
1790− , "boost" .= boost ]
1793−instance ToJSON NestedQuery where
1794− toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1795− object [ "path" .= nqPath
1796− , "score_mode" .= nqScoreType
1797− , "query" .= nqQuery ]
1800−instance ToJSON MoreLikeThisFieldQuery where
1801− toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
1802− percent mtf mqt stopwords mindf maxdf
1803− minwl maxwl boostTerms boost analyzer) =
1804− object [ fieldName .= omitNulls base ]
1805− where base = [ "like_text" .= text
1806− , "percent_terms_to_match" .= percent
1807− , "min_term_freq" .= mtf
1808− , "max_query_terms" .= mqt
1809− , "stop_words" .= stopwords
1810− , "min_doc_freq" .= mindf
1811− , "max_doc_freq" .= maxdf
1812− , "min_word_length" .= minwl
1813− , "max_word_length" .= maxwl
1814− , "boost_terms" .= boostTerms
1816− , "analyzer" .= analyzer ]
1819−instance ToJSON MoreLikeThisQuery where
1820− toJSON (MoreLikeThisQuery text fields percent
1821− mtf mqt stopwords mindf maxdf
1822− minwl maxwl boostTerms boost analyzer) =
1824− where base = [ "like_text" .= text
1825− , "fields" .= fields
1826− , "percent_terms_to_match" .= percent
1827− , "min_term_freq" .= mtf
1828− , "max_query_terms" .= mqt
1829− , "stop_words" .= stopwords
1830− , "min_doc_freq" .= mindf
1831− , "max_doc_freq" .= maxdf
1832− , "min_word_length" .= minwl
1833− , "max_word_length" .= maxwl
1834− , "boost_terms" .= boostTerms
1836− , "analyzer" .= analyzer ]
1839−instance ToJSON IndicesQuery where
1840− toJSON (IndicesQuery indices query noMatch) =
1841− omitNulls [ "indices" .= indices
1842− , "no_match_query" .= noMatch
1843− , "query" .= query ]
1846−instance ToJSON HasParentQuery where
1847− toJSON (HasParentQuery queryType query scoreType) =
1848− omitNulls [ "parent_type" .= queryType
1849− , "score_type" .= scoreType
1850− , "query" .= query ]
1853−instance ToJSON HasChildQuery where
1854− toJSON (HasChildQuery queryType query scoreType) =
1855− omitNulls [ "query" .= query
1856− , "score_type" .= scoreType
1857− , "type" .= queryType ]
1860−instance ToJSON FuzzyQuery where
1861− toJSON (FuzzyQuery (FieldName fieldName) queryText
1862− prefixLength maxEx fuzziness boost) =
1863− object [ fieldName .= omitNulls base ]
1864− where base = [ "value" .= queryText
1865− , "fuzziness" .= fuzziness
1866− , "prefix_length" .= prefixLength
1868− , "max_expansions" .= maxEx ]
1871−instance ToJSON FuzzyLikeFieldQuery where
1872− toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
1873− fieldText maxTerms ignoreFreq fuzziness prefixLength
1875− object [ fieldName .=
1876− omitNulls [ "like_text" .= fieldText
1877− , "max_query_terms" .= maxTerms
1878− , "ignore_tf" .= ignoreFreq
1879− , "fuzziness" .= fuzziness
1880− , "prefix_length" .= prefixLength
1881− , "analyzer" .= analyzer
1882− , "boost" .= boost ]]
1885−instance ToJSON FuzzyLikeThisQuery where
1886− toJSON (FuzzyLikeThisQuery fields text maxTerms
1887− ignoreFreq fuzziness prefixLength boost analyzer) =
1889− where base = [ "fields" .= fields
1890− , "like_text" .= text
1891− , "max_query_terms" .= maxTerms
1892− , "ignore_tf" .= ignoreFreq
1893− , "fuzziness" .= fuzziness
1894− , "prefix_length" .= prefixLength
1895− , "analyzer" .= analyzer
1896− , "boost" .= boost ]
1899−instance ToJSON FilteredQuery where
1900− toJSON (FilteredQuery query fFilter) =
1901− object [ "query" .= query
1902− , "filter" .= fFilter ]
1905−instance ToJSON DisMaxQuery where
1906− toJSON (DisMaxQuery queries tiebreaker boost) =
1908− where base = [ "queries" .= queries
1910− , "tie_breaker" .= tiebreaker ]
1913−instance ToJSON CommonTermsQuery where
1914− toJSON (CommonTermsQuery (FieldName fieldName)
1915− (QueryString query) cf lfo hfo msm
1916− boost analyzer disableCoord) =
1917− object [fieldName .= omitNulls base ]
1918− where base = [ "query" .= query
1919− , "cutoff_frequency" .= cf
1920− , "low_freq_operator" .= lfo
1921− , "minimum_should_match" .= msm
1923− , "analyzer" .= analyzer
1924− , "disable_coord" .= disableCoord
1925− , "high_freq_operator" .= hfo ]
1928−instance ToJSON CommonMinimumMatch where
1929− toJSON (CommonMinimumMatch mm) = toJSON mm
1930− toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1931− object [ "low_freq" .= lowF
1932− , "high_freq" .= highF ]
1934−instance ToJSON BoostingQuery where
1935− toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1936− object [ "positive" .= bqPositiveQuery
1937− , "negative" .= bqNegativeQuery
1938− , "negative_boost" .= bqNegativeBoost ]
1941−instance ToJSON BoolQuery where
1942− toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1944− where base = [ "must" .= mustM
1945− , "must_not" .= notM
1946− , "should" .= shouldM
1947− , "minimum_should_match" .= bqMin
1949− , "disable_coord" .= disableCoord ]
1952−instance ToJSON MatchQuery where
1953− toJSON (MatchQuery (FieldName fieldName)
1954− (QueryString mqQueryString) booleanOperator
1955− zeroTermsQuery cutoffFrequency matchQueryType
1956− analyzer maxExpansions lenient) =
1957− object [ fieldName .= omitNulls base ]
1958− where base = [ "query" .= mqQueryString
1959− , "operator" .= booleanOperator
1960− , "zero_terms_query" .= zeroTermsQuery
1961− , "cutoff_frequency" .= cutoffFrequency
1962− , "type" .= matchQueryType
1963− , "analyzer" .= analyzer
1964− , "max_expansions" .= maxExpansions
1965− , "lenient" .= lenient ]
1968−instance ToJSON MultiMatchQuery where
1969− toJSON (MultiMatchQuery fields (QueryString query) boolOp
1970− ztQ tb mmqt cf analyzer maxEx lenient) =
1971− object ["multi_match" .= omitNulls base]
1972− where base = [ "fields" .= fmap toJSON fields
1974− , "operator" .= boolOp
1975− , "zero_terms_query" .= ztQ
1976− , "tiebreaker" .= tb
1978− , "cutoff_frequency" .= cf
1979− , "analyzer" .= analyzer
1980− , "max_expansions" .= maxEx
1981− , "lenient" .= lenient ]
1984−instance ToJSON MultiMatchQueryType where
1985− toJSON MultiMatchBestFields = "best_fields"
1986− toJSON MultiMatchMostFields = "most_fields"
1987− toJSON MultiMatchCrossFields = "cross_fields"
1988− toJSON MultiMatchPhrase = "phrase"
1989− toJSON MultiMatchPhrasePrefix = "phrase_prefix"
1991−instance ToJSON BooleanOperator where
1992− toJSON And = String "and"
1993− toJSON Or = String "or"
1995−instance ToJSON ZeroTermsQuery where
1996− toJSON ZeroTermsNone = String "none"
1997− toJSON ZeroTermsAll = String "all"
1999−instance ToJSON MatchQueryType where
2000− toJSON MatchPhrase = "phrase"
2001− toJSON MatchPhrasePrefix = "phrase_prefix"
2003−instance ToJSON FieldName where
2004− toJSON (FieldName fieldName) = String fieldName
2006−instance ToJSON ReplicaCount
2007−instance ToJSON ShardCount
2008−instance ToJSON CutoffFrequency
2009−instance ToJSON Analyzer
2010−instance ToJSON MaxExpansions
2011−instance ToJSON Lenient
2012−instance ToJSON Boost
2013−instance ToJSON Version
2014−instance ToJSON Tiebreaker
2015−instance ToJSON MinimumMatch
2016−instance ToJSON DisableCoord
2017−instance ToJSON PrefixLength
2018−instance ToJSON Fuzziness
2019−instance ToJSON IgnoreTermFrequency
2020−instance ToJSON MaxQueryTerms
2021−instance ToJSON TypeName
2022−instance ToJSON IndexName
2023−instance ToJSON TemplateName
2024−instance ToJSON TemplatePattern
2025−instance ToJSON BoostTerms
2026−instance ToJSON MaxWordLength
2027−instance ToJSON MinWordLength
2028−instance ToJSON MaxDocFrequency
2029−instance ToJSON MinDocFrequency
2030−instance ToJSON PhraseSlop
2031−instance ToJSON StopWord
2032−instance ToJSON QueryPath
2033−instance ToJSON MinimumTermFrequency
2034−instance ToJSON PercentMatch
2035−instance ToJSON MappingName
2036−instance ToJSON DocId
2037−instance ToJSON QueryString
2038−instance ToJSON AllowLeadingWildcard
2039−instance ToJSON LowercaseExpanded
2040−instance ToJSON AnalyzeWildcard
2041−instance ToJSON GeneratePhraseQueries
2042−instance ToJSON Locale
2043−instance ToJSON EnablePositionIncrements
2044−instance FromJSON Version
2045−instance FromJSON IndexName
2046−instance FromJSON MappingName
2047−instance FromJSON DocId
2050−instance FromJSON Status where
2051− parseJSON (Object v) = Status <$>
2057− parseJSON _ = empty
2060−instance ToJSON IndexSettings where
2061− toJSON (IndexSettings s r) = object ["settings" .=
2063− object ["number_of_shards" .= s, "number_of_replicas" .= r]
2067−instance ToJSON IndexTemplate where
2068− toJSON (IndexTemplate p s m) = merge
2069− (object [ "template" .= p
2070− , "mappings" .= foldl' merge (object []) m
2074− merge (Object o1) (Object o2) = toJSON $ HM.union o1 o2
2076− merge _ _ = undefined
2078−instance (FromJSON a) => FromJSON (EsResult a) where
2079− parseJSON jsonVal@(Object v) = do
2080− found <- v .:? "found" .!= False
2082− then parseJSON jsonVal
2083− else return Nothing
2084− EsResult <$> v .: "_index" <*>
2088− parseJSON _ = empty
2090−instance (FromJSON a) => FromJSON (EsResultFound a) where
2091− parseJSON (Object v) = EsResultFound <$>
2092− v .: "_version" <*>
2094− parseJSON _ = empty
2096−instance ToJSON Search where
2097− toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize sFields) =
2098− omitNulls [ "query" .= query
2099− , "filter" .= sFilter
2101− , "aggregations" .= searchAggs
2102− , "highlight" .= highlight
2105− , "track_scores" .= sTrackSortScores
2106− , "fields" .= sFields]
2109−instance ToJSON FieldHighlight where
2110− toJSON (FieldHighlight (FieldName fName) (Just fSettings)) =
2111− object [ fName .= fSettings ]
2112− toJSON (FieldHighlight (FieldName fName) Nothing) =
2113− object [ fName .= emptyObject ]
2115−instance ToJSON Highlights where
2116− toJSON (Highlights global fields) =
2117− omitNulls (("fields" .= fields)
2118− : highlightSettingsPairs global)
2120−instance ToJSON HighlightSettings where
2121− toJSON hs = omitNulls (highlightSettingsPairs (Just hs))
2123−highlightSettingsPairs :: Maybe HighlightSettings -> [Pair]
2124−highlightSettingsPairs Nothing = []
2125−highlightSettingsPairs (Just (Plain plh)) = plainHighPairs (Just plh)
2126−highlightSettingsPairs (Just (Postings ph)) = postHighPairs (Just ph)
2127−highlightSettingsPairs (Just (FastVector fvh)) = fastVectorHighPairs (Just fvh)
2130−plainHighPairs :: Maybe PlainHighlight -> [Pair]
2131−plainHighPairs Nothing = []
2132−plainHighPairs (Just (PlainHighlight plCom plNonPost)) =
2133− [ "type" .= String "plain"]
2134− ++ commonHighlightPairs plCom
2135− ++ nonPostingsToPairs plNonPost
2137−postHighPairs :: Maybe PostingsHighlight -> [Pair]
2138−postHighPairs Nothing = []
2139−postHighPairs (Just (PostingsHighlight pCom)) =
2140− ("type" .= String "postings")
2141− : commonHighlightPairs pCom
2143−fastVectorHighPairs :: Maybe FastVectorHighlight -> [Pair]
2144−fastVectorHighPairs Nothing = []
2145−fastVectorHighPairs (Just
2146− (FastVectorHighlight fvCom fvNonPostSettings fvBoundChars
2147− fvBoundMaxScan fvFragOff fvMatchedFields
2149− [ "type" .= String "fvh"
2150− , "boundary_chars" .= fvBoundChars
2151− , "boundary_max_scan" .= fvBoundMaxScan
2152− , "fragment_offset" .= fvFragOff
2153− , "matched_fields" .= fvMatchedFields
2154− , "phraseLimit" .= fvPhraseLim]
2155− ++ commonHighlightPairs fvCom
2156− ++ nonPostingsToPairs fvNonPostSettings
2158−commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
2159−commonHighlightPairs Nothing = []
2160−commonHighlightPairs (Just (CommonHighlight chScore chForceSource chTag chEncoder
2161− chNoMatchSize chHighlightQuery
2162− chRequireFieldMatch)) =
2163− [ "order" .= chScore
2164− , "force_source" .= chForceSource
2165− , "encoder" .= chEncoder
2166− , "no_match_size" .= chNoMatchSize
2167− , "highlight_query" .= chHighlightQuery
2168− , "require_fieldMatch" .= chRequireFieldMatch]
2169− ++ highlightTagToPairs chTag
2172−nonPostingsToPairs :: Maybe NonPostings -> [Pair]
2173−nonPostingsToPairs Nothing = []
2174−nonPostingsToPairs (Just (NonPostings npFragSize npNumOfFrags)) =
2175− [ "fragment_size" .= npFragSize
2176− , "number_of_fragments" .= npNumOfFrags]
2180−instance ToJSON HighlightEncoder where
2181− toJSON DefaultEncoder = String "default"
2182− toJSON HTMLEncoder = String "html"
2184−highlightTagToPairs :: Maybe HighlightTag -> [Pair]
2185−highlightTagToPairs (Just (TagSchema _)) = [ "scheme" .= String "default"]
2186−highlightTagToPairs (Just (CustomTags (pre, post))) = [ "pre_tags" .= pre
2187− , "post_tags" .= post]
2188−highlightTagToPairs Nothing = []
2190−instance ToJSON SortSpec where
2191− toJSON (DefaultSortSpec
2192− (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
2193− dsSortMode dsMissingSort dsNestedFilter)) =
2194− object [dsSortFieldName .= omitNulls base] where
2195− base = [ "order" .= dsSortOrder
2196− , "ignore_unmapped" .= dsIgnoreUnmapped
2197− , "mode" .= dsSortMode
2198− , "missing" .= dsMissingSort
2199− , "nested_filter" .= dsNestedFilter ]
2201− toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
2202− object [ "unit" .= units
2203− , field .= gdsLatLon
2204− , "order" .= gdsSortOrder ]
2207−instance ToJSON SortOrder where
2208− toJSON Ascending = String "asc"
2209− toJSON Descending = String "desc"
2212−instance ToJSON SortMode where
2213− toJSON SortMin = String "min"
2214− toJSON SortMax = String "max"
2215− toJSON SortSum = String "sum"
2216− toJSON SortAvg = String "avg"
2219−instance ToJSON Missing where
2220− toJSON LastMissing = String "_last"
2221− toJSON FirstMissing = String "_first"
2222− toJSON (CustomMissing txt) = String txt
2225−instance ToJSON ScoreType where
2226− toJSON ScoreTypeMax = "max"
2227− toJSON ScoreTypeAvg = "avg"
2228− toJSON ScoreTypeSum = "sum"
2229− toJSON ScoreTypeNone = "none"
2232−instance ToJSON Distance where
2233− toJSON (Distance dCoefficient dUnit) =
2234− String boltedTogether where
2235− coefText = showText dCoefficient
2236− (String unitText) = toJSON dUnit
2237− boltedTogether = mappend coefText unitText
2240−instance ToJSON DistanceUnit where
2241− toJSON Miles = String "mi"
2242− toJSON Yards = String "yd"
2243− toJSON Feet = String "ft"
2244− toJSON Inches = String "in"
2245− toJSON Kilometers = String "km"
2246− toJSON Meters = String "m"
2247− toJSON Centimeters = String "cm"
2248− toJSON Millimeters = String "mm"
2249− toJSON NauticalMiles = String "nmi"
2252−instance ToJSON DistanceType where
2253− toJSON Arc = String "arc"
2254− toJSON SloppyArc = String "sloppy_arc"
2255− toJSON Plane = String "plane"
2258−instance ToJSON OptimizeBbox where
2259− toJSON NoOptimizeBbox = String "none"
2260− toJSON (OptimizeGeoFilterType gft) = toJSON gft
2263−instance ToJSON GeoBoundingBoxConstraint where
2264− toJSON (GeoBoundingBoxConstraint
2265− (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2266− object [gbbcGeoBBField .= gbbcConstraintBox
2267− , "_cache" .= cache
2271−instance ToJSON GeoFilterType where
2272− toJSON GeoFilterMemory = String "memory"
2273− toJSON GeoFilterIndexed = String "indexed"
2276−instance ToJSON GeoBoundingBox where
2277− toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2278− object ["top_left" .= gbbTopLeft
2279− , "bottom_right" .= gbbBottomRight]
2282−instance ToJSON LatLon where
2283− toJSON (LatLon lLat lLon) =
2284− object ["lat" .= lLat
2288−-- index for smaller ranges, fielddata for longer ranges
2289−instance ToJSON RangeExecution where
2290− toJSON RangeExecutionIndex = "index"
2291− toJSON RangeExecutionFielddata = "fielddata"
2294−instance ToJSON RegexpFlags where
2295− toJSON AllRegexpFlags = String "ALL"
2296− toJSON NoRegexpFlags = String "NONE"
2297− toJSON (SomeRegexpFlags (h :| fs)) = String $ T.intercalate "|" flagStrs
2298− where flagStrs = map flagStr . nub $ h:fs
2299− flagStr AnyString = "ANYSTRING"
2300− flagStr Automaton = "AUTOMATON"
2301− flagStr Complement = "COMPLEMENT"
2302− flagStr Empty = "EMPTY"
2303− flagStr Intersection = "INTERSECTION"
2304− flagStr Interval = "INTERVAL"
2306−instance ToJSON Term where
2307− toJSON (Term field value) = object ["term" .= object
2311−instance ToJSON BoolMatch where
2312− toJSON (MustMatch term cache) = object ["must" .= term,
2314− toJSON (MustNotMatch term cache) = object ["must_not" .= term,
2316− toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2320instance (FromJSON a) => FromJSON (SearchResult a) where
529instance (FromJSON a) => FromJSON (SearchResult a) where
2321 parseJSON (Object v) = SearchResult <$>
530 parseJSON (Object v) = SearchResult <$>
@@ -2323,52 +532,11 @@ instance (FromJSON a) => FromJSON (SearchResult a) where
2323 v .: "timed_out" <*>
532 v .: "timed_out" <*>
2324 v .: "_shards" <*>
533 v .: "_shards" <*>
2325 v .: "hits" <*>
534 v .: "hits" <*>
2326− v .:? "aggregations"
535+ v .:? "aggregations" <*>
2327− parseJSON _ = empty
536+ v .:? "_scroll_id" <*>
2328−
537+ v .:? "suggest"
2329−instance (FromJSON a) => FromJSON (SearchHits a) where
2330− parseJSON (Object v) = SearchHits <$>
2332− v .: "max_score" <*>
2334− parseJSON _ = empty
2336−instance (FromJSON a) => FromJSON (Hit a) where
2337− parseJSON (Object v) = Hit <$>
2344− parseJSON _ = empty
2346−instance FromJSON ShardResult where
2347− parseJSON (Object v) = ShardResult <$>
2349− v .: "successful" <*>
2351 parseJSON _ = empty
538 parseJSON _ = empty
2353−
540+newtype ScrollId =
2354−instance FromJSON DocVersion where
541+ ScrollId Text
2355− parseJSON v = do
542+ deriving (Eq, Show, Ord, ToJSON, FromJSON)
2357− maybe (fail "DocVersion out of range") return $ mkDocVersion i
2359−instance Bounded DocVersion where
2360− minBound = DocVersion 1
2361− maxBound = DocVersion 9200000000000000000 -- 9.2e+18
2363−instance Enum DocVersion where
2365− | x /= maxBound = DocVersion (succ $ docVersionNumber x)
2366− | otherwise = succError "DocVersion"
2368− | x /= minBound = DocVersion (pred $ docVersionNumber x)
2369− | otherwise = predError "DocVersion"
2371− fromMaybe (error $ show i ++ " out of DocVersion range") $ mkDocVersion i
2372− fromEnum = docVersionNumber
2373− enumFrom = boundedEnumFrom
2374− enumFromThen = boundedEnumFromThen