@@ -1,8 +1,8 @@
1−{-# LANGUAGE DeriveGeneric #-}
21{-# LANGUAGE FlexibleContexts #-}
32{-# LANGUAGE FlexibleInstances #-}
43{-# LANGUAGE GeneralizedNewtypeDeriving #-}
54{-# LANGUAGE MultiParamTypeClasses #-}
5+{-# LANGUAGE NamedFieldPuns #-}
66{-# LANGUAGE OverloadedStrings #-}
77{-# LANGUAGE RecordWildCards #-}
88{-# LANGUAGE UndecidableInstances #-}
@@ -10,11 +10,11 @@
1010-------------------------------------------------------------------------------
1111-- |
1212-- Module : Database.Bloodhound.Types
13−-- Copyright : (C) 2014 Chris Allen
13+-- Copyright : (C) 2014, 2018 Chris Allen
1414-- License : BSD-style (see the file LICENSE)
1515-- Maintainer : Chris Allen <cma@bitemyapp.com
1616-- Stability : provisional
17−-- Portability : DeriveGeneric, RecordWildCards
17+-- Portability : RecordWildCards
1818--
1919-- Data types for describing actions and data structures performed to interact
2020-- with Elasticsearch. The two main buckets your queries against Elasticsearch
@@ -42,16 +42,28 @@ module Database.Bloodhound.Types
4242 , mkTermsAggregation
4343 , mkTermsScriptAggregation
4444 , mkDateHistogram
45+ , mkCardinalityAggregation
4546 , mkDocVersion
47+ , mkStatsAggregation
48+ , mkExtendedStatsAggregation
4649 , docVersionNumber
50+ , toMissing
4751 , toTerms
4852 , toDateHistogram
53+ , toTopHits
4954 , omitNulls
5055 , BH(..)
5156 , runBH
52− , BHEnv(..)
57+ , BHEnv
58+ , bhServer
59+ , bhManager
60+ , bhRequestHook
61+ , mkBHEnv
5362 , MonadBH(..)
5463 , Version(..)
64+ , VersionNumber(..)
65+ , MaybeNA(..)
66+ , BuildHash(..)
5567 , Status(..)
5668 , Existence(..)
5769 , NullValue(..)
@@ -59,8 +71,12 @@ module Database.Bloodhound.Types
5971 , UpdatableIndexSetting(..)
6072 , IndexSettingsSummary(..)
6173 , AllocationPolicy(..)
74+ , Compression(..)
6275 , ReplicaBounds(..)
6376 , Bytes(..)
77+ , gigabytes
78+ , megabytes
79+ , kilobytes
6480 , FSType(..)
6581 , InitialShardCount(..)
6682 , NodeAttrFilter(..)
@@ -72,6 +88,17 @@ module Database.Bloodhound.Types
7288 , EsResult(..)
7389 , EsResultFound(..)
7490 , EsError(..)
91+ , EsProtocolException(..)
92+ , IndexAlias(..)
93+ , IndexAliasName(..)
94+ , IndexAliasAction(..)
95+ , IndexAliasCreate(..)
96+ , IndexAliasSummary(..)
97+ , IndexAliasesSummary(..)
98+ , AliasRouting(..)
99+ , SearchAliasRouting(..)
100+ , IndexAliasRouting(..)
101+ , RoutingValue(..)
75102 , DocVersion
76103 , ExternalDocVersion(..)
77104 , VersionControl(..)
@@ -81,7 +108,7 @@ module Database.Bloodhound.Types
81108 , Search(..)
82109 , SearchType(..)
83110 , SearchResult(..)
84− , ScrollId
111+ , ScrollId(..)
85112 , SearchHits(..)
86113 , TrackSortScores
87114 , From(..)
@@ -93,8 +120,8 @@ module Database.Bloodhound.Types
93120 , Pattern(..)
94121 , ShardResult(..)
95122 , Hit(..)
123+ , HitFields(..)
96124 , Filter(..)
97− , Seminearring(..)
98125 , BoolMatch(..)
99126 , Term(..)
100127 , GeoPoint(..)
@@ -121,8 +148,22 @@ module Database.Bloodhound.Types
121148 , RegexpFlags(..)
122149 , RegexpFlag(..)
123150 , FieldName(..)
151+ , ScriptFields(..)
152+ , ScriptFieldName
153+ , ScriptFieldValue
124154 , Script(..)
155+ , ScriptLanguage(..)
156+ , ScriptInline(..)
157+ , ScriptId(..)
158+ , ScriptParams(..)
159+ , ScriptParamName
160+ , ScriptParamValue
125161 , IndexName(..)
162+ , IndexSelection(..)
163+ , NodeSelection(..)
164+ , NodeSelector(..)
165+ , ForceMergeIndexSettings(..)
166+ , defaultForceMergeIndexSettings
126167 , TemplateName(..)
127168 , TemplatePattern(..)
128169 , MappingName(..)
@@ -146,8 +187,19 @@ module Database.Bloodhound.Types
146187 , BoolQuery(..)
147188 , BoostingQuery(..)
148189 , CommonTermsQuery(..)
190+ , FunctionScoreQuery(..)
191+ , BoostMode(..)
192+ , ScoreMode(..)
193+ , FunctionScoreFunctions(..)
194+ , ComponentFunctionScoreFunction(..)
195+ , FunctionScoreFunction(..)
196+ , Weight(..)
197+ , Seed(..)
198+ , FieldValueFactor(..)
199+ , Factor(..)
200+ , FactorModifier(..)
201+ , FactorMissingFieldValue(..)
149202 , DisMaxQuery(..)
150− , FilteredQuery(..)
151203 , FuzzyLikeThisQuery(..)
152204 , FuzzyLikeFieldQuery(..)
153205 , FuzzyQuery(..)
@@ -163,10 +215,16 @@ module Database.Bloodhound.Types
163215 , RangeQuery(..)
164216 , RegexpQuery(..)
165217 , QueryString(..)
218+ , TemplateQueryInline(..)
219+ , TemplateQueryKeyValuePairs(..)
220+ , WildcardQuery(..)
166221 , BooleanOperator(..)
167222 , ZeroTermsQuery(..)
168223 , CutoffFrequency(..)
169224 , Analyzer(..)
225+ , Tokenizer(..)
226+ , TokenFilter(..)
227+ , CharFilter(..)
170228 , MaxExpansions(..)
171229 , Lenient(..)
172230 , MatchQueryType(..)
@@ -213,16 +271,118 @@ module Database.Bloodhound.Types
213271 , CollectionMode(..)
214272 , TermOrder(..)
215273 , TermInclusion(..)
274+ , SnapshotRepoSelection(..)
275+ , GenericSnapshotRepo(..)
276+ , SnapshotRepo(..)
277+ , SnapshotRepoConversionError(..)
278+ , SnapshotRepoType(..)
279+ , GenericSnapshotRepoSettings(..)
280+ , SnapshotRepoUpdateSettings(..)
281+ , defaultSnapshotRepoUpdateSettings
282+ , SnapshotRepoName(..)
283+ , SnapshotRepoPattern(..)
284+ , SnapshotVerification(..)
285+ , SnapshotNodeVerification(..)
286+ , FullNodeId(..)
287+ , NodeName(..)
288+ , ClusterName(..)
289+ , NodesInfo(..)
290+ , NodesStats(..)
291+ , NodeStats(..)
292+ , NodeBreakersStats(..)
293+ , NodeBreakerStats(..)
294+ , NodeHTTPStats(..)
295+ , NodeTransportStats(..)
296+ , NodeFSStats(..)
297+ , NodeDataPathStats(..)
298+ , NodeFSTotalStats(..)
299+ , NodeNetworkStats(..)
300+ , NodeThreadPoolsStats(..)
301+ , NodeThreadPoolStats(..)
302+ , NodeJVMStats(..)
303+ , JVMBufferPoolStats(..)
304+ , JVMGCStats(..)
305+ , JVMPoolStats(..)
306+ , NodeProcessStats(..)
307+ , NodeOSStats(..)
308+ , LoadAvgs(..)
309+ , NodeIndicesStats(..)
310+ , EsAddress(..)
311+ , PluginName(..)
312+ , NodeInfo(..)
313+ , NodePluginInfo(..)
314+ , NodeHTTPInfo(..)
315+ , NodeTransportInfo(..)
316+ , BoundTransportAddress(..)
317+ , NodeNetworkInfo(..)
318+ , MacAddress(..)
319+ , NetworkInterfaceName(..)
320+ , NodeNetworkInterface(..)
321+ , NodeThreadPoolsInfo(..)
322+ , NodeThreadPoolInfo(..)
323+ , ThreadPoolSize(..)
324+ , ThreadPoolType(..)
325+ , NodeJVMInfo(..)
326+ , JVMMemoryPool(..)
327+ , JVMGCCollector(..)
328+ , JVMMemoryInfo(..)
329+ , PID(..)
330+ , NodeOSInfo(..)
331+ , CPUInfo(..)
332+ , NodeProcessInfo(..)
333+ , FsSnapshotRepo(..)
334+ , SnapshotCreateSettings(..)
335+ , defaultSnapshotCreateSettings
336+ , SnapshotSelection(..)
337+ , SnapshotPattern(..)
338+ , SnapshotInfo(..)
339+ , SnapshotShardFailure(..)
340+ , ShardId(..)
341+ , SnapshotName(..)
342+ , SnapshotState(..)
343+ , SnapshotRestoreSettings(..)
344+ , defaultSnapshotRestoreSettings
345+ , RestoreRenamePattern(..)
346+ , RestoreRenameToken(..)
347+ , RRGroupRefNum
348+ , rrGroupRefNum
349+ , mkRRGroupRefNum
350+ , RestoreIndexSettings(..)
351+ , Suggest(..)
352+ , SuggestType(..)
353+ , PhraseSuggester(..)
354+ , PhraseSuggesterHighlighter(..)
355+ , PhraseSuggesterCollate(..)
356+ , mkPhraseSuggester
357+ , SuggestOptions(..)
358+ , SuggestResponse(..)
359+ , NamedSuggestionResponse(..)
360+ , DirectGenerators(..)
361+ , mkDirectGenerators
362+ , DirectGeneratorSuggestModeTypes (..)
216363
217364 , Aggregation(..)
218365 , Aggregations
219366 , AggregationResults
367+ , BucketValue(..)
220368 , Bucket(..)
221369 , BucketAggregation(..)
222370 , TermsAggregation(..)
371+ , MissingAggregation(..)
223372 , ValueCountAggregation(..)
224373 , FilterAggregation(..)
374+ , CardinalityAggregation(..)
375+ , MaxAggregation(..)
225376 , DateHistogramAggregation(..)
377+ , DateRangeAggregation(..)
378+ , DateRangeAggRange(..)
379+ , DateMathExpr(..)
380+ , DateMathAnchor(..)
381+ , DateMathModifier(..)
382+ , DateMathUnit(..)
383+ , TopHitsAggregation(..)
384+ , StatisticsAggregation(..)
385+ , SearchAfterKey
226386
227387 , Highlights(..)
228388 , FieldHighlight(..)
@@ -236,608 +396,36 @@ module Database.Bloodhound.Types
236396 , HighlightTag(..)
237397 , HitHighlight
238398
399+ , MissingResult(..)
239400 , TermsResult(..)
240401 , DateHistogramResult(..)
241− ) where
242−
243−import Control.Applicative
244−import Control.Monad.Catch
245−import Control.Monad.Except
246−import Control.Monad.Reader
247−import Control.Monad.State
248−import Control.Monad.Writer
249−import Data.Aeson
250−import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
251−import qualified Data.ByteString.Lazy.Char8 as L
252−import qualified Data.HashMap.Strict as HM (union)
253−import Data.List (foldl', nub)
254−import Data.List.NonEmpty (NonEmpty (..), toList)
255−import qualified Data.Map.Strict as M
256−import Data.Maybe
257−import Data.Text (Text)
258−import qualified Data.Text as T
259−import Data.Time.Clock (UTCTime, NominalDiffTime)
260−import qualified Data.Vector as V
261−import GHC.Enum
262−import GHC.Generics (Generic)
263−import Network.HTTP.Client
264−import qualified Network.HTTP.Types.Method as NHTM
265−
266−import Database.Bloodhound.Types.Class
267−
268−-- $setup
269−-- >>> :set -XOverloadedStrings
270−-- >>> import Database.Bloodhound
271−-- >>> let testServer = (Server "http://localhost:9200")
272−-- >>> let testIndex = IndexName "twitter"
273−-- >>> let testMapping = MappingName "tweet"
274−-- >>> let defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
275−
276−-- defaultIndexSettings is exported by Database.Bloodhound as well
277−-- no trailing slashes in servers, library handles building the path.
278−
279−{-| Common environment for Elasticsearch calls. Connections will be
280− pipelined according to the provided HTTP connection manager.
281−-}
282−data BHEnv = BHEnv { bhServer :: Server
283− , bhManager :: Manager
284− }
285−
286−{-| All API calls to Elasticsearch operate within
287− MonadBH. The idea is that it can be easily embedded in your
288− own monad transformer stack. A default instance for a ReaderT and
289− alias 'BH' is provided for the simple case.
290−-}
291−class (Functor m, Applicative m, MonadIO m) => MonadBH m where
292− getBHEnv :: m BHEnv
293−
294−newtype BH m a = BH {
295− unBH :: ReaderT BHEnv m a
296− } deriving ( Functor
297− , Applicative
298− , Monad
299− , MonadIO
300− , MonadState s
301− , MonadWriter w
302− , MonadError e
303− , Alternative
304− , MonadPlus
305− , MonadFix
306− , MonadThrow
307− , MonadCatch
308− , MonadMask)
309−
310−instance MonadTrans BH where
311− lift = BH . lift
312−
313−instance (MonadReader r m) => MonadReader r (BH m) where
314− ask = lift ask
315− local f (BH (ReaderT m)) = BH $ ReaderT $ \r ->
316− local f (m r)
317−
318−instance (Functor m, Applicative m, MonadIO m) => MonadBH (BH m) where
319− getBHEnv = BH getBHEnv
320−
321−
322−instance (Functor m, Applicative m, MonadIO m) => MonadBH (ReaderT BHEnv m) where
323− getBHEnv = ask
324−
325−runBH :: BHEnv -> BH m a -> m a
326−runBH e f = runReaderT (unBH f) e
327−
328−{-| 'Version' is embedded in 'Status' -}
329−data Version = Version { number :: Text
330− , build_hash :: Text
331− , build_timestamp :: UTCTime
332− , build_snapshot :: Bool
333− , lucene_version :: Text } deriving (Eq, Show, Generic)
334−
335−{-| 'Status' is a data type for describing the JSON body returned by
336− Elasticsearch when you query its status. This was deprecated in 1.2.0.
337−
338− <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-status.html#indices-status>
339−-}
340−
341−data Status = Status { ok :: Maybe Bool
342− , status :: Int
343− , name :: Text
344− , version :: Version
345− , tagline :: Text } deriving (Eq, Show)
346−
347−{-| 'IndexSettings' is used to configure the shards and replicas when you create
348− an Elasticsearch Index.
349−
350− <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-create-index.html>
351−-}
352−
353−data IndexSettings =
354− IndexSettings { indexShards :: ShardCount
355− , indexReplicas :: ReplicaCount } deriving (Eq, Show)
356−
357−{-| 'defaultIndexSettings' is an 'IndexSettings' with 3 shards and 2 replicas. -}
358−defaultIndexSettings :: IndexSettings
359−defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
360−
361−{-| 'UpdatableIndexSetting' are settings which may be updated after an index is created.
362−
363− <https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html>
364−-}
365−data UpdatableIndexSetting = NumberOfReplicas ReplicaCount
366− -- ^ The number of replicas each shard has.
367− | AutoExpandReplicas ReplicaBounds
368− | BlocksReadOnly Bool
369− -- ^ Set to True to have the index read only. False to allow writes and metadata changes.
370− | BlocksRead Bool
371− -- ^ Set to True to disable read operations against the index.
372− | BlocksWrite Bool
373− -- ^ Set to True to disable write operations against the index.
374− | BlocksMetaData Bool
375− -- ^ Set to True to disable metadata operations against the index.
376− | RefreshInterval NominalDiffTime
377− -- ^ The async refresh interval of a shard
378− | IndexConcurrency Int
379− | FailOnMergeFailure Bool
380− | TranslogFlushThresholdOps Int
381− -- ^ When to flush on operations.
382− | TranslogFlushThresholdSize Bytes
383− -- ^ When to flush based on translog (bytes) size.
384− | TranslogFlushThresholdPeriod NominalDiffTime
385− -- ^ When to flush based on a period of not flushing.
386− | TranslogDisableFlush Bool
387− -- ^ Disables flushing. Note, should be set for a short interval and then enabled.
388− | CacheFilterMaxSize (Maybe Bytes)
389− -- ^ The maximum size of filter cache (per segment in shard).
390− | CacheFilterExpire (Maybe NominalDiffTime)
391− -- ^ The expire after access time for filter cache.
392− | GatewaySnapshotInterval NominalDiffTime
393− -- ^ The gateway snapshot interval (only applies to shared gateways).
394− | RoutingAllocationInclude (NonEmpty NodeAttrFilter)
395− -- ^ A node matching any rule will be allowed to host shards from the index.
396− | RoutingAllocationExclude (NonEmpty NodeAttrFilter)
397− -- ^ A node matching any rule will NOT be allowed to host shards from the index.
398− | RoutingAllocationRequire (NonEmpty NodeAttrFilter)
399− -- ^ Only nodes matching all rules will be allowed to host shards from the index.
400− | RoutingAllocationEnable AllocationPolicy
401− -- ^ Enables shard allocation for a specific index.
402− | RoutingAllocationShardsPerNode ShardCount
403− -- ^ Controls the total number of shards (replicas and primaries) allowed to be allocated on a single node.
404− | RecoveryInitialShards InitialShardCount
405− -- ^ When using local gateway a particular shard is recovered only if there can be allocated quorum shards in the cluster.
406− | GCDeletes NominalDiffTime
407− | TTLDisablePurge Bool
408− -- ^ Disables temporarily the purge of expired docs.
409− | TranslogFSType FSType
410− | IndexCompoundFormat CompoundFormat
411− | IndexCompoundOnFlush Bool
412− | WarmerEnabled Bool
413− deriving (Eq, Show)
414−
415−data AllocationPolicy = AllocAll
416− -- ^ Allows shard allocation for all shards.
417− | AllocPrimaries
418− -- ^ Allows shard allocation only for primary shards.
419− | AllocNewPrimaries
420− -- ^ Allows shard allocation only for primary shards for new indices.
421− | AllocNone
422− -- ^ No shard allocation is allowed
423− deriving (Eq, Show)
424−
425−data ReplicaBounds = ReplicasBounded Int Int
426− | ReplicasLowerBounded Int
427− | ReplicasUnbounded
428− deriving (Eq, Show)
429−
430−newtype Bytes = Bytes Int deriving (Eq, Show, Ord, ToJSON)
431−
432−data FSType = FSSimple
433− | FSBuffered deriving (Eq, Show, Ord)
434−
435−data InitialShardCount = QuorumShards
436− | QuorumMinus1Shards
437− | FullShards
438− | FullMinus1Shards
439− | ExplicitShards Int
440− deriving (Eq, Show)
441−
442−data NodeAttrFilter = NodeAttrFilter { nodeAttrFilterName :: NodeAttrName
443− , nodeAttrFilterValues :: NonEmpty Text}
444− deriving (Eq, Show)
445−
446−newtype NodeAttrName = NodeAttrName Text deriving (Eq, Show)
447−
448−data CompoundFormat = CompoundFileFormat Bool
449− | MergeSegmentVsTotalIndex Double
450− -- ^ percentage between 0 and 1 where 0 is false, 1 is true
451− deriving (Eq, Show)
452−
453−newtype NominalDiffTimeJSON = NominalDiffTimeJSON NominalDiffTime
454−
455−data IndexSettingsSummary = IndexSettingsSummary { sSummaryShardCount :: ShardCount
456− , sSummaryUpdateable :: [UpdatableIndexSetting]}
457− deriving (Eq, Show)
458−
459−{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
460−type Reply = Network.HTTP.Client.Response L.ByteString
461−type Method = NHTM.Method
462−
463−{-| 'OpenCloseIndex' is a sum type for opening and closing indices.
464−
465− <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
466−-}
467−data OpenCloseIndex = OpenIndex | CloseIndex deriving (Eq, Show)
468−
469−data FieldType = GeoPointType
470− | GeoShapeType
471− | FloatType
472− | IntegerType
473− | LongType
474− | ShortType
475− | ByteType deriving (Eq, Show)
476−
477−data FieldDefinition =
478− FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
479−
480−{-| An 'IndexTemplate' defines a template that will automatically be
481− applied to new indices created. The templates include both
482− 'IndexSettings' and mappings, and a simple 'TemplatePattern' that
483− controls if the template will be applied to the index created.
484− Specify mappings as follows: @[toJSON TweetMapping, ...]@
485−
486− https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices-templates.html
487−-}
488−data IndexTemplate =
489− IndexTemplate { templatePattern :: TemplatePattern
490− , templateSettings :: Maybe IndexSettings
491− , templateMappings :: [Value]
492− }
493−
494−data MappingField =
495− MappingField { mappingFieldName :: FieldName
496− , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
497−
498−{-| Support for type reification of 'Mapping's is currently incomplete, for
499− now the mapping API verbiage expects a 'ToJSON'able blob.
500−
501− Indexes have mappings, mappings are schemas for the documents contained in the
502− index. I'd recommend having only one mapping per index, always having a mapping,
503− and keeping different kinds of documents separated if possible.
504−-}
505−data Mapping = Mapping { typeName :: TypeName
506− , mappingFields :: [MappingField] } deriving (Eq, Show)
507−
508−{-| 'BulkOperation' is a sum type for expressing the four kinds of bulk
509− operation index, create, delete, and update. 'BulkIndex' behaves like an
510− "upsert", 'BulkCreate' will fail if a document already exists at the DocId.
511−
512− <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html#docs-bulk>
513−-}
514−data BulkOperation =
515− BulkIndex IndexName MappingName DocId Value
516− | BulkCreate IndexName MappingName DocId Value
517− | BulkDelete IndexName MappingName DocId
518− | BulkUpdate IndexName MappingName DocId Value deriving (Eq, Show)
519−
520−{-| 'EsResult' describes the standard wrapper JSON document that you see in
521− successful Elasticsearch lookups or lookups that couldn't find the document.
522−-}
523−data EsResult a = EsResult { _index :: Text
524− , _type :: Text
525− , _id :: Text
526− , foundResult :: Maybe (EsResultFound a)} deriving (Eq, Show)
527−
528−{-| 'EsResultFound' contains the document and its metadata inside of an
529− 'EsResult' when the document was successfully found.
530−-}
531−data EsResultFound a = EsResultFound { _version :: DocVersion
532− , _source :: a } deriving (Eq, Show)
533−
534−{-| 'EsError' is the generic type that will be returned when there was a
535− problem. If you can't parse the expected response, its a good idea to
536− try parsing this.
537−-}
538−data EsError = EsError { errorStatus :: Int
539− , errorMessage :: Text } deriving (Eq, Show)
540−
541−
542−{-| 'DocVersion' is an integer version number for a document between 1
543−and 9.2e+18 used for <<https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html optimistic concurrency control>>.
544−-}
545−newtype DocVersion = DocVersion {
546− docVersionNumber :: Int
547− } deriving (Eq, Show, Ord, ToJSON)
548−
549−-- | Smart constructor for in-range doc version
550−mkDocVersion :: Int -> Maybe DocVersion
551−mkDocVersion i
552− | i >= (docVersionNumber minBound) && i <= (docVersionNumber maxBound) =
553− Just $ DocVersion i
554− | otherwise = Nothing
555−
556−
557−{-| 'ExternalDocVersion' is a convenience wrapper if your code uses its
558−own version numbers instead of ones from ES.
559−-}
560−newtype ExternalDocVersion = ExternalDocVersion DocVersion
561− deriving (Eq, Show, Ord, Bounded, Enum, ToJSON)
562−
563−{-| 'VersionControl' is specified when indexing documents as a
564−optimistic concurrency control.
565−-}
566−data VersionControl = NoVersionControl
567− -- ^ Don't send a version. This is a pure overwrite.
568− | InternalVersion DocVersion
569− -- ^ Use the default ES versioning scheme. Only
570− -- index the document if the version is the same
571− -- as the one specified. Only applicable to
572− -- updates, as you should be getting Version from
573− -- a search result.
574− | ExternalGT ExternalDocVersion
575− -- ^ Use your own version numbering. Only index
576− -- the document if the version is strictly higher
577− -- OR the document doesn't exist. The given
578− -- version will be used as the new version number
579− -- for the stored document. N.B. All updates must
580− -- increment this number, meaning there is some
581− -- global, external ordering of updates.
582− | ExternalGTE ExternalDocVersion
583− -- ^ Use your own version numbering. Only index
584− -- the document if the version is equal or higher
585− -- than the stored version. Will succeed if there
586− -- is no existing document. The given version will
587− -- be used as the new version number for the
588− -- stored document. Use with care, as this could
589− -- result in data loss.
590− | ForceVersion ExternalDocVersion
591− -- ^ The document will always be indexed and the
592− -- given version will be the new version. This is
593− -- typically used for correcting errors. Use with
594− -- care, as this could result in data loss.
595− deriving (Show, Eq, Ord)
596−
597−{-| 'DocumentParent' is used to specify a parent document.
598−-}
599−newtype DocumentParent = DocumentParent DocId
600− deriving (Eq, Show)
601−
602−{-| 'IndexDocumentSettings' are special settings supplied when indexing
603−a document. For the best backwards compatiblity when new fields are
604−added, you should probably prefer to start with 'defaultIndexDocumentSettings'
605−-}
606−data IndexDocumentSettings =
607− IndexDocumentSettings { idsVersionControl :: VersionControl
608− , idsParent :: Maybe DocumentParent
609− } deriving (Eq, Show)
610−
611−{-| Reasonable default settings. Chooses no version control and no parent.
612−-}
613−defaultIndexDocumentSettings :: IndexDocumentSettings
614−defaultIndexDocumentSettings = IndexDocumentSettings NoVersionControl Nothing
615−
616−{-| 'Sort' is a synonym for a list of 'SortSpec's. Sort behavior is order
617− dependent with later sorts acting as tie-breakers for earlier sorts.
618−-}
619−type Sort = [SortSpec]
620−
621−{-| The two main kinds of 'SortSpec' are 'DefaultSortSpec' and
622− 'GeoDistanceSortSpec'. The latter takes a 'SortOrder', 'GeoPoint', and
623− 'DistanceUnit' to express "nearness" to a single geographical point as a
624− sort specification.
625−
626−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
627−-}
628−data SortSpec = DefaultSortSpec DefaultSort
629− | GeoDistanceSortSpec SortOrder GeoPoint DistanceUnit deriving (Eq, Show)
630−
631−{-| 'DefaultSort' is usually the kind of 'SortSpec' you'll want. There's a
632− 'mkSort' convenience function for when you want to specify only the most
633− common parameters.
634−
635−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
636−-}
637−data DefaultSort =
638− DefaultSort { sortFieldName :: FieldName
639− , sortOrder :: SortOrder
640− -- default False
641− , ignoreUnmapped :: Bool
642− , sortMode :: Maybe SortMode
643− , missingSort :: Maybe Missing
644− , nestedFilter :: Maybe Filter } deriving (Eq, Show)
645−
646−{-| 'SortOrder' is 'Ascending' or 'Descending', as you might expect. These get
647− encoded into "asc" or "desc" when turned into JSON.
648−
649−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
650−-}
651−data SortOrder = Ascending
652− | Descending deriving (Eq, Show)
653−
654−{-| 'Missing' prescribes how to handle missing fields. A missing field can be
655− sorted last, first, or using a custom value as a substitute.
656−
657−<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_missing_values>
658−-}
659−data Missing = LastMissing
660− | FirstMissing
661− | CustomMissing Text deriving (Eq, Show)
662−
663−{-| 'SortMode' prescribes how to handle sorting array/multi-valued fields.
664−
665−http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_sort_mode_option
666−-}
667−data SortMode = SortMin
668− | SortMax
669− | SortSum
670− | SortAvg deriving (Eq, Show)
671−
672−{-| 'mkSort' defaults everything but the 'FieldName' and the 'SortOrder' so
673− that you can concisely describe the usual kind of 'SortSpec's you want.
674−-}
675−mkSort :: FieldName -> SortOrder -> DefaultSort
676−mkSort fieldName sOrder = DefaultSort fieldName sOrder False Nothing Nothing Nothing
677−
678−{-| 'Cache' is for telling ES whether it should cache a 'Filter' not.
679− 'Query's cannot be cached.
680−-}
681−type Cache = Bool -- caching on/off
682−defaultCache :: Cache
683−defaultCache = False
684−
685−{-| 'PrefixValue' is used in 'PrefixQuery' as the main query component.
686−-}
687−type PrefixValue = Text
688−
689−{-| 'BooleanOperator' is the usual And/Or operators with an ES compatible
690− JSON encoding baked in. Used all over the place.
691−-}
692−data BooleanOperator = And | Or deriving (Eq, Show)
693−
694−{-| 'ShardCount' is part of 'IndexSettings'
695−-}
696−newtype ShardCount = ShardCount Int deriving (Eq, Show, Generic)
697−
698−{-| 'ReplicaCount' is part of 'IndexSettings'
699−-}
700−newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic)
701−
702−{-| 'Server' is used with the client functions to point at the ES instance
703−-}
704−newtype Server = Server Text deriving (Eq, Show)
705−
706−{-| 'IndexName' is used to describe which index to query/create/delete
707−-}
708−newtype IndexName = IndexName Text deriving (Eq, Generic, Show)
709−
710−{-| 'TemplateName' is used to describe which template to query/create/delete
711−-}
712−newtype TemplateName = TemplateName Text deriving (Eq, Show, Generic)
713−
714−{-| 'TemplatePattern' represents a pattern which is matched against index names
715−-}
716−newtype TemplatePattern = TemplatePattern Text deriving (Eq, Show, Generic)
717−
718−{-| 'MappingName' is part of mappings which are how ES describes and schematizes
719− the data in the indices.
720−-}
721−newtype MappingName = MappingName Text deriving (Eq, Generic, Show)
722−
723−{-| 'DocId' is a generic wrapper value for expressing unique Document IDs.
724− Can be set by the user or created by ES itself. Often used in client
725− functions for poking at specific documents.
726−-}
727−newtype DocId = DocId Text deriving (Eq, Generic, Show)
728−
729−{-| 'QueryString' is used to wrap query text bodies, be they human written or not.
730−-}
731−newtype QueryString = QueryString Text deriving (Eq, Generic, Show)
732−
733−{-| 'FieldName' is used all over the place wherever a specific field within
734− a document needs to be specified, usually in 'Query's or 'Filter's.
735−-}
736−newtype FieldName = FieldName Text deriving (Eq, Show)
737−
738−
739−{-| 'Script' is often used in place of 'FieldName' to specify more
740−complex ways of extracting a value from a document.
741−-}
742−newtype Script = Script { scriptText :: Text } deriving (Eq, Show)
743−
744−{-| 'CacheName' is used in 'RegexpFilter' for describing the
745− 'CacheKey' keyed caching behavior.
746−-}
747−newtype CacheName = CacheName Text deriving (Eq, Show)
748−
749−{-| 'CacheKey' is used in 'RegexpFilter' to key regex caching.
750−-}
751−newtype CacheKey =
752− CacheKey Text deriving (Eq, Show)
753−newtype Existence =
754− Existence Bool deriving (Eq, Show)
755−newtype NullValue =
756− NullValue Bool deriving (Eq, Show)
757−newtype CutoffFrequency =
758− CutoffFrequency Double deriving (Eq, Show, Generic)
759−newtype Analyzer =
760− Analyzer Text deriving (Eq, Show, Generic)
761−newtype MaxExpansions =
762− MaxExpansions Int deriving (Eq, Show, Generic)
763−
764−{-| 'Lenient', if set to true, will cause format based failures to be
765− ignored. I don't know what the bloody default is, Elasticsearch
766− documentation didn't say what it was. Let me know if you figure it out.
767−-}
768−newtype Lenient =
769− Lenient Bool deriving (Eq, Show, Generic)
770−newtype Tiebreaker =
771− Tiebreaker Double deriving (Eq, Show, Generic)
772−newtype Boost =
773− Boost Double deriving (Eq, Show, Generic)
774−newtype BoostTerms =
775− BoostTerms Double deriving (Eq, Show, Generic)
776−
777−{-| 'MinimumMatch' controls how many should clauses in the bool query should
778− match. Can be an absolute value (2) or a percentage (30%) or a
779− combination of both.
780−-}
781−newtype MinimumMatch =
782− MinimumMatch Int deriving (Eq, Show, Generic)
783−newtype MinimumMatchText =
784− MinimumMatchText Text deriving (Eq, Show)
785−newtype DisableCoord =
786− DisableCoord Bool deriving (Eq, Show, Generic)
787−newtype IgnoreTermFrequency =
788− IgnoreTermFrequency Bool deriving (Eq, Show, Generic)
789−newtype MinimumTermFrequency =
790− MinimumTermFrequency Int deriving (Eq, Show, Generic)
791−newtype MaxQueryTerms =
792− MaxQueryTerms Int deriving (Eq, Show, Generic)
793−newtype Fuzziness =
794− Fuzziness Double deriving (Eq, Show, Generic)
795−
796−{-| 'PrefixLength' is the prefix length used in queries, defaults to 0. -}
797−newtype PrefixLength =
798− PrefixLength Int deriving (Eq, Show, Generic)
799−newtype TypeName =
800− TypeName Text deriving (Eq, Show, Generic)
801−newtype PercentMatch =
802− PercentMatch Double deriving (Eq, Show, Generic)
803−newtype StopWord =
804− StopWord Text deriving (Eq, Show, Generic)
805−newtype QueryPath =
806− QueryPath Text deriving (Eq, Show, Generic)
807−
808−{-| Allowing a wildcard at the beginning of a word (eg "*ing") is particularly
809− heavy, because all terms in the index need to be examined, just in case
810− they match. Leading wildcards can be disabled by setting
811− 'AllowLeadingWildcard' to false. -}
812−newtype AllowLeadingWildcard =
813− AllowLeadingWildcard Bool deriving (Eq, Show, Generic)
814−newtype LowercaseExpanded =
815− LowercaseExpanded Bool deriving (Eq, Show, Generic)
816−newtype EnablePositionIncrements =
817− EnablePositionIncrements Bool deriving (Eq, Show, Generic)
818−
819−{-| By default, wildcard terms in a query are not analyzed.
820− Setting 'AnalyzeWildcard' to true enables best-effort analysis.
821−-}
822−newtype AnalyzeWildcard = AnalyzeWildcard Bool deriving (Eq, Show, Generic)
823−
824−{-| 'GeneratePhraseQueries' defaults to false.
825−-}
826−newtype GeneratePhraseQueries =
827− GeneratePhraseQueries Bool deriving (Eq, Show, Generic)
828−
829−{-| 'Locale' is used for string conversions - defaults to ROOT.
830−-}
831−newtype Locale = Locale Text deriving (Eq, Show, Generic)
832−newtype MaxWordLength = MaxWordLength Int deriving (Eq, Show, Generic)
833−newtype MinWordLength = MinWordLength Int deriving (Eq, Show, Generic)
834−
835−{-| 'PhraseSlop' sets the default slop for phrases, 0 means exact
836− phrase matches. Default is 0.
837−-}
838−newtype PhraseSlop = PhraseSlop Int deriving (Eq, Show, Generic)
839−newtype MinDocFrequency = MinDocFrequency Int deriving (Eq, Show, Generic)
840−newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic)
402+ , DateRangeResult(..)
403+ , TopHitResult(..)
404+
405+ , EsUsername(..)
406+ , EsPassword(..)
407+
408+ , Analysis(..)
409+ , AnalyzerDefinition(..)
410+ , TokenizerDefinition(..)
411+ , TokenFilterDefinition(..)
412+ , CharFilterDefinition(..)
413+ , Ngram(..)
414+ , TokenChar(..)
415+ , Shingle(..)
416+ , Language(..)
417+ ) where
418+
419+import Bloodhound.Import
420+
421+import Database.Bloodhound.Internal.Aggregation
422+import Database.Bloodhound.Internal.Analysis
423+import Database.Bloodhound.Internal.Client
424+import Database.Bloodhound.Internal.Highlight
425+import Database.Bloodhound.Internal.Newtypes
426+import Database.Bloodhound.Internal.Query
427+import Database.Bloodhound.Internal.Sort
428+import Database.Bloodhound.Internal.Suggest
841429
842430{-| 'unpackId' is a silly convenience function that gets used once.
843431-}
@@ -845,8 +433,6 @@ unpackId :: DocId -> Text
845433unpackId (DocId docId) = docId
846434
847435type TrackSortScores = Bool
848−newtype From = From Int deriving (Eq, Show, ToJSON)
849−newtype Size = Size Int deriving (Eq, Show, ToJSON)
850436
851437data Search = Search { queryBody :: Maybe Query
852438 , filterBody :: Maybe Filter
@@ -858,1754 +444,87 @@ data Search = Search { queryBody :: Maybe Query
858444 , from :: From
859445 , size :: Size
860446 , searchType :: SearchType
447+ , searchAfterKey :: Maybe SearchAfterKey
861448 , fields :: Maybe [FieldName]
862− , source :: Maybe Source } deriving (Eq, Show)
449+ , scriptFields :: Maybe ScriptFields
450+ , source :: Maybe Source
451+ , suggestBody :: Maybe Suggest -- ^ Only one Suggestion request / response per Search is supported.
452+ } deriving (Eq, Show)
453+
454+
455+instance ToJSON Search where
456+ toJSON (Search mquery sFilter sort searchAggs
457+ highlight sTrackSortScores sFrom sSize _ sAfter sFields
458+ sScriptFields sSource sSuggest) =
459+ omitNulls [ "query" .= query'
460+ , "sort" .= sort
461+ , "aggregations" .= searchAggs
462+ , "highlight" .= highlight
463+ , "from" .= sFrom
464+ , "size" .= sSize
465+ , "track_scores" .= sTrackSortScores
466+ , "search_after" .= sAfter
467+ , "fields" .= sFields
468+ , "script_fields" .= sScriptFields
469+ , "_source" .= sSource
470+ , "suggest" .= sSuggest]
471+
472+ where query' = case sFilter of
473+ Nothing -> mquery
474+ Just x ->
475+ Just
476+ . QueryBoolQuery
477+ $ mkBoolQuery (maybeToList mquery)
478+ [x] [] []
863479
864480data SearchType = SearchTypeQueryThenFetch
865481 | SearchTypeDfsQueryThenFetch
866− | SearchTypeCount
867− | SearchTypeScan
868− | SearchTypeQueryAndFetch
869− | SearchTypeDfsQueryAndFetch
870482 deriving (Eq, Show)
871483
872484data Source =
873485 NoSource
874486 | SourcePatterns PatternOrPatterns
875487 | SourceIncludeExclude Include Exclude
876− deriving (Show, Eq)
877−
878−data PatternOrPatterns = PopPattern Pattern
879− | PopPatterns [Pattern] deriving (Eq, Show)
880−
881−data Include = Include [Pattern] deriving (Eq, Show)
882−data Exclude = Exclude [Pattern] deriving (Eq, Show)
883−
884−newtype Pattern = Pattern Text deriving (Eq, Show)
885−
886−data Highlights = Highlights { globalsettings :: Maybe HighlightSettings
887− , highlightFields :: [FieldHighlight]
888− } deriving (Show, Eq)
889−
890−data FieldHighlight = FieldHighlight FieldName (Maybe HighlightSettings)
891− deriving (Show, Eq)
892−
893−
894−data HighlightSettings = Plain PlainHighlight
895− | Postings PostingsHighlight
896− | FastVector FastVectorHighlight
897− deriving (Show, Eq)
898−data PlainHighlight =
899− PlainHighlight { plainCommon :: Maybe CommonHighlight
900− , plainNonPost :: Maybe NonPostings } deriving (Show, Eq)
901−
902− -- This requires that index_options are set to 'offset' in the mapping.
903−data PostingsHighlight = PostingsHighlight (Maybe CommonHighlight) deriving (Show, Eq)
904−
905−-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
906−data FastVectorHighlight =
907− FastVectorHighlight { fvCommon :: Maybe CommonHighlight
908− , fvNonPostSettings :: Maybe NonPostings
909− , boundaryChars :: Maybe Text
910− , boundaryMaxScan :: Maybe Int
911− , fragmentOffset :: Maybe Int
912− , matchedFields :: [Text]
913− , phraseLimit :: Maybe Int
914− } deriving (Show, Eq)
915−
916−data CommonHighlight =
917− CommonHighlight { order :: Maybe Text
918− , forceSource :: Maybe Bool
919− , tag :: Maybe HighlightTag
920− , encoder :: Maybe HighlightEncoder
921− , noMatchSize :: Maybe Int
922− , highlightQuery :: Maybe Query
923− , requireFieldMatch :: Maybe Bool
924− } deriving (Show, Eq)
925−
926−-- Settings that are only applicable to FastVector and Plain highlighters.
927−data NonPostings =
928− NonPostings { fragmentSize :: Maybe Int
929− , numberOfFragments :: Maybe Int} deriving (Show, Eq)
930−
931−data HighlightEncoder = DefaultEncoder
932− | HTMLEncoder
933− deriving (Show, Eq)
934−
935−-- NOTE: Should the tags use some kind of HTML type, rather than Text?
936−data HighlightTag = TagSchema Text
937− | CustomTags ([Text], [Text]) -- Only uses more than the first value in the lists if fvh
938− deriving (Show, Eq)
939−
940−
941−data Query =
942− TermQuery Term (Maybe Boost)
943− | TermsQuery (NonEmpty Term)
944− | QueryMatchQuery MatchQuery
945− | QueryMultiMatchQuery MultiMatchQuery
946− | QueryBoolQuery BoolQuery
947− | QueryBoostingQuery BoostingQuery
948− | QueryCommonTermsQuery CommonTermsQuery
949− | ConstantScoreFilter Filter Boost
950− | ConstantScoreQuery Query Boost
951− | QueryDisMaxQuery DisMaxQuery
952− | QueryFilteredQuery FilteredQuery
953− | QueryFuzzyLikeThisQuery FuzzyLikeThisQuery
954− | QueryFuzzyLikeFieldQuery FuzzyLikeFieldQuery
955− | QueryFuzzyQuery FuzzyQuery
956− | QueryHasChildQuery HasChildQuery
957− | QueryHasParentQuery HasParentQuery
958− | IdsQuery MappingName [DocId]
959− | QueryIndicesQuery IndicesQuery
960− | MatchAllQuery (Maybe Boost)
961− | QueryMoreLikeThisQuery MoreLikeThisQuery
962− | QueryMoreLikeThisFieldQuery MoreLikeThisFieldQuery
963− | QueryNestedQuery NestedQuery
964− | QueryPrefixQuery PrefixQuery
965− | QueryQueryStringQuery QueryStringQuery
966− | QuerySimpleQueryStringQuery SimpleQueryStringQuery
967− | QueryRangeQuery RangeQuery
968− | QueryRegexpQuery RegexpQuery
969− deriving (Eq, Show)
970−
971−data RegexpQuery =
972− RegexpQuery { regexpQueryField :: FieldName
973− , regexpQuery :: Regexp
974− , regexpQueryFlags :: RegexpFlags
975− , regexpQueryBoost :: Maybe Boost
976− } deriving (Eq, Show)
977−
978−data RangeQuery =
979− RangeQuery { rangeQueryField :: FieldName
980− , rangeQueryRange :: RangeValue
981− , rangeQueryBoost :: Boost } deriving (Eq, Show)
982−
983−mkRangeQuery :: FieldName -> RangeValue -> RangeQuery
984−mkRangeQuery f r = RangeQuery f r (Boost 1.0)
985−
986−data SimpleQueryStringQuery =
987− SimpleQueryStringQuery
988− { simpleQueryStringQuery :: QueryString
989− , simpleQueryStringField :: Maybe FieldOrFields
990− , simpleQueryStringOperator :: Maybe BooleanOperator
991− , simpleQueryStringAnalyzer :: Maybe Analyzer
992− , simpleQueryStringFlags :: Maybe [SimpleQueryFlag]
993− , simpleQueryStringLowercaseExpanded :: Maybe LowercaseExpanded
994− , simpleQueryStringLocale :: Maybe Locale
995− } deriving (Eq, Show)
996−
997−data SimpleQueryFlag =
998− SimpleQueryAll
999− | SimpleQueryNone
1000− | SimpleQueryAnd
1001− | SimpleQueryOr
1002− | SimpleQueryPrefix
1003− | SimpleQueryPhrase
1004− | SimpleQueryPrecedence
1005− | SimpleQueryEscape
1006− | SimpleQueryWhitespace
1007− | SimpleQueryFuzzy
1008− | SimpleQueryNear
1009− | SimpleQuerySlop deriving (Eq, Show)
1010−
1011−-- use_dis_max and tie_breaker when fields are plural?
1012−data QueryStringQuery =
1013− QueryStringQuery
1014− { queryStringQuery :: QueryString
1015− , queryStringDefaultField :: Maybe FieldName
1016− , queryStringOperator :: Maybe BooleanOperator
1017− , queryStringAnalyzer :: Maybe Analyzer
1018− , queryStringAllowLeadingWildcard :: Maybe AllowLeadingWildcard
1019− , queryStringLowercaseExpanded :: Maybe LowercaseExpanded
1020− , queryStringEnablePositionIncrements :: Maybe EnablePositionIncrements
1021− , queryStringFuzzyMaxExpansions :: Maybe MaxExpansions
1022− , queryStringFuzziness :: Maybe Fuzziness
1023− , queryStringFuzzyPrefixLength :: Maybe PrefixLength
1024− , queryStringPhraseSlop :: Maybe PhraseSlop
1025− , queryStringBoost :: Maybe Boost
1026− , queryStringAnalyzeWildcard :: Maybe AnalyzeWildcard
1027− , queryStringGeneratePhraseQueries :: Maybe GeneratePhraseQueries
1028− , queryStringMinimumShouldMatch :: Maybe MinimumMatch
1029− , queryStringLenient :: Maybe Lenient
1030− , queryStringLocale :: Maybe Locale
1031− } deriving (Eq, Show)
1032−
1033−mkQueryStringQuery :: QueryString -> QueryStringQuery
1034−mkQueryStringQuery qs =
1035− QueryStringQuery qs Nothing Nothing
1036− Nothing Nothing Nothing Nothing
1037− Nothing Nothing Nothing Nothing
1038− Nothing Nothing Nothing Nothing
1039− Nothing Nothing
1040−
1041−data FieldOrFields = FofField FieldName
1042− | FofFields [FieldName] deriving (Eq, Show)
1043−
1044−data PrefixQuery =
1045− PrefixQuery
1046− { prefixQueryField :: FieldName
1047− , prefixQueryPrefixValue :: Text
1048− , prefixQueryBoost :: Maybe Boost } deriving (Eq, Show)
1049−
1050−data NestedQuery =
1051− NestedQuery
1052− { nestedQueryPath :: QueryPath
1053− , nestedQueryScoreType :: ScoreType
1054− , nestedQuery :: Query } deriving (Eq, Show)
1055−
1056−data MoreLikeThisFieldQuery =
1057− MoreLikeThisFieldQuery
1058− { moreLikeThisFieldText :: Text
1059− , moreLikeThisFieldFields :: FieldName
1060− -- default 0.3 (30%)
1061− , moreLikeThisFieldPercentMatch :: Maybe PercentMatch
1062− , moreLikeThisFieldMinimumTermFreq :: Maybe MinimumTermFrequency
1063− , moreLikeThisFieldMaxQueryTerms :: Maybe MaxQueryTerms
1064− , moreLikeThisFieldStopWords :: Maybe [StopWord]
1065− , moreLikeThisFieldMinDocFrequency :: Maybe MinDocFrequency
1066− , moreLikeThisFieldMaxDocFrequency :: Maybe MaxDocFrequency
1067− , moreLikeThisFieldMinWordLength :: Maybe MinWordLength
1068− , moreLikeThisFieldMaxWordLength :: Maybe MaxWordLength
1069− , moreLikeThisFieldBoostTerms :: Maybe BoostTerms
1070− , moreLikeThisFieldBoost :: Maybe Boost
1071− , moreLikeThisFieldAnalyzer :: Maybe Analyzer
1072− } deriving (Eq, Show)
1073−
1074−data MoreLikeThisQuery =
1075− MoreLikeThisQuery
1076− { moreLikeThisText :: Text
1077− , moreLikeThisFields :: Maybe [FieldName]
1078− -- default 0.3 (30%)
1079− , moreLikeThisPercentMatch :: Maybe PercentMatch
1080− , moreLikeThisMinimumTermFreq :: Maybe MinimumTermFrequency
1081− , moreLikeThisMaxQueryTerms :: Maybe MaxQueryTerms
1082− , moreLikeThisStopWords :: Maybe [StopWord]
1083− , moreLikeThisMinDocFrequency :: Maybe MinDocFrequency
1084− , moreLikeThisMaxDocFrequency :: Maybe MaxDocFrequency
1085− , moreLikeThisMinWordLength :: Maybe MinWordLength
1086− , moreLikeThisMaxWordLength :: Maybe MaxWordLength
1087− , moreLikeThisBoostTerms :: Maybe BoostTerms
1088− , moreLikeThisBoost :: Maybe Boost
1089− , moreLikeThisAnalyzer :: Maybe Analyzer
1090− } deriving (Eq, Show)
1091−
1092−data IndicesQuery =
1093− IndicesQuery
1094− { indicesQueryIndices :: [IndexName]
1095− , indicesQuery :: Query
1096− -- default "all"
1097− , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
1098−
1099−data HasParentQuery =
1100− HasParentQuery
1101− { hasParentQueryType :: TypeName
1102− , hasParentQuery :: Query
1103− , hasParentQueryScoreType :: Maybe ScoreType } deriving (Eq, Show)
1104−
1105−data HasChildQuery =
1106− HasChildQuery
1107− { hasChildQueryType :: TypeName
1108− , hasChildQuery :: Query
1109− , hasChildQueryScoreType :: Maybe ScoreType } deriving (Eq, Show)
1110−
1111−data ScoreType =
1112− ScoreTypeMax
1113− | ScoreTypeSum
1114− | ScoreTypeAvg
1115− | ScoreTypeNone deriving (Eq, Show)
1116−
1117−data FuzzyQuery =
1118− FuzzyQuery { fuzzyQueryField :: FieldName
1119− , fuzzyQueryValue :: Text
1120− , fuzzyQueryPrefixLength :: PrefixLength
1121− , fuzzyQueryMaxExpansions :: MaxExpansions
1122− , fuzzyQueryFuzziness :: Fuzziness
1123− , fuzzyQueryBoost :: Maybe Boost
1124− } deriving (Eq, Show)
1125−
1126−data FuzzyLikeFieldQuery =
1127− FuzzyLikeFieldQuery
1128− { fuzzyLikeField :: FieldName
1129− -- anaphora is good for the soul.
1130− , fuzzyLikeFieldText :: Text
1131− , fuzzyLikeFieldMaxQueryTerms :: MaxQueryTerms
1132− , fuzzyLikeFieldIgnoreTermFrequency :: IgnoreTermFrequency
1133− , fuzzyLikeFieldFuzziness :: Fuzziness
1134− , fuzzyLikeFieldPrefixLength :: PrefixLength
1135− , fuzzyLikeFieldBoost :: Boost
1136− , fuzzyLikeFieldAnalyzer :: Maybe Analyzer
1137− } deriving (Eq, Show)
1138−
1139−data FuzzyLikeThisQuery =
1140− FuzzyLikeThisQuery
1141− { fuzzyLikeFields :: [FieldName]
1142− , fuzzyLikeText :: Text
1143− , fuzzyLikeMaxQueryTerms :: MaxQueryTerms
1144− , fuzzyLikeIgnoreTermFrequency :: IgnoreTermFrequency
1145− , fuzzyLikeFuzziness :: Fuzziness
1146− , fuzzyLikePrefixLength :: PrefixLength
1147− , fuzzyLikeBoost :: Boost
1148− , fuzzyLikeAnalyzer :: Maybe Analyzer
1149− } deriving (Eq, Show)
1150−
1151−data FilteredQuery =
1152− FilteredQuery
1153− { filteredQuery :: Query
1154− , filteredFilter :: Filter } deriving (Eq, Show)
1155−
1156−data DisMaxQuery =
1157− DisMaxQuery { disMaxQueries :: [Query]
1158− -- default 0.0
1159− , disMaxTiebreaker :: Tiebreaker
1160− , disMaxBoost :: Maybe Boost
1161− } deriving (Eq, Show)
1162−
1163−data MatchQuery =
1164− MatchQuery { matchQueryField :: FieldName
1165− , matchQueryQueryString :: QueryString
1166− , matchQueryOperator :: BooleanOperator
1167− , matchQueryZeroTerms :: ZeroTermsQuery
1168− , matchQueryCutoffFrequency :: Maybe CutoffFrequency
1169− , matchQueryMatchType :: Maybe MatchQueryType
1170− , matchQueryAnalyzer :: Maybe Analyzer
1171− , matchQueryMaxExpansions :: Maybe MaxExpansions
1172− , matchQueryLenient :: Maybe Lenient
1173− , matchQueryBoost :: Maybe Boost } deriving (Eq, Show)
1174−
1175−{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
1176− enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
1177−-}
1178−mkMatchQuery :: FieldName -> QueryString -> MatchQuery
1179−mkMatchQuery field query = MatchQuery field query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
1180−
1181−data MatchQueryType =
1182− MatchPhrase
1183− | MatchPhrasePrefix deriving (Eq, Show)
1184−
1185−data MultiMatchQuery =
1186− MultiMatchQuery { multiMatchQueryFields :: [FieldName]
1187− , multiMatchQueryString :: QueryString
1188− , multiMatchQueryOperator :: BooleanOperator
1189− , multiMatchQueryZeroTerms :: ZeroTermsQuery
1190− , multiMatchQueryTiebreaker :: Maybe Tiebreaker
1191− , multiMatchQueryType :: Maybe MultiMatchQueryType
1192− , multiMatchQueryCutoffFrequency :: Maybe CutoffFrequency
1193− , multiMatchQueryAnalyzer :: Maybe Analyzer
1194− , multiMatchQueryMaxExpansions :: Maybe MaxExpansions
1195− , multiMatchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
1196−
1197−{-| 'mkMultiMatchQuery' is a convenience function that defaults the less common parameters,
1198− enabling you to provide only the list of 'FieldName's and 'QueryString' to
1199− make a 'MultiMatchQuery'.
1200−-}
1201−
1202−mkMultiMatchQuery :: [FieldName] -> QueryString -> MultiMatchQuery
1203−mkMultiMatchQuery matchFields query =
1204− MultiMatchQuery matchFields query
1205− Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
1206−
1207−data MultiMatchQueryType =
1208− MultiMatchBestFields
1209− | MultiMatchMostFields
1210− | MultiMatchCrossFields
1211− | MultiMatchPhrase
1212− | MultiMatchPhrasePrefix deriving (Eq, Show)
1213−
1214−data BoolQuery =
1215− BoolQuery { boolQueryMustMatch :: [Query]
1216− , boolQueryMustNotMatch :: [Query]
1217− , boolQueryShouldMatch :: [Query]
1218− , boolQueryMinimumShouldMatch :: Maybe MinimumMatch
1219− , boolQueryBoost :: Maybe Boost
1220− , boolQueryDisableCoord :: Maybe DisableCoord
1221− } deriving (Eq, Show)
1222−
1223−mkBoolQuery :: [Query] -> [Query] -> [Query] -> BoolQuery
1224−mkBoolQuery must mustNot should =
1225− BoolQuery must mustNot should Nothing Nothing Nothing
1226−
1227−data BoostingQuery =
1228− BoostingQuery { positiveQuery :: Query
1229− , negativeQuery :: Query
1230− , negativeBoost :: Boost } deriving (Eq, Show)
1231−
1232−data CommonTermsQuery =
1233− CommonTermsQuery { commonField :: FieldName
1234− , commonQuery :: QueryString
1235− , commonCutoffFrequency :: CutoffFrequency
1236− , commonLowFreqOperator :: BooleanOperator
1237− , commonHighFreqOperator :: BooleanOperator
1238− , commonMinimumShouldMatch :: Maybe CommonMinimumMatch
1239− , commonBoost :: Maybe Boost
1240− , commonAnalyzer :: Maybe Analyzer
1241− , commonDisableCoord :: Maybe DisableCoord
1242− } deriving (Eq, Show)
1243−
1244−data CommonMinimumMatch =
1245− CommonMinimumMatchHighLow MinimumMatchHighLow
1246− | CommonMinimumMatch MinimumMatch
1247− deriving (Eq, Show)
1248−
1249−data MinimumMatchHighLow =
1250− MinimumMatchHighLow { lowFreq :: MinimumMatch
1251− , highFreq :: MinimumMatch } deriving (Eq, Show)
1252−
1253−data Filter = AndFilter [Filter] Cache
1254− | OrFilter [Filter] Cache
1255− | NotFilter Filter Cache
1256− | IdentityFilter
1257− | BoolFilter BoolMatch
1258− | ExistsFilter FieldName -- always cached
1259− | GeoBoundingBoxFilter GeoBoundingBoxConstraint
1260− | GeoDistanceFilter GeoPoint Distance DistanceType OptimizeBbox Cache
1261− | GeoDistanceRangeFilter GeoPoint DistanceRange
1262− | GeoPolygonFilter FieldName [LatLon]
1263− | IdsFilter MappingName [DocId]
1264− | LimitFilter Int
1265− | MissingFilter FieldName Existence NullValue
1266− | PrefixFilter FieldName PrefixValue Cache
1267− | QueryFilter Query Cache
1268− | RangeFilter FieldName RangeValue RangeExecution Cache
1269− | RegexpFilter FieldName Regexp RegexpFlags CacheName Cache CacheKey
1270− | TermFilter Term Cache
1271− deriving (Eq, Show)
1272−
1273−data ZeroTermsQuery = ZeroTermsNone
1274− | ZeroTermsAll deriving (Eq, Show)
1275−
1276−data RangeExecution = RangeExecutionIndex
1277− | RangeExecutionFielddata deriving (Eq, Show)
1278−
1279−newtype Regexp = Regexp Text deriving (Eq, Show)
1280−
1281−data RegexpFlags = AllRegexpFlags
1282− | NoRegexpFlags
1283− | SomeRegexpFlags (NonEmpty RegexpFlag) deriving (Eq, Show)
1284−
1285−data RegexpFlag = AnyString
1286− | Automaton
1287− | Complement
1288− | Empty
1289− | Intersection
1290− | Interval deriving (Eq, Show)
1291−
1292−newtype LessThan = LessThan Double deriving (Eq, Show)
1293−newtype LessThanEq = LessThanEq Double deriving (Eq, Show)
1294−newtype GreaterThan = GreaterThan Double deriving (Eq, Show)
1295−newtype GreaterThanEq = GreaterThanEq Double deriving (Eq, Show)
1296−
1297−newtype LessThanD = LessThanD UTCTime deriving (Eq, Show)
1298−newtype LessThanEqD = LessThanEqD UTCTime deriving (Eq, Show)
1299−newtype GreaterThanD = GreaterThanD UTCTime deriving (Eq, Show)
1300−newtype GreaterThanEqD = GreaterThanEqD UTCTime deriving (Eq, Show)
1301−
1302−data RangeValue = RangeDateLte LessThanEqD
1303− | RangeDateLt LessThanD
1304− | RangeDateGte GreaterThanEqD
1305− | RangeDateGt GreaterThanD
1306− | RangeDateGtLt GreaterThanD LessThanD
1307− | RangeDateGteLte GreaterThanEqD LessThanEqD
1308− | RangeDateGteLt GreaterThanEqD LessThanD
1309− | RangeDateGtLte GreaterThanD LessThanEqD
1310− | RangeDoubleLte LessThanEq
1311− | RangeDoubleLt LessThan
1312− | RangeDoubleGte GreaterThanEq
1313− | RangeDoubleGt GreaterThan
1314− | RangeDoubleGtLt GreaterThan LessThan
1315− | RangeDoubleGteLte GreaterThanEq LessThanEq
1316− | RangeDoubleGteLt GreaterThanEq LessThan
1317− | RangeDoubleGtLte GreaterThan LessThanEq
1318− deriving (Eq, Show)
1319−
1320−rangeValueToPair :: RangeValue -> [Pair]
1321−rangeValueToPair rv = case rv of
1322− RangeDateLte (LessThanEqD t) -> ["lte" .= t]
1323− RangeDateGte (GreaterThanEqD t) -> ["gte" .= t]
1324− RangeDateLt (LessThanD t) -> ["lt" .= t]
1325− RangeDateGt (GreaterThanD t) -> ["gt" .= t]
1326− RangeDateGteLte (GreaterThanEqD l) (LessThanEqD g) -> ["gte" .= l, "lte" .= g]
1327− RangeDateGtLte (GreaterThanD l) (LessThanEqD g) -> ["gt" .= l, "lte" .= g]
1328− RangeDateGteLt (GreaterThanEqD l) (LessThanD g) -> ["gte" .= l, "lt" .= g]
1329− RangeDateGtLt (GreaterThanD l) (LessThanD g) -> ["gt" .= l, "lt" .= g]
1330− RangeDoubleLte (LessThanEq t) -> ["lte" .= t]
1331− RangeDoubleGte (GreaterThanEq t) -> ["gte" .= t]
1332− RangeDoubleLt (LessThan t) -> ["lt" .= t]
1333− RangeDoubleGt (GreaterThan t) -> ["gt" .= t]
1334− RangeDoubleGteLte (GreaterThanEq l) (LessThanEq g) -> ["gte" .= l, "lte" .= g]
1335− RangeDoubleGtLte (GreaterThan l) (LessThanEq g) -> ["gt" .= l, "lte" .= g]
1336− RangeDoubleGteLt (GreaterThanEq l) (LessThan g) -> ["gte" .= l, "lt" .= g]
1337− RangeDoubleGtLt (GreaterThan l) (LessThan g) -> ["gt" .= l, "lt" .= g]
1338−
1339−data Term = Term { termField :: Text
1340− , termValue :: Text } deriving (Eq, Show)
1341−
1342−data BoolMatch = MustMatch Term Cache
1343− | MustNotMatch Term Cache
1344− | ShouldMatch [Term] Cache deriving (Eq, Show)
1345−
1346−-- "memory" or "indexed"
1347−data GeoFilterType = GeoFilterMemory
1348− | GeoFilterIndexed deriving (Eq, Show)
1349−
1350−data LatLon = LatLon { lat :: Double
1351− , lon :: Double } deriving (Eq, Show)
1352−
1353−data GeoBoundingBox =
1354− GeoBoundingBox { topLeft :: LatLon
1355− , bottomRight :: LatLon } deriving (Eq, Show)
1356−
1357−data GeoBoundingBoxConstraint =
1358− GeoBoundingBoxConstraint { geoBBField :: FieldName
1359− , constraintBox :: GeoBoundingBox
1360− , bbConstraintcache :: Cache
1361− , geoType :: GeoFilterType
1362− } deriving (Eq, Show)
1363−
1364−data GeoPoint =
1365− GeoPoint { geoField :: FieldName
1366− , latLon :: LatLon} deriving (Eq, Show)
1367−
1368−data DistanceUnit = Miles
1369− | Yards
1370− | Feet
1371− | Inches
1372− | Kilometers
1373− | Meters
1374− | Centimeters
1375− | Millimeters
1376− | NauticalMiles deriving (Eq, Show)
1377−
1378−data DistanceType = Arc
1379− | SloppyArc -- doesn't exist <1.0
1380− | Plane deriving (Eq, Show)
1381−
1382−data OptimizeBbox = OptimizeGeoFilterType GeoFilterType
1383− | NoOptimizeBbox deriving (Eq, Show)
1384−
1385−data Distance =
1386− Distance { coefficient :: Double
1387− , unit :: DistanceUnit } deriving (Eq, Show)
1388−
1389−data DistanceRange =
1390− DistanceRange { distanceFrom :: Distance
1391− , distanceTo :: Distance } deriving (Eq, Show)
1392−
1393−data SearchResult a =
1394− SearchResult { took :: Int
1395− , timedOut :: Bool
1396− , shards :: ShardResult
1397− , searchHits :: SearchHits a
1398− , aggregations :: Maybe AggregationResults
1399− , scrollId :: Maybe ScrollId } deriving (Eq, Show)
1400−
1401−type ScrollId = Text -- Fixme: Newtype
1402−
1403−type Score = Maybe Double
1404−
1405−data SearchHits a =
1406− SearchHits { hitsTotal :: Int
1407− , maxScore :: Score
1408− , hits :: [Hit a] } deriving (Eq, Show)
1409−
1410−
1411−instance Monoid (SearchHits a) where
1412− mempty = SearchHits 0 Nothing mempty
1413− mappend (SearchHits ta ma ha) (SearchHits tb mb hb) =
1414− SearchHits (ta + tb) (max ma mb) (ha <> hb)
1415−
1416−
1417−data Hit a =
1418− Hit { hitIndex :: IndexName
1419− , hitType :: MappingName
1420− , hitDocId :: DocId
1421− , hitScore :: Score
1422− , hitSource :: Maybe a
1423− , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show)
1424−
1425−data ShardResult =
1426− ShardResult { shardTotal :: Int
1427− , shardsSuccessful :: Int
1428− , shardsFailed :: Int } deriving (Eq, Show, Generic)
1429−
1430−type HitHighlight = M.Map Text [Text]
1431−
1432−showText :: Show a => a -> Text
1433−showText = T.pack . show
1434−
1435−type Aggregations = M.Map Text Aggregation
1436−
1437−emptyAggregations :: Aggregations
1438−emptyAggregations = M.empty
1439−
1440−mkAggregations :: Text -> Aggregation -> Aggregations
1441−mkAggregations name aggregation = M.insert name aggregation emptyAggregations
1442−
1443−data TermOrder = TermOrder{ termSortField :: Text
1444− , termSortOrder :: SortOrder } deriving (Eq, Show)
1445−
1446−data TermInclusion = TermInclusion Text
1447− | TermPattern Text Text deriving (Eq, Show)
1448−
1449−data CollectionMode = BreadthFirst
1450− | DepthFirst deriving (Eq, Show)
1451−
1452−data ExecutionHint = Ordinals
1453− | GlobalOrdinals
1454− | GlobalOrdinalsHash
1455− | GlobalOrdinalsLowCardinality
1456− | Map deriving (Eq, Show)
1457−
1458−data TimeInterval = Weeks
1459− | Days
1460− | Hours
1461− | Minutes
1462− | Seconds deriving (Eq)
1463−
1464−data Interval = Year
1465− | Quarter
1466− | Month
1467− | Week
1468− | Day
1469− | Hour
1470− | Minute
1471− | Second
1472− | FractionalInterval Float TimeInterval deriving (Eq, Show)
1473−
1474−data Aggregation = TermsAgg TermsAggregation
1475− | DateHistogramAgg DateHistogramAggregation
1476− | ValueCountAgg ValueCountAggregation
1477− | FilterAgg FilterAggregation deriving (Eq, Show)
1478−
1479−
1480−data TermsAggregation = TermsAggregation { term :: Either Text Text
1481− , termInclude :: Maybe TermInclusion
1482− , termExclude :: Maybe TermInclusion
1483− , termOrder :: Maybe TermOrder
1484− , termMinDocCount :: Maybe Int
1485− , termSize :: Maybe Int
1486− , termShardSize :: Maybe Int
1487− , termCollectMode :: Maybe CollectionMode
1488− , termExecutionHint :: Maybe ExecutionHint
1489− , termAggs :: Maybe Aggregations
1490− } deriving (Eq, Show)
1491−
1492−data DateHistogramAggregation = DateHistogramAggregation { dateField :: FieldName
1493− , dateInterval :: Interval
1494− , dateFormat :: Maybe Text
1495− -- pre and post deprecated in 1.5
1496− , datePreZone :: Maybe Text
1497− , datePostZone :: Maybe Text
1498− , datePreOffset :: Maybe Text
1499− , datePostOffset :: Maybe Text
1500− , dateAggs :: Maybe Aggregations
1501− } deriving (Eq, Show)
1502−
1503−-- | See <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html> for more information.
1504−data ValueCountAggregation = FieldValueCount FieldName
1505− | ScriptValueCount Script deriving (Eq, Show)
1506−
1507−-- | 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.
1508−data FilterAggregation = FilterAggregation { faFilter :: Filter
1509− , faAggs :: Maybe Aggregations} deriving (Eq, Show)
1510−
1511−mkTermsAggregation :: Text -> TermsAggregation
1512−mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1513−
1514−mkTermsScriptAggregation :: Text -> TermsAggregation
1515−mkTermsScriptAggregation t = TermsAggregation (Right t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1516−
1517−mkDateHistogram :: FieldName -> Interval -> DateHistogramAggregation
1518−mkDateHistogram t i = DateHistogramAggregation t i Nothing Nothing Nothing Nothing Nothing Nothing
1519−
1520−instance ToJSON TermOrder where
1521− toJSON (TermOrder termSortField termSortOrder) = object [termSortField .= termSortOrder]
1522−
1523−instance ToJSON TermInclusion where
1524− toJSON (TermInclusion x) = toJSON x
1525− toJSON (TermPattern pattern flags) = omitNulls [ "pattern" .= pattern,
1526− "flags" .= flags]
1527−
1528−instance ToJSON CollectionMode where
1529− toJSON BreadthFirst = "breadth_first"
1530− toJSON DepthFirst = "depth_first"
1531−
1532−instance ToJSON ExecutionHint where
1533− toJSON Ordinals = "ordinals"
1534− toJSON GlobalOrdinals = "global_ordinals"
1535− toJSON GlobalOrdinalsHash = "global_ordinals_hash"
1536− toJSON GlobalOrdinalsLowCardinality = "global_ordinals_low_cardinality"
1537− toJSON Map = "map"
1538−
1539−instance ToJSON Interval where
1540− toJSON Year = "year"
1541− toJSON Quarter = "quarter"
1542− toJSON Month = "month"
1543− toJSON Week = "week"
1544− toJSON Day = "day"
1545− toJSON Hour = "hour"
1546− toJSON Minute = "minute"
1547− toJSON Second = "second"
1548− toJSON (FractionalInterval fraction interval) = toJSON $ show fraction ++ show interval
1549−
1550−instance Show TimeInterval where
1551− show Weeks = "w"
1552− show Days = "d"
1553− show Hours = "h"
1554− show Minutes = "m"
1555− show Seconds = "s"
1556−
1557−instance ToJSON Aggregation where
1558− toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1559− omitNulls ["terms" .= omitNulls [ toJSON' term,
1560− "include" .= include,
1561− "exclude" .= exclude,
1562− "order" .= order,
1563− "min_doc_count" .= minDocCount,
1564− "size" .= size,
1565− "shard_size" .= shardSize,
1566− "collect_mode" .= collectMode,
1567− "execution_hint" .= executionHint
1568− ],
1569− "aggs" .= termAggs ]
1570− where
1571− toJSON' x = case x of { Left y -> "field" .= y; Right y -> "script" .= y }
1572−
1573− toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
1574− omitNulls ["date_histogram" .= omitNulls [ "field" .= field,
1575− "interval" .= interval,
1576− "format" .= format,
1577− "pre_zone" .= preZone,
1578− "post_zone" .= postZone,
1579− "pre_offset" .= preOffset,
1580− "post_offset" .= postOffset
1581− ],
1582− "aggs" .= dateHistoAggs ]
1583− toJSON (ValueCountAgg a) = object ["value_count" .= v]
1584− where v = case a of
1585− (FieldValueCount (FieldName n)) -> object ["field" .= n]
1586− (ScriptValueCount (Script s)) -> object ["script" .= s]
1587− toJSON (FilterAgg (FilterAggregation filt ags)) =
1588− omitNulls [ "filter" .= filt
1589− , "aggs" .= ags]
1590−
1591−type AggregationResults = M.Map Text Value
1592−
1593−class BucketAggregation a where
1594− key :: a -> Text
1595− docCount :: a -> Int
1596− aggs :: a -> Maybe AggregationResults
1597−
1598−
1599−data Bucket a = Bucket { buckets :: [a]} deriving (Show)
1600−
1601−data TermsResult = TermsResult { termKey :: Text
1602− , termsDocCount :: Int
1603− , termsAggs :: Maybe AggregationResults } deriving (Show)
1604−
1605−data DateHistogramResult = DateHistogramResult { dateKey :: Int
1606− , dateKeyStr :: Maybe Text
1607− , dateDocCount :: Int
1608− , dateHistogramAggs :: Maybe AggregationResults } deriving (Show)
1609−
1610−toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1611−toTerms t a = M.lookup t a >>= deserialize
1612− where deserialize = parseMaybe parseJSON
1613−
1614−toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1615−toDateHistogram t a = M.lookup t a >>= deserialize
1616− where deserialize = parseMaybe parseJSON
1617−
1618−instance BucketAggregation TermsResult where
1619− key = termKey
1620− docCount = termsDocCount
1621− aggs = termsAggs
1622−
1623−instance BucketAggregation DateHistogramResult where
1624− key = showText . dateKey
1625− docCount = dateDocCount
1626− aggs = dateHistogramAggs
1627−
1628−instance (FromJSON a, BucketAggregation a) => FromJSON (Bucket a) where
1629− parseJSON (Object v) = Bucket <$>
1630− v .: "buckets"
1631− parseJSON _ = mempty
1632−
1633−instance FromJSON TermsResult where
1634− parseJSON (Object v) = TermsResult <$>
1635− v .: "key" <*>
1636− v .: "doc_count" <*>
1637− v .:? "aggregations"
1638− parseJSON _ = mempty
1639−
1640−instance FromJSON DateHistogramResult where
1641− parseJSON (Object v) = DateHistogramResult <$>
1642− v .: "key" <*>
1643− v .:? "key_as_string" <*>
1644− v .: "doc_count" <*>
1645− v .:? "aggregations"
1646− parseJSON _ = mempty
1647−
1648−instance Monoid Filter where
1649− mempty = IdentityFilter
1650− mappend a b = AndFilter [a, b] defaultCache
1651−
1652−instance Seminearring Filter where
1653− a <||> b = OrFilter [a, b] defaultCache
1654−
1655−instance ToJSON Filter where
1656− toJSON (AndFilter filters cache) =
1657− object ["and" .=
1658− object [ "filters" .= fmap toJSON filters
1659− , "_cache" .= cache]]
1660−
1661− toJSON (OrFilter filters cache) =
1662− object ["or" .=
1663− object [ "filters" .= fmap toJSON filters
1664− , "_cache" .= cache]]
1665−
1666− toJSON (NotFilter notFilter cache) =
1667− object ["not" .=
1668− object ["filter" .= notFilter
1669− , "_cache" .= cache]]
1670−
1671− toJSON (IdentityFilter) =
1672− object ["match_all" .= object []]
1673−
1674− toJSON (TermFilter (Term termFilterField termFilterValue) cache) =
1675− object ["term" .= object base]
1676− where base = [termFilterField .= termFilterValue,
1677− "_cache" .= cache]
1678−
1679− toJSON (ExistsFilter (FieldName fieldName)) =
1680− object ["exists" .= object
1681− ["field" .= fieldName]]
1682−
1683− toJSON (BoolFilter boolMatch) =
1684− object ["bool" .= boolMatch]
1685−
1686− toJSON (GeoBoundingBoxFilter bbConstraint) =
1687− object ["geo_bounding_box" .= bbConstraint]
1688−
1689− toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1690− distance distanceType optimizeBbox cache) =
1691− object ["geo_distance" .=
1692− object ["distance" .= distance
1693− , "distance_type" .= distanceType
1694− , "optimize_bbox" .= optimizeBbox
1695− , distanceGeoField .= geoDistLatLon
1696− , "_cache" .= cache]]
1697−
1698− toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1699− (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1700− object ["geo_distance_range" .=
1701− object ["from" .= geoDistRangeDistFrom
1702− , "to" .= drDistanceTo
1703− , gddrField .= drLatLon]]
1704−
1705− toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1706− object ["geo_polygon" .=
1707− object [geoPolygonFilterField .=
1708− object ["points" .= fmap toJSON latLons]]]
1709−
1710− toJSON (IdsFilter (MappingName mappingName) values) =
1711− object ["ids" .=
1712− object ["type" .= mappingName
1713− , "values" .= fmap unpackId values]]
1714−
1715− toJSON (LimitFilter limit) =
1716− object ["limit" .= object ["value" .= limit]]
1717−
1718− toJSON (MissingFilter (FieldName fieldName) (Existence existence) (NullValue nullValue)) =
1719− object ["missing" .=
1720− object ["field" .= fieldName
1721− , "existence" .= existence
1722− , "null_value" .= nullValue]]
1723−
1724− toJSON (PrefixFilter (FieldName fieldName) fieldValue cache) =
1725− object ["prefix" .=
1726− object [fieldName .= fieldValue
1727− , "_cache" .= cache]]
1728−
1729− toJSON (QueryFilter query False) =
1730− object ["query" .= toJSON query ]
1731− toJSON (QueryFilter query True) =
1732− object ["fquery" .=
1733− object [ "query" .= toJSON query
1734− , "_cache" .= True ]]
1735−
1736− toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1737− object ["range" .=
1738− object [ fieldName .= object (rangeValueToPair rangeValue)
1739− , "execution" .= rangeExecution
1740− , "_cache" .= cache]]
1741−
1742− toJSON (RegexpFilter (FieldName fieldName)
1743− (Regexp regexText) flags (CacheName cacheName) cache (CacheKey cacheKey)) =
1744− object ["regexp" .=
1745− object [fieldName .=
1746− object ["value" .= regexText
1747− , "flags" .= flags]
1748− , "_name" .= cacheName
1749− , "_cache" .= cache
1750− , "_cache_key" .= cacheKey]]
1751−
1752−instance ToJSON GeoPoint where
1753− toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1754− object [ geoPointField .= geoPointLatLon ]
1755−
1756−
1757−instance ToJSON Query where
1758− toJSON (TermQuery (Term termQueryField termQueryValue) boost) =
1759− object [ "term" .=
1760− object [termQueryField .= object merged]]
1761− where
1762− base = [ "value" .= termQueryValue ]
1763− boosted = maybe [] (return . ("boost" .=)) boost
1764− merged = mappend base boosted
1765−
1766− toJSON (TermsQuery terms) =
1767− object [ "terms" .= object conjoined ]
1768− where conjoined = [ getTermsField terms .=
1769− fmap (toJSON . getTermValue) (toList terms)]
1770− getTermsField ((Term f _ ) :| _) = f
1771− getTermValue (Term _ v) = v
1772− toJSON (IdsQuery idsQueryMappingName docIds) =
1773− object [ "ids" .= object conjoined ]
1774− where conjoined = [ "type" .= idsQueryMappingName
1775− , "values" .= fmap toJSON docIds ]
1776−
1777− toJSON (QueryQueryStringQuery qQueryStringQuery) =
1778− object [ "query_string" .= qQueryStringQuery ]
1779−
1780− toJSON (QueryMatchQuery matchQuery) =
1781− object [ "match" .= matchQuery ]
1782−
1783− toJSON (QueryMultiMatchQuery multiMatchQuery) =
1784− toJSON multiMatchQuery
1785−
1786− toJSON (QueryBoolQuery boolQuery) =
1787− object [ "bool" .= boolQuery ]
1788−
1789− toJSON (QueryBoostingQuery boostingQuery) =
1790− object [ "boosting" .= boostingQuery ]
1791−
1792− toJSON (QueryCommonTermsQuery commonTermsQuery) =
1793− object [ "common" .= commonTermsQuery ]
1794−
1795− toJSON (ConstantScoreFilter csFilter boost) =
1796− object [ "constant_score" .= csFilter
1797− , "boost" .= boost]
1798−
1799− toJSON (ConstantScoreQuery query boost) =
1800− object [ "constant_score" .= query
1801− , "boost" .= boost]
1802−
1803− toJSON (QueryDisMaxQuery disMaxQuery) =
1804− object [ "dis_max" .= disMaxQuery ]
1805−
1806− toJSON (QueryFilteredQuery qFilteredQuery) =
1807− object [ "filtered" .= qFilteredQuery ]
1808−
1809− toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1810− object [ "fuzzy_like_this" .= fuzzyQuery ]
1811−
1812− toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1813− object [ "fuzzy_like_this_field" .= fuzzyFieldQuery ]
1814−
1815− toJSON (QueryFuzzyQuery fuzzyQuery) =
1816− object [ "fuzzy" .= fuzzyQuery ]
1817−
1818− toJSON (QueryHasChildQuery childQuery) =
1819− object [ "has_child" .= childQuery ]
1820−
1821− toJSON (QueryHasParentQuery parentQuery) =
1822− object [ "has_parent" .= parentQuery ]
1823−
1824− toJSON (QueryIndicesQuery qIndicesQuery) =
1825− object [ "indices" .= qIndicesQuery ]
1826−
1827− toJSON (MatchAllQuery boost) =
1828− object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1829−
1830− toJSON (QueryMoreLikeThisQuery query) =
1831− object [ "more_like_this" .= query ]
1832−
1833− toJSON (QueryMoreLikeThisFieldQuery query) =
1834− object [ "more_like_this_field" .= query ]
1835−
1836− toJSON (QueryNestedQuery query) =
1837− object [ "nested" .= query ]
1838−
1839− toJSON (QueryPrefixQuery query) =
1840− object [ "prefix" .= query ]
1841−
1842− toJSON (QueryRangeQuery query) =
1843− object [ "range" .= query ]
1844−
1845− toJSON (QueryRegexpQuery query) =
1846− object [ "regexp" .= query ]
1847−
1848− toJSON (QuerySimpleQueryStringQuery query) =
1849− object [ "simple_query_string" .= query ]
1850−
1851−
1852−omitNulls :: [(Text, Value)] -> Value
1853−omitNulls = object . filter notNull where
1854− notNull (_, Null) = False
1855− notNull (_, Array a) = (not . V.null) a
1856− notNull _ = True
1857−
1858−
1859−instance ToJSON SimpleQueryStringQuery where
1860− toJSON SimpleQueryStringQuery {..} =
1861− omitNulls (base ++ maybeAdd)
1862− where base = [ "query" .= simpleQueryStringQuery ]
1863− maybeAdd = [ "fields" .= simpleQueryStringField
1864− , "default_operator" .= simpleQueryStringOperator
1865− , "analyzer" .= simpleQueryStringAnalyzer
1866− , "flags" .= simpleQueryStringFlags
1867− , "lowercase_expanded_terms" .= simpleQueryStringLowercaseExpanded
1868− , "locale" .= simpleQueryStringLocale ]
1869−
1870−
1871−instance ToJSON FieldOrFields where
1872− toJSON (FofField fieldName) =
1873− toJSON fieldName
1874− toJSON (FofFields fieldNames) =
1875− toJSON fieldNames
1876−
1877−instance ToJSON SimpleQueryFlag where
1878− toJSON SimpleQueryAll = "ALL"
1879− toJSON SimpleQueryNone = "NONE"
1880− toJSON SimpleQueryAnd = "AND"
1881− toJSON SimpleQueryOr = "OR"
1882− toJSON SimpleQueryPrefix = "PREFIX"
1883− toJSON SimpleQueryPhrase = "PHRASE"
1884− toJSON SimpleQueryPrecedence = "PRECEDENCE"
1885− toJSON SimpleQueryEscape = "ESCAPE"
1886− toJSON SimpleQueryWhitespace = "WHITESPACE"
1887− toJSON SimpleQueryFuzzy = "FUZZY"
1888− toJSON SimpleQueryNear = "NEAR"
1889− toJSON SimpleQuerySlop = "SLOP"
1890−
1891−
1892−instance ToJSON RegexpQuery where
1893− toJSON (RegexpQuery (FieldName rqQueryField)
1894− (Regexp regexpQueryQuery) rqQueryFlags
1895− rqQueryBoost) =
1896− object [ rqQueryField .= omitNulls base ]
1897− where base = [ "value" .= regexpQueryQuery
1898− , "flags" .= rqQueryFlags
1899− , "boost" .= rqQueryBoost ]
1900−
1901−
1902−instance ToJSON QueryStringQuery where
1903− toJSON (QueryStringQuery qsQueryString
1904− qsDefaultField qsOperator
1905− qsAnalyzer qsAllowWildcard
1906− qsLowercaseExpanded qsEnablePositionIncrements
1907− qsFuzzyMaxExpansions qsFuzziness
1908− qsFuzzyPrefixLength qsPhraseSlop
1909− qsBoost qsAnalyzeWildcard
1910− qsGeneratePhraseQueries qsMinimumShouldMatch
1911− qsLenient qsLocale) =
1912− omitNulls base
1913− where
1914− base = [ "query" .= qsQueryString
1915− , "default_field" .= qsDefaultField
1916− , "default_operator" .= qsOperator
1917− , "analyzer" .= qsAnalyzer
1918− , "allow_leading_wildcard" .= qsAllowWildcard
1919− , "lowercase_expanded_terms" .= qsLowercaseExpanded
1920− , "enable_position_increments" .= qsEnablePositionIncrements
1921− , "fuzzy_max_expansions" .= qsFuzzyMaxExpansions
1922− , "fuzziness" .= qsFuzziness
1923− , "fuzzy_prefix_length" .= qsFuzzyPrefixLength
1924− , "phrase_slop" .= qsPhraseSlop
1925− , "boost" .= qsBoost
1926− , "analyze_wildcard" .= qsAnalyzeWildcard
1927− , "auto_generate_phrase_queries" .= qsGeneratePhraseQueries
1928− , "minimum_should_match" .= qsMinimumShouldMatch
1929− , "lenient" .= qsLenient
1930− , "locale" .= qsLocale ]
1931−
1932−
1933−instance ToJSON RangeQuery where
1934− toJSON (RangeQuery (FieldName fieldName) range boost) =
1935− object [ fieldName .= conjoined ]
1936− where conjoined = [ "boost" .= boost ] ++ (rangeValueToPair range)
1937−
1938−
1939−instance ToJSON PrefixQuery where
1940− toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1941− object [ fieldName .= omitNulls base ]
1942− where base = [ "value" .= queryValue
1943− , "boost" .= boost ]
1944−
1945−
1946−instance ToJSON NestedQuery where
1947− toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1948− object [ "path" .= nqPath
1949− , "score_mode" .= nqScoreType
1950− , "query" .= nqQuery ]
1951−
1952−
1953−instance ToJSON MoreLikeThisFieldQuery where
1954− toJSON (MoreLikeThisFieldQuery text (FieldName fieldName)
1955− percent mtf mqt stopwords mindf maxdf
1956− minwl maxwl boostTerms boost analyzer) =
1957− object [ fieldName .= omitNulls base ]
1958− where base = [ "like_text" .= text
1959− , "percent_terms_to_match" .= percent
1960− , "min_term_freq" .= mtf
1961− , "max_query_terms" .= mqt
1962− , "stop_words" .= stopwords
1963− , "min_doc_freq" .= mindf
1964− , "max_doc_freq" .= maxdf
1965− , "min_word_length" .= minwl
1966− , "max_word_length" .= maxwl
1967− , "boost_terms" .= boostTerms
1968− , "boost" .= boost
1969− , "analyzer" .= analyzer ]
1970−
1971−
1972−instance ToJSON MoreLikeThisQuery where
1973− toJSON (MoreLikeThisQuery text fields percent
1974− mtf mqt stopwords mindf maxdf
1975− minwl maxwl boostTerms boost analyzer) =
1976− omitNulls base
1977− where base = [ "like_text" .= text
1978− , "fields" .= fields
1979− , "percent_terms_to_match" .= percent
1980− , "min_term_freq" .= mtf
1981− , "max_query_terms" .= mqt
1982− , "stop_words" .= stopwords
1983− , "min_doc_freq" .= mindf
1984− , "max_doc_freq" .= maxdf
1985− , "min_word_length" .= minwl
1986− , "max_word_length" .= maxwl
1987− , "boost_terms" .= boostTerms
1988− , "boost" .= boost
1989− , "analyzer" .= analyzer ]
1990−
1991−
1992−instance ToJSON IndicesQuery where
1993− toJSON (IndicesQuery indices query noMatch) =
1994− omitNulls [ "indices" .= indices
1995− , "no_match_query" .= noMatch
1996− , "query" .= query ]
1997−
1998−
1999−instance ToJSON HasParentQuery where
2000− toJSON (HasParentQuery queryType query scoreType) =
2001− omitNulls [ "parent_type" .= queryType
2002− , "score_type" .= scoreType
2003− , "query" .= query ]
2004−
2005−
2006−instance ToJSON HasChildQuery where
2007− toJSON (HasChildQuery queryType query scoreType) =
2008− omitNulls [ "query" .= query
2009− , "score_type" .= scoreType
2010− , "type" .= queryType ]
2011−
2012−
2013−instance ToJSON FuzzyQuery where
2014− toJSON (FuzzyQuery (FieldName fieldName) queryText
2015− prefixLength maxEx fuzziness boost) =
2016− object [ fieldName .= omitNulls base ]
2017− where base = [ "value" .= queryText
2018− , "fuzziness" .= fuzziness
2019− , "prefix_length" .= prefixLength
2020− , "boost" .= boost
2021− , "max_expansions" .= maxEx ]
2022−
2023−
2024−instance ToJSON FuzzyLikeFieldQuery where
2025− toJSON (FuzzyLikeFieldQuery (FieldName fieldName)
2026− fieldText maxTerms ignoreFreq fuzziness prefixLength
2027− boost analyzer) =
2028− object [ fieldName .=
2029− omitNulls [ "like_text" .= fieldText
2030− , "max_query_terms" .= maxTerms
2031− , "ignore_tf" .= ignoreFreq
2032− , "fuzziness" .= fuzziness
2033− , "prefix_length" .= prefixLength
2034− , "analyzer" .= analyzer
2035− , "boost" .= boost ]]
2036−
2037−
2038−instance ToJSON FuzzyLikeThisQuery where
2039− toJSON (FuzzyLikeThisQuery fields text maxTerms
2040− ignoreFreq fuzziness prefixLength boost analyzer) =
2041− omitNulls base
2042− where base = [ "fields" .= fields
2043− , "like_text" .= text
2044− , "max_query_terms" .= maxTerms
2045− , "ignore_tf" .= ignoreFreq
2046− , "fuzziness" .= fuzziness
2047− , "prefix_length" .= prefixLength
2048− , "analyzer" .= analyzer
2049− , "boost" .= boost ]
2050−
2051−
2052−instance ToJSON FilteredQuery where
2053− toJSON (FilteredQuery query fFilter) =
2054− object [ "query" .= query
2055− , "filter" .= fFilter ]
2056−
2057−
2058−instance ToJSON DisMaxQuery where
2059− toJSON (DisMaxQuery queries tiebreaker boost) =
2060− omitNulls base
2061− where base = [ "queries" .= queries
2062− , "boost" .= boost
2063− , "tie_breaker" .= tiebreaker ]
2064−
2065−
2066−instance ToJSON CommonTermsQuery where
2067− toJSON (CommonTermsQuery (FieldName fieldName)
2068− (QueryString query) cf lfo hfo msm
2069− boost analyzer disableCoord) =
2070− object [fieldName .= omitNulls base ]
2071− where base = [ "query" .= query
2072− , "cutoff_frequency" .= cf
2073− , "low_freq_operator" .= lfo
2074− , "minimum_should_match" .= msm
2075− , "boost" .= boost
2076− , "analyzer" .= analyzer
2077− , "disable_coord" .= disableCoord
2078− , "high_freq_operator" .= hfo ]
2079−
2080−
2081−instance ToJSON CommonMinimumMatch where
2082− toJSON (CommonMinimumMatch mm) = toJSON mm
2083− toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
2084− object [ "low_freq" .= lowF
2085− , "high_freq" .= highF ]
2086−
2087−instance ToJSON BoostingQuery where
2088− toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
2089− object [ "positive" .= bqPositiveQuery
2090− , "negative" .= bqNegativeQuery
2091− , "negative_boost" .= bqNegativeBoost ]
2092−
2093−
2094−instance ToJSON BoolQuery where
2095− toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
2096− omitNulls base
2097− where base = [ "must" .= mustM
2098− , "must_not" .= notM
2099− , "should" .= shouldM
2100− , "minimum_should_match" .= bqMin
2101− , "boost" .= boost
2102− , "disable_coord" .= disableCoord ]
2103−
2104−
2105−instance ToJSON MatchQuery where
2106− toJSON (MatchQuery (FieldName fieldName)
2107− (QueryString mqQueryString) booleanOperator
2108− zeroTermsQuery cutoffFrequency matchQueryType
2109− analyzer maxExpansions lenient boost) =
2110− object [ fieldName .= omitNulls base ]
2111− where base = [ "query" .= mqQueryString
2112− , "operator" .= booleanOperator
2113− , "zero_terms_query" .= zeroTermsQuery
2114− , "cutoff_frequency" .= cutoffFrequency
2115− , "type" .= matchQueryType
2116− , "analyzer" .= analyzer
2117− , "max_expansions" .= maxExpansions
2118− , "lenient" .= lenient
2119− , "boost" .= boost ]
2120−
2121−
2122−instance ToJSON MultiMatchQuery where
2123− toJSON (MultiMatchQuery fields (QueryString query) boolOp
2124− ztQ tb mmqt cf analyzer maxEx lenient) =
2125− object ["multi_match" .= omitNulls base]
2126− where base = [ "fields" .= fmap toJSON fields
2127− , "query" .= query
2128− , "operator" .= boolOp
2129− , "zero_terms_query" .= ztQ
2130− , "tiebreaker" .= tb
2131− , "type" .= mmqt
2132− , "cutoff_frequency" .= cf
2133− , "analyzer" .= analyzer
2134− , "max_expansions" .= maxEx
2135− , "lenient" .= lenient ]
2136−
2137−
2138−instance ToJSON MultiMatchQueryType where
2139− toJSON MultiMatchBestFields = "best_fields"
2140− toJSON MultiMatchMostFields = "most_fields"
2141− toJSON MultiMatchCrossFields = "cross_fields"
2142− toJSON MultiMatchPhrase = "phrase"
2143− toJSON MultiMatchPhrasePrefix = "phrase_prefix"
2144−
2145−instance ToJSON BooleanOperator where
2146− toJSON And = String "and"
2147− toJSON Or = String "or"
2148−
2149−instance ToJSON ZeroTermsQuery where
2150− toJSON ZeroTermsNone = String "none"
2151− toJSON ZeroTermsAll = String "all"
2152−
2153−instance ToJSON MatchQueryType where
2154− toJSON MatchPhrase = "phrase"
2155− toJSON MatchPhrasePrefix = "phrase_prefix"
2156−
2157−instance ToJSON FieldName where
2158− toJSON (FieldName fieldName) = String fieldName
2159−
2160−instance ToJSON ReplicaCount where
2161− toJSON = genericToJSON defaultOptions
2162−instance ToJSON ShardCount where
2163− toJSON = genericToJSON defaultOptions
2164−instance ToJSON CutoffFrequency where
2165− toJSON = genericToJSON defaultOptions
2166−instance ToJSON Analyzer where
2167− toJSON = genericToJSON defaultOptions
2168−instance ToJSON MaxExpansions where
2169− toJSON = genericToJSON defaultOptions
2170−instance ToJSON Lenient where
2171− toJSON = genericToJSON defaultOptions
2172−instance ToJSON Boost where
2173− toJSON = genericToJSON defaultOptions
2174−instance ToJSON Version where
2175− toJSON = genericToJSON defaultOptions
2176−instance ToJSON Tiebreaker where
2177− toJSON = genericToJSON defaultOptions
2178−instance ToJSON MinimumMatch where
2179− toJSON = genericToJSON defaultOptions
2180−instance ToJSON DisableCoord where
2181− toJSON = genericToJSON defaultOptions
2182−instance ToJSON PrefixLength where
2183− toJSON = genericToJSON defaultOptions
2184−instance ToJSON Fuzziness where
2185− toJSON = genericToJSON defaultOptions
2186−instance ToJSON IgnoreTermFrequency where
2187− toJSON = genericToJSON defaultOptions
2188−instance ToJSON MaxQueryTerms where
2189− toJSON = genericToJSON defaultOptions
2190−instance ToJSON TypeName where
2191− toJSON = genericToJSON defaultOptions
2192−instance ToJSON IndexName where
2193− toJSON = genericToJSON defaultOptions
2194−instance ToJSON TemplateName where
2195− toJSON = genericToJSON defaultOptions
2196−instance ToJSON TemplatePattern where
2197− toJSON = genericToJSON defaultOptions
2198−instance ToJSON BoostTerms where
2199− toJSON = genericToJSON defaultOptions
2200−instance ToJSON MaxWordLength where
2201− toJSON = genericToJSON defaultOptions
2202−instance ToJSON MinWordLength where
2203− toJSON = genericToJSON defaultOptions
2204−instance ToJSON MaxDocFrequency where
2205− toJSON = genericToJSON defaultOptions
2206−instance ToJSON MinDocFrequency where
2207− toJSON = genericToJSON defaultOptions
2208−instance ToJSON PhraseSlop where
2209− toJSON = genericToJSON defaultOptions
2210−instance ToJSON StopWord where
2211− toJSON = genericToJSON defaultOptions
2212−instance ToJSON QueryPath where
2213− toJSON = genericToJSON defaultOptions
2214−instance ToJSON MinimumTermFrequency where
2215− toJSON = genericToJSON defaultOptions
2216−instance ToJSON PercentMatch where
2217− toJSON = genericToJSON defaultOptions
2218−instance ToJSON MappingName where
2219− toJSON = genericToJSON defaultOptions
2220−instance ToJSON DocId where
2221− toJSON = genericToJSON defaultOptions
2222−instance ToJSON QueryString where
2223− toJSON = genericToJSON defaultOptions
2224−instance ToJSON AllowLeadingWildcard where
2225− toJSON = genericToJSON defaultOptions
2226−instance ToJSON LowercaseExpanded where
2227− toJSON = genericToJSON defaultOptions
2228−instance ToJSON AnalyzeWildcard where
2229− toJSON = genericToJSON defaultOptions
2230−instance ToJSON GeneratePhraseQueries where
2231− toJSON = genericToJSON defaultOptions
2232−instance ToJSON Locale where
2233− toJSON = genericToJSON defaultOptions
2234−instance ToJSON EnablePositionIncrements where
2235− toJSON = genericToJSON defaultOptions
2236−
2237−instance FromJSON Version where
2238− parseJSON = genericParseJSON defaultOptions
2239−instance FromJSON IndexName where
2240− parseJSON = genericParseJSON defaultOptions
2241−instance FromJSON MappingName where
2242− parseJSON = genericParseJSON defaultOptions
2243−instance FromJSON DocId where
2244− parseJSON = genericParseJSON defaultOptions
2245−
2246−
2247−instance FromJSON Status where
2248− parseJSON (Object v) = Status <$>
2249− v .:? "ok" <*>
2250− v .: "status" <*>
2251− v .: "name" <*>
2252− v .: "version" <*>
2253− v .: "tagline"
2254− parseJSON _ = empty
2255−
2256−
2257−instance ToJSON IndexSettings where
2258− toJSON (IndexSettings s r) = object ["settings" .=
2259− object ["index" .=
2260− object ["number_of_shards" .= s, "number_of_replicas" .= r]
2261− ]
2262− ]
2263−
2264−instance ToJSON UpdatableIndexSetting where
2265− toJSON (NumberOfReplicas x) = oPath ("index" :| ["number_of_replicas"]) x
2266− toJSON (AutoExpandReplicas x) = oPath ("index" :| ["auto_expand_replicas"]) x
2267− toJSON (BlocksReadOnly x) = oPath ("blocks" :| ["read_only"]) x
2268− toJSON (BlocksRead x) = oPath ("blocks" :| ["read"]) x
2269− toJSON (BlocksWrite x) = oPath ("blocks" :| ["write"]) x
2270− toJSON (BlocksMetaData x) = oPath ("blocks" :| ["metadata"]) x
2271− toJSON (RefreshInterval x) = oPath ("index" :| ["refresh_interval"]) (NominalDiffTimeJSON x)
2272− toJSON (IndexConcurrency x) = oPath ("index" :| ["concurrency"]) x
2273− toJSON (FailOnMergeFailure x) = oPath ("index" :| ["fail_on_merge_failure"]) x
2274− toJSON (TranslogFlushThresholdOps x) = oPath ("index" :| ["translog", "flush_threshold_ops"]) x
2275− toJSON (TranslogFlushThresholdSize x) = oPath ("index" :| ["translog", "flush_threshold_size"]) x
2276− toJSON (TranslogFlushThresholdPeriod x) = oPath ("index" :| ["translog", "flush_threshold_period"]) (NominalDiffTimeJSON x)
2277− toJSON (TranslogDisableFlush x) = oPath ("index" :| ["translog", "disable_flush"]) x
2278− toJSON (CacheFilterMaxSize x) = oPath ("index" :| ["cache", "filter", "max_size"]) x
2279− toJSON (CacheFilterExpire x) = oPath ("index" :| ["cache", "filter", "expire"]) (NominalDiffTimeJSON <$> x)
2280− toJSON (GatewaySnapshotInterval x) = oPath ("index" :| ["gateway", "snapshot_interval"]) (NominalDiffTimeJSON x)
2281− toJSON (RoutingAllocationInclude fs) = oPath ("index" :| ["routing", "allocation", "include"]) (attrFilterJSON fs)
2282− toJSON (RoutingAllocationExclude fs) = oPath ("index" :| ["routing", "allocation", "exclude"]) (attrFilterJSON fs)
2283− toJSON (RoutingAllocationRequire fs) = oPath ("index" :| ["routing", "allocation", "require"]) (attrFilterJSON fs)
2284− toJSON (RoutingAllocationEnable x) = oPath ("index" :| ["routing", "allocation", "enable"]) x
2285− toJSON (RoutingAllocationShardsPerNode x) = oPath ("index" :| ["routing", "allocation", "total_shards_per_node"]) x
2286− toJSON (RecoveryInitialShards x) = oPath ("index" :| ["recovery", "initial_shards"]) x
2287− toJSON (GCDeletes x) = oPath ("index" :| ["gc_deletes"]) (NominalDiffTimeJSON x)
2288− toJSON (TTLDisablePurge x) = oPath ("index" :| ["ttl", "disable_purge"]) x
2289− toJSON (TranslogFSType x) = oPath ("index" :| ["translog", "fs", "type"]) x
2290− toJSON (IndexCompoundFormat x) = oPath ("index" :| ["compound_format"]) x
2291− toJSON (IndexCompoundOnFlush x) = oPath ("index" :| ["compound_on_flush"]) x
2292− toJSON (WarmerEnabled x) = oPath ("index" :| ["warmer", "enabled"]) x
2293−
2294−oPath :: ToJSON a => NonEmpty Text -> a -> Value
2295−oPath (k :| []) v = object [k .= v]
2296−oPath (k:| (h:t)) v = object [k .= oPath (h :| t) v]
2297−
2298−attrFilterJSON :: NonEmpty NodeAttrFilter -> Value
2299−attrFilterJSON fs = object [ n .= T.intercalate "," (toList vs)
2300− | NodeAttrFilter (NodeAttrName n) vs <- toList fs]
2301−
2302−instance ToJSON ReplicaBounds where
2303− toJSON (ReplicasBounded a b) = String (showText a <> "-" <> showText b)
2304− toJSON (ReplicasLowerBounded a) = String (showText a <> "-all")
2305− toJSON ReplicasUnbounded = Bool False
2306−
2307−instance ToJSON AllocationPolicy where
2308− toJSON AllocAll = String "all"
2309− toJSON AllocPrimaries = String "primaries"
2310− toJSON AllocNewPrimaries = String "new_primaries"
2311− toJSON AllocNone = String "none"
2312−
2313−instance ToJSON InitialShardCount where
2314− toJSON QuorumShards = String "quorum"
2315− toJSON QuorumMinus1Shards = String "quorum-1"
2316− toJSON FullShards = String "full"
2317− toJSON FullMinus1Shards = String "full-1"
2318− toJSON (ExplicitShards x) = toJSON x
2319−
2320−instance ToJSON FSType where
2321− toJSON FSSimple = "simple"
2322− toJSON FSBuffered = "buffered"
2323−
2324−instance ToJSON CompoundFormat where
2325− toJSON (CompoundFileFormat x) = Bool x
2326− toJSON (MergeSegmentVsTotalIndex x) = toJSON x
2327−
2328−instance ToJSON NominalDiffTimeJSON where
2329− toJSON (NominalDiffTimeJSON t) = String (showText (round t :: Integer) <> "s")
2330−
2331−instance ToJSON IndexTemplate where
2332− toJSON (IndexTemplate p s m) = merge
2333− (object [ "template" .= p
2334− , "mappings" .= foldl' merge (object []) m
2335− ])
2336− (toJSON s)
2337− where
2338− merge (Object o1) (Object o2) = toJSON $ HM.union o1 o2
2339− merge o Null = o
2340− merge _ _ = undefined
2341−
2342−instance (FromJSON a) => FromJSON (EsResult a) where
2343− parseJSON jsonVal@(Object v) = do
2344− found <- v .:? "found" .!= False
2345− fr <- if found
2346− then parseJSON jsonVal
2347− else return Nothing
2348− EsResult <$> v .: "_index" <*>
2349− v .: "_type" <*>
2350− v .: "_id" <*>
2351− pure fr
2352− parseJSON _ = empty
2353−
2354−instance (FromJSON a) => FromJSON (EsResultFound a) where
2355− parseJSON (Object v) = EsResultFound <$>
2356− v .: "_version" <*>
2357− v .: "_source"
2358− parseJSON _ = empty
2359−
2360−instance FromJSON EsError where
2361− parseJSON (Object v) = EsError <$>
2362− v .: "status" <*>
2363− v .: "error"
2364− parseJSON _ = empty
2365−
2366−instance ToJSON Search where
2367− toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize _ sFields sSource) =
2368− omitNulls [ "query" .= query
2369− , "filter" .= sFilter
2370− , "sort" .= sort
2371− , "aggregations" .= searchAggs
2372− , "highlight" .= highlight
2373− , "from" .= sFrom
2374− , "size" .= sSize
2375− , "track_scores" .= sTrackSortScores
2376− , "fields" .= sFields
2377− , "_source" .= sSource]
2378−
488+ deriving (Eq, Show)
2379489
2380490instance ToJSON Source where
2381491 toJSON NoSource = toJSON False
2382492 toJSON (SourcePatterns patterns) = toJSON patterns
2383− toJSON (SourceIncludeExclude incl excl) = object [ "include" .= incl, "exclude" .= excl ]
493+ toJSON (SourceIncludeExclude incl excl) = object [ "includes" .= incl, "excludes" .= excl ]
494+
495+data PatternOrPatterns = PopPattern Pattern
496+ | PopPatterns [Pattern] deriving (Eq, Read, Show)
2384497
2385498instance ToJSON PatternOrPatterns where
2386499 toJSON (PopPattern pattern) = toJSON pattern
2387500 toJSON (PopPatterns patterns) = toJSON patterns
2388501
502+data Include = Include [Pattern] deriving (Eq, Read, Show)
503+data Exclude = Exclude [Pattern] deriving (Eq, Read, Show)
504+
2389505instance ToJSON Include where
2390506 toJSON (Include patterns) = toJSON patterns
2391507
2392508instance ToJSON Exclude where
2393509 toJSON (Exclude patterns) = toJSON patterns
2394510
511+newtype Pattern = Pattern Text deriving (Eq, Read, Show)
512+
2395513instance ToJSON Pattern where
2396514 toJSON (Pattern pattern) = toJSON pattern
2397515
2398−
2399−instance ToJSON FieldHighlight where
2400− toJSON (FieldHighlight (FieldName fName) (Just fSettings)) =
2401− object [ fName .= fSettings ]
2402− toJSON (FieldHighlight (FieldName fName) Nothing) =
2403− object [ fName .= emptyObject ]
2404−
2405−instance ToJSON Highlights where
2406− toJSON (Highlights global fields) =
2407− omitNulls (("fields" .= fields)
2408− : highlightSettingsPairs global)
2409−
2410−instance ToJSON HighlightSettings where
2411− toJSON hs = omitNulls (highlightSettingsPairs (Just hs))
2412−
2413−highlightSettingsPairs :: Maybe HighlightSettings -> [Pair]
2414−highlightSettingsPairs Nothing = []
2415−highlightSettingsPairs (Just (Plain plh)) = plainHighPairs (Just plh)
2416−highlightSettingsPairs (Just (Postings ph)) = postHighPairs (Just ph)
2417−highlightSettingsPairs (Just (FastVector fvh)) = fastVectorHighPairs (Just fvh)
2418−
2419−
2420−plainHighPairs :: Maybe PlainHighlight -> [Pair]
2421−plainHighPairs Nothing = []
2422−plainHighPairs (Just (PlainHighlight plCom plNonPost)) =
2423− [ "type" .= String "plain"]
2424− ++ commonHighlightPairs plCom
2425− ++ nonPostingsToPairs plNonPost
2426−
2427−postHighPairs :: Maybe PostingsHighlight -> [Pair]
2428−postHighPairs Nothing = []
2429−postHighPairs (Just (PostingsHighlight pCom)) =
2430− ("type" .= String "postings")
2431− : commonHighlightPairs pCom
2432−
2433−fastVectorHighPairs :: Maybe FastVectorHighlight -> [Pair]
2434−fastVectorHighPairs Nothing = []
2435−fastVectorHighPairs (Just
2436− (FastVectorHighlight fvCom fvNonPostSettings fvBoundChars
2437− fvBoundMaxScan fvFragOff fvMatchedFields
2438− fvPhraseLim)) =
2439− [ "type" .= String "fvh"
2440− , "boundary_chars" .= fvBoundChars
2441− , "boundary_max_scan" .= fvBoundMaxScan
2442− , "fragment_offset" .= fvFragOff
2443− , "matched_fields" .= fvMatchedFields
2444− , "phraseLimit" .= fvPhraseLim]
2445− ++ commonHighlightPairs fvCom
2446− ++ nonPostingsToPairs fvNonPostSettings
2447−
2448−commonHighlightPairs :: Maybe CommonHighlight -> [Pair]
2449−commonHighlightPairs Nothing = []
2450−commonHighlightPairs (Just (CommonHighlight chScore chForceSource chTag chEncoder
2451− chNoMatchSize chHighlightQuery
2452− chRequireFieldMatch)) =
2453− [ "order" .= chScore
2454− , "force_source" .= chForceSource
2455− , "encoder" .= chEncoder
2456− , "no_match_size" .= chNoMatchSize
2457− , "highlight_query" .= chHighlightQuery
2458− , "require_fieldMatch" .= chRequireFieldMatch]
2459− ++ highlightTagToPairs chTag
2460−
2461−
2462−nonPostingsToPairs :: Maybe NonPostings -> [Pair]
2463−nonPostingsToPairs Nothing = []
2464−nonPostingsToPairs (Just (NonPostings npFragSize npNumOfFrags)) =
2465− [ "fragment_size" .= npFragSize
2466− , "number_of_fragments" .= npNumOfFrags]
2467−
2468−
2469−
2470−instance ToJSON HighlightEncoder where
2471− toJSON DefaultEncoder = String "default"
2472− toJSON HTMLEncoder = String "html"
2473−
2474−highlightTagToPairs :: Maybe HighlightTag -> [Pair]
2475−highlightTagToPairs (Just (TagSchema _)) = [ "scheme" .= String "default"]
2476−highlightTagToPairs (Just (CustomTags (pre, post))) = [ "pre_tags" .= pre
2477− , "post_tags" .= post]
2478−highlightTagToPairs Nothing = []
2479−
2480−instance ToJSON SortSpec where
2481− toJSON (DefaultSortSpec
2482− (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
2483− dsSortMode dsMissingSort dsNestedFilter)) =
2484− object [dsSortFieldName .= omitNulls base] where
2485− base = [ "order" .= dsSortOrder
2486− , "ignore_unmapped" .= dsIgnoreUnmapped
2487− , "mode" .= dsSortMode
2488− , "missing" .= dsMissingSort
2489− , "nested_filter" .= dsNestedFilter ]
2490−
2491− toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
2492− object [ "unit" .= units
2493− , field .= gdsLatLon
2494− , "order" .= gdsSortOrder ]
2495−
2496−
2497−instance ToJSON SortOrder where
2498− toJSON Ascending = String "asc"
2499− toJSON Descending = String "desc"
2500−
2501−
2502−instance ToJSON SortMode where
2503− toJSON SortMin = String "min"
2504− toJSON SortMax = String "max"
2505− toJSON SortSum = String "sum"
2506− toJSON SortAvg = String "avg"
2507−
2508−
2509−instance ToJSON Missing where
2510− toJSON LastMissing = String "_last"
2511− toJSON FirstMissing = String "_first"
2512− toJSON (CustomMissing txt) = String txt
2513−
2514−
2515−instance ToJSON ScoreType where
2516− toJSON ScoreTypeMax = "max"
2517− toJSON ScoreTypeAvg = "avg"
2518− toJSON ScoreTypeSum = "sum"
2519− toJSON ScoreTypeNone = "none"
2520−
2521−
2522−instance ToJSON Distance where
2523− toJSON (Distance dCoefficient dUnit) =
2524− String boltedTogether where
2525− coefText = showText dCoefficient
2526− (String unitText) = toJSON dUnit
2527− boltedTogether = mappend coefText unitText
2528−
2529−
2530−instance ToJSON DistanceUnit where
2531− toJSON Miles = String "mi"
2532− toJSON Yards = String "yd"
2533− toJSON Feet = String "ft"
2534− toJSON Inches = String "in"
2535− toJSON Kilometers = String "km"
2536− toJSON Meters = String "m"
2537− toJSON Centimeters = String "cm"
2538− toJSON Millimeters = String "mm"
2539− toJSON NauticalMiles = String "nmi"
2540−
2541−
2542−instance ToJSON DistanceType where
2543− toJSON Arc = String "arc"
2544− toJSON SloppyArc = String "sloppy_arc"
2545− toJSON Plane = String "plane"
2546−
2547−
2548−instance ToJSON OptimizeBbox where
2549− toJSON NoOptimizeBbox = String "none"
2550− toJSON (OptimizeGeoFilterType gft) = toJSON gft
2551−
2552−
2553−instance ToJSON GeoBoundingBoxConstraint where
2554− toJSON (GeoBoundingBoxConstraint
2555− (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2556− object [gbbcGeoBBField .= gbbcConstraintBox
2557− , "_cache" .= cache
2558− , "type" .= type']
2559−
2560−
2561−instance ToJSON GeoFilterType where
2562− toJSON GeoFilterMemory = String "memory"
2563− toJSON GeoFilterIndexed = String "indexed"
2564−
2565−
2566−instance ToJSON GeoBoundingBox where
2567− toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2568− object ["top_left" .= gbbTopLeft
2569− , "bottom_right" .= gbbBottomRight]
2570−
2571−
2572−instance ToJSON LatLon where
2573− toJSON (LatLon lLat lLon) =
2574− object ["lat" .= lLat
2575− , "lon" .= lLon]
2576−
2577−
2578−-- index for smaller ranges, fielddata for longer ranges
2579−instance ToJSON RangeExecution where
2580− toJSON RangeExecutionIndex = "index"
2581− toJSON RangeExecutionFielddata = "fielddata"
2582−
2583−
2584−instance ToJSON RegexpFlags where
2585− toJSON AllRegexpFlags = String "ALL"
2586− toJSON NoRegexpFlags = String "NONE"
2587− toJSON (SomeRegexpFlags (h :| fs)) = String $ T.intercalate "|" flagStrs
2588− where flagStrs = map flagStr . nub $ h:fs
2589− flagStr AnyString = "ANYSTRING"
2590− flagStr Automaton = "AUTOMATON"
2591− flagStr Complement = "COMPLEMENT"
2592− flagStr Empty = "EMPTY"
2593− flagStr Intersection = "INTERSECTION"
2594− flagStr Interval = "INTERVAL"
2595−
2596−instance ToJSON Term where
2597− toJSON (Term field value) = object ["term" .= object
2598− [field .= value]]
2599−
2600−
2601−instance ToJSON BoolMatch where
2602− toJSON (MustMatch term cache) = object ["must" .= term,
2603− "_cache" .= cache]
2604− toJSON (MustNotMatch term cache) = object ["must_not" .= term,
2605− "_cache" .= cache]
2606− toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2607− "_cache" .= cache]
2608−
516+data SearchResult a =
517+ SearchResult { took :: Int
518+ , timedOut :: Bool
519+ , shards :: ShardResult
520+ , searchHits :: SearchHits a
521+ , aggregations :: Maybe AggregationResults
522+ , scrollId :: Maybe ScrollId
523+ -- ^ Only one Suggestion request / response per
524+ -- Search is supported.
525+ , suggest :: Maybe NamedSuggestionResponse
526+ }
527+ deriving (Eq, Show)
2609528
2610529instance (FromJSON a) => FromJSON (SearchResult a) where
2611530 parseJSON (Object v) = SearchResult <$>
@@ -2614,52 +533,10 @@ instance (FromJSON a) => FromJSON (SearchResult a) where
2614533 v .: "_shards" <*>
2615534 v .: "hits" <*>
2616535 v .:? "aggregations" <*>
2617− v .:? "_scroll_id"
2618− parseJSON _ = empty
2619−
2620−instance (FromJSON a) => FromJSON (SearchHits a) where
2621− parseJSON (Object v) = SearchHits <$>
2622− v .: "total" <*>
2623− v .: "max_score" <*>
2624− v .: "hits"
536+ v .:? "_scroll_id" <*>
537+ v .:? "suggest"
2625538 parseJSON _ = empty
2626539
2627−instance (FromJSON a) => FromJSON (Hit a) where
2628− parseJSON (Object v) = Hit <$>
2629− v .: "_index" <*>
2630− v .: "_type" <*>
2631− v .: "_id" <*>
2632− v .: "_score" <*>
2633− v .:? "_source" <*>
2634− v .:? "highlight"
2635− parseJSON _ = empty
2636−
2637−instance FromJSON ShardResult where
2638− parseJSON (Object v) = ShardResult <$>
2639− v .: "total" <*>
2640− v .: "successful" <*>
2641− v .: "failed"
2642− parseJSON _ = empty
2643−
2644−
2645−instance FromJSON DocVersion where
2646− parseJSON v = do
2647− i <- parseJSON v
2648− maybe (fail "DocVersion out of range") return $ mkDocVersion i
2649−
2650−instance Bounded DocVersion where
2651− minBound = DocVersion 1
2652− maxBound = DocVersion 9200000000000000000 -- 9.2e+18
2653−
2654−instance Enum DocVersion where
2655− succ x
2656− | x /= maxBound = DocVersion (succ $ docVersionNumber x)
2657− | otherwise = succError "DocVersion"
2658− pred x
2659− | x /= minBound = DocVersion (pred $ docVersionNumber x)
2660− | otherwise = predError "DocVersion"
2661− toEnum i =
2662− fromMaybe (error $ show i ++ " out of DocVersion range") $ mkDocVersion i
2663− fromEnum = docVersionNumber
2664− enumFrom = boundedEnumFrom
2665− enumFromThen = boundedEnumFromThen
540+newtype ScrollId =
541+ ScrollId Text
542+ deriving (Eq, Show, Ord, ToJSON, FromJSON)