git.iko.soy/typeable/bloodhound
on master help sign in
Finish up index settings feature
a27cec5Michael Xavier
bloodhound.cabal−1
@@ -71,7 +71,6 @@ test-suite tests
71 mtl,
71 mtl,
72 quickcheck-properties,
72 quickcheck-properties,
73 derive,
73 derive,
74− quickcheck-instances,
75 errors
74 errors
76 default-language: Haskell2010
75 default-language: Haskell2010
77
76
src/Database/Bloodhound/Client.hs+2−3
@@ -25,6 +25,7 @@ module Database.Bloodhound.Client
25 , createIndex
25 , createIndex
26 , deleteIndex
26 , deleteIndex
27 , updateIndexSettings
27 , updateIndexSettings
28+ , getIndexSettings
28 , indexExists
29 , indexExists
29 , openIndex
30 , openIndex
30 , closeIndex
31 , closeIndex
@@ -293,11 +294,9 @@ updateIndexSettings updates (IndexName indexName) =
293 jsonBody = Object (deepMerge [u | Object u <- toJSON <$> toList updates])
294 jsonBody = Object (deepMerge [u | Object u <- toJSON <$> toList updates])
294
295
295
296
296−--TODO: This feels a little nicer than returning a reply and coyly
297−--implying that it *should* be an IndexSettingsSummary
298getIndexSettings :: (MonadBH m, MonadThrow m) => IndexName
297getIndexSettings :: (MonadBH m, MonadThrow m) => IndexName
299 -> m (Either EsError IndexSettingsSummary)
298 -> m (Either EsError IndexSettingsSummary)
300−getIndexSettings (IndexName indexName) =
299+getIndexSettings (IndexName indexName) = do
301 parseEsResponse =<< get =<< url
300 parseEsResponse =<< get =<< url
302 where url = joinPath [indexName, "_settings"]
301 where url = joinPath [indexName, "_settings"]
303
302
src/Database/Bloodhound/Types.hs+192−152
@@ -368,7 +368,7 @@ data Status = Status { ok :: Maybe Bool
368 , status :: Int
368 , status :: Int
369 , name :: Text
369 , name :: Text
370 , version :: Version
370 , version :: Version
371− , tagline :: Text } deriving (Eq, Show)
371+ , tagline :: Text } deriving (Eq, Show, Generic)
372
372
373{-| 'IndexSettings' is used to configure the shards and replicas when you create
373{-| 'IndexSettings' is used to configure the shards and replicas when you create
374 an Elasticsearch Index.
374 an Elasticsearch Index.
@@ -378,7 +378,7 @@ data Status = Status { ok :: Maybe Bool
378
378
379data IndexSettings =
379data IndexSettings =
380 IndexSettings { indexShards :: ShardCount
380 IndexSettings { indexShards :: ShardCount
381− , indexReplicas :: ReplicaCount } deriving (Eq, Show)
381+ , indexReplicas :: ReplicaCount } deriving (Eq, Show, Generic)
382
382
383{-| 'defaultIndexSettings' is an 'IndexSettings' with 3 shards and 2 replicas. -}
383{-| 'defaultIndexSettings' is an 'IndexSettings' with 3 shards and 2 replicas. -}
384defaultIndexSettings :: IndexSettings
384defaultIndexSettings :: IndexSettings
@@ -436,7 +436,7 @@ data UpdatableIndexSetting = NumberOfReplicas ReplicaCount
436 | IndexCompoundFormat CompoundFormat
436 | IndexCompoundFormat CompoundFormat
437 | IndexCompoundOnFlush Bool
437 | IndexCompoundOnFlush Bool
438 | WarmerEnabled Bool
438 | WarmerEnabled Bool
439− deriving (Eq, Show)
439+ deriving (Eq, Show, Generic)
440
440
441data AllocationPolicy = AllocAll
441data AllocationPolicy = AllocAll
442 -- ^ Allows shard allocation for all shards.
442 -- ^ Allows shard allocation for all shards.
@@ -446,42 +446,42 @@ data AllocationPolicy = AllocAll
446 -- ^ Allows shard allocation only for primary shards for new indices.
446 -- ^ Allows shard allocation only for primary shards for new indices.
447 | AllocNone
447 | AllocNone
448 -- ^ No shard allocation is allowed
448 -- ^ No shard allocation is allowed
449− deriving (Eq, Show)
449+ deriving (Eq, Show, Generic)
450
450
451data ReplicaBounds = ReplicasBounded Int Int
451data ReplicaBounds = ReplicasBounded Int Int
452 | ReplicasLowerBounded Int
452 | ReplicasLowerBounded Int
453 | ReplicasUnbounded
453 | ReplicasUnbounded
454− deriving (Eq, Show)
454+ deriving (Eq, Show, Generic)
455
455
456−newtype Bytes = Bytes Int deriving (Eq, Show, Ord, ToJSON, FromJSON)
456+newtype Bytes = Bytes Int deriving (Eq, Show, Generic, Ord, ToJSON, FromJSON)
457
457
458data FSType = FSSimple
458data FSType = FSSimple
459− | FSBuffered deriving (Eq, Show, Ord)
459+ | FSBuffered deriving (Eq, Show, Generic, Ord)
460
460
461data InitialShardCount = QuorumShards
461data InitialShardCount = QuorumShards
462 | QuorumMinus1Shards
462 | QuorumMinus1Shards
463 | FullShards
463 | FullShards
464 | FullMinus1Shards
464 | FullMinus1Shards
465 | ExplicitShards Int
465 | ExplicitShards Int
466− deriving (Eq, Show)
466+ deriving (Eq, Show, Generic)
467
467
468data NodeAttrFilter = NodeAttrFilter { nodeAttrFilterName :: NodeAttrName
468data NodeAttrFilter = NodeAttrFilter { nodeAttrFilterName :: NodeAttrName
469 , nodeAttrFilterValues :: NonEmpty Text}
469 , nodeAttrFilterValues :: NonEmpty Text}
470− deriving (Eq, Show)
470+ deriving (Eq, Show, Generic, Ord)
471
471
472−newtype NodeAttrName = NodeAttrName Text deriving (Eq, Show)
472+newtype NodeAttrName = NodeAttrName Text deriving (Eq, Show, Ord, Generic)
473
473
474data CompoundFormat = CompoundFileFormat Bool
474data CompoundFormat = CompoundFileFormat Bool
475 | MergeSegmentVsTotalIndex Double
475 | MergeSegmentVsTotalIndex Double
476 -- ^ percentage between 0 and 1 where 0 is false, 1 is true
476 -- ^ percentage between 0 and 1 where 0 is false, 1 is true
477− deriving (Eq, Show)
477+ deriving (Eq, Show, Generic)
478
478
479newtype NominalDiffTimeJSON = NominalDiffTimeJSON { ndtJSON :: NominalDiffTime }
479newtype NominalDiffTimeJSON = NominalDiffTimeJSON { ndtJSON :: NominalDiffTime }
480
480
481data IndexSettingsSummary = IndexSettingsSummary { sSummaryIndexName :: IndexName
481data IndexSettingsSummary = IndexSettingsSummary { sSummaryIndexName :: IndexName
482 , sSummaryFixedSettings :: IndexSettings
482 , sSummaryFixedSettings :: IndexSettings
483 , sSummaryUpdateable :: [UpdatableIndexSetting]}
483 , sSummaryUpdateable :: [UpdatableIndexSetting]}
484− deriving (Eq, Show)
484+ deriving (Eq, Show, Generic)
485
485
486{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
486{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
487type Reply = Network.HTTP.Client.Response L.ByteString
487type Reply = Network.HTTP.Client.Response L.ByteString
@@ -491,7 +491,7 @@ type Method = NHTM.Method
491
491
492 <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
492 <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
493-}
493-}
494−data OpenCloseIndex = OpenIndex | CloseIndex deriving (Eq, Show)
494+data OpenCloseIndex = OpenIndex | CloseIndex deriving (Eq, Show, Generic)
495
495
496data FieldType = GeoPointType
496data FieldType = GeoPointType
497 | GeoShapeType
497 | GeoShapeType
@@ -499,10 +499,10 @@ data FieldType = GeoPointType
499 | IntegerType
499 | IntegerType
500 | LongType
500 | LongType
501 | ShortType
501 | ShortType
502− | ByteType deriving (Eq, Show)
502+ | ByteType deriving (Eq, Show, Generic)
503
503
504data FieldDefinition =
504data FieldDefinition =
505− FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
505+ FieldDefinition { fieldType :: FieldType } deriving (Eq, Show, Generic)
506
506
507{-| An 'IndexTemplate' defines a template that will automatically be
507{-| An 'IndexTemplate' defines a template that will automatically be
508 applied to new indices created. The templates include both
508 applied to new indices created. The templates include both
@@ -520,7 +520,7 @@ data IndexTemplate =
520
520
521data MappingField =
521data MappingField =
522 MappingField { mappingFieldName :: FieldName
522 MappingField { mappingFieldName :: FieldName
523− , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
523+ , fieldDefinition :: FieldDefinition } deriving (Eq, Show, Generic)
524
524
525{-| Support for type reification of 'Mapping's is currently incomplete, for
525{-| Support for type reification of 'Mapping's is currently incomplete, for
526 now the mapping API verbiage expects a 'ToJSON'able blob.
526 now the mapping API verbiage expects a 'ToJSON'able blob.
@@ -530,7 +530,7 @@ data MappingField =
530 and keeping different kinds of documents separated if possible.
530 and keeping different kinds of documents separated if possible.
531-}
531-}
532data Mapping = Mapping { typeName :: TypeName
532data Mapping = Mapping { typeName :: TypeName
533− , mappingFields :: [MappingField] } deriving (Eq, Show)
533+ , mappingFields :: [MappingField] } deriving (Eq, Show, Generic)
534
534
535{-| 'BulkOperation' is a sum type for expressing the four kinds of bulk
535{-| 'BulkOperation' is a sum type for expressing the four kinds of bulk
536 operation index, create, delete, and update. 'BulkIndex' behaves like an
536 operation index, create, delete, and update. 'BulkIndex' behaves like an
@@ -542,7 +542,7 @@ data BulkOperation =
542 BulkIndex IndexName MappingName DocId Value
542 BulkIndex IndexName MappingName DocId Value
543 | BulkCreate IndexName MappingName DocId Value
543 | BulkCreate IndexName MappingName DocId Value
544 | BulkDelete IndexName MappingName DocId
544 | BulkDelete IndexName MappingName DocId
545− | BulkUpdate IndexName MappingName DocId Value deriving (Eq, Show)
545+ | BulkUpdate IndexName MappingName DocId Value deriving (Eq, Show, Generic)
546
546
547{-| 'EsResult' describes the standard wrapper JSON document that you see in
547{-| 'EsResult' describes the standard wrapper JSON document that you see in
548 successful Elasticsearch lookups or lookups that couldn't find the document.
548 successful Elasticsearch lookups or lookups that couldn't find the document.
@@ -550,55 +550,55 @@ data BulkOperation =
550data EsResult a = EsResult { _index :: Text
550data EsResult a = EsResult { _index :: Text
551 , _type :: Text
551 , _type :: Text
552 , _id :: Text
552 , _id :: Text
553− , foundResult :: Maybe (EsResultFound a)} deriving (Eq, Show)
553+ , foundResult :: Maybe (EsResultFound a)} deriving (Eq, Show, Generic)
554
554
555{-| 'EsResultFound' contains the document and its metadata inside of an
555{-| 'EsResultFound' contains the document and its metadata inside of an
556 'EsResult' when the document was successfully found.
556 'EsResult' when the document was successfully found.
557-}
557-}
558data EsResultFound a = EsResultFound { _version :: DocVersion
558data EsResultFound a = EsResultFound { _version :: DocVersion
559− , _source :: a } deriving (Eq, Show)
559+ , _source :: a } deriving (Eq, Show, Generic)
560
560
561{-| 'EsError' is the generic type that will be returned when there was a
561{-| 'EsError' is the generic type that will be returned when there was a
562 problem. If you can't parse the expected response, its a good idea to
562 problem. If you can't parse the expected response, its a good idea to
563 try parsing this.
563 try parsing this.
564-}
564-}
565data EsError = EsError { errorStatus :: Int
565data EsError = EsError { errorStatus :: Int
566− , errorMessage :: Text } deriving (Eq, Show)
566+ , errorMessage :: Text } deriving (Eq, Show, Generic)
567
567
568data IndexAlias = IndexAlias { srcIndex :: IndexName
568data IndexAlias = IndexAlias { srcIndex :: IndexName
569− , indexAlias :: IndexAliasName } deriving (Eq, Show)
569+ , indexAlias :: IndexAliasName } deriving (Eq, Show, Generic)
570
570
571−newtype IndexAliasName = IndexAliasName { indexAliasName :: IndexName } deriving (Eq, Show, ToJSON)
571+newtype IndexAliasName = IndexAliasName { indexAliasName :: IndexName } deriving (Eq, Show, Generic, ToJSON)
572
572
573data IndexAliasAction = AddAlias IndexAlias IndexAliasCreate
573data IndexAliasAction = AddAlias IndexAlias IndexAliasCreate
574− | RemoveAlias IndexAlias deriving (Show, Eq, Typeable)
574+ | RemoveAlias IndexAlias deriving (Show, Eq, Generic, Typeable)
575
575
576data IndexAliasCreate = IndexAliasCreate { aliasCreateRouting :: Maybe AliasRouting
576data IndexAliasCreate = IndexAliasCreate { aliasCreateRouting :: Maybe AliasRouting
577 , aliasCreateFilter :: Maybe Filter}
577 , aliasCreateFilter :: Maybe Filter}
578− deriving (Show, Eq, Typeable)
578+ deriving (Show, Eq, Generic, Typeable)
579
579
580data AliasRouting = AllAliasRouting RoutingValue
580data AliasRouting = AllAliasRouting RoutingValue
581 | GranularAliasRouting (Maybe SearchAliasRouting) (Maybe IndexAliasRouting)
581 | GranularAliasRouting (Maybe SearchAliasRouting) (Maybe IndexAliasRouting)
582− deriving (Show, Eq, Typeable)
582+ deriving (Show, Eq, Generic, Typeable)
583
583
584−newtype SearchAliasRouting = SearchAliasRouting (NonEmpty RoutingValue) deriving (Show, Eq, Typeable)
584+newtype SearchAliasRouting = SearchAliasRouting (NonEmpty RoutingValue) deriving (Show, Eq, Generic, Typeable)
585
585
586−newtype IndexAliasRouting = IndexAliasRouting RoutingValue deriving (Show, Eq, ToJSON, FromJSON, Typeable)
586+newtype IndexAliasRouting = IndexAliasRouting RoutingValue deriving (Show, Eq, Generic, ToJSON, FromJSON, Typeable)
587
587
588−newtype RoutingValue = RoutingValue { routingValue :: Text } deriving (Show, Eq, ToJSON, FromJSON, Typeable)
588+newtype RoutingValue = RoutingValue { routingValue :: Text } deriving (Show, Eq, Generic, ToJSON, FromJSON, Typeable)
589
589
590−newtype IndexAliasesSummary = IndexAliasesSummary { indexAliasesSummary :: [IndexAliasSummary] } deriving (Show, Eq, Typeable)
590+newtype IndexAliasesSummary = IndexAliasesSummary { indexAliasesSummary :: [IndexAliasSummary] } deriving (Show, Eq, Generic, Typeable)
591
591
592{-| 'IndexAliasSummary' is a summary of an index alias configured for a server. -}
592{-| 'IndexAliasSummary' is a summary of an index alias configured for a server. -}
593data IndexAliasSummary = IndexAliasSummary { indexAliasSummaryAlias :: IndexAlias
593data IndexAliasSummary = IndexAliasSummary { indexAliasSummaryAlias :: IndexAlias
594− , indexAliasSummaryCreate :: IndexAliasCreate} deriving (Show, Eq)
594+ , indexAliasSummaryCreate :: IndexAliasCreate} deriving (Show, Eq, Generic)
595
595
596{-| 'DocVersion' is an integer version number for a document between 1
596{-| 'DocVersion' is an integer version number for a document between 1
597and 9.2e+18 used for <<https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html optimistic concurrency control>>.
597and 9.2e+18 used for <<https://www.elastic.co/guide/en/elasticsearch/guide/current/optimistic-concurrency-control.html optimistic concurrency control>>.
598-}
598-}
599newtype DocVersion = DocVersion {
599newtype DocVersion = DocVersion {
600 docVersionNumber :: Int
600 docVersionNumber :: Int
601− } deriving (Eq, Show, Ord, ToJSON)
601+ } deriving (Eq, Show, Generic, Ord, ToJSON)
602
602
603-- | Smart constructor for in-range doc version
603-- | Smart constructor for in-range doc version
604mkDocVersion :: Int -> Maybe DocVersion
604mkDocVersion :: Int -> Maybe DocVersion
@@ -612,7 +612,7 @@ mkDocVersion i
612own version numbers instead of ones from ES.
612own version numbers instead of ones from ES.
613-}
613-}
614newtype ExternalDocVersion = ExternalDocVersion DocVersion
614newtype ExternalDocVersion = ExternalDocVersion DocVersion
615− deriving (Eq, Show, Ord, Bounded, Enum, ToJSON)
615+ deriving (Eq, Show, Generic, Ord, Bounded, Enum, ToJSON)
616
616
617{-| 'VersionControl' is specified when indexing documents as a
617{-| 'VersionControl' is specified when indexing documents as a
618optimistic concurrency control.
618optimistic concurrency control.
@@ -646,12 +646,12 @@ data VersionControl = NoVersionControl
646 -- given version will be the new version. This is
646 -- given version will be the new version. This is
647 -- typically used for correcting errors. Use with
647 -- typically used for correcting errors. Use with
648 -- care, as this could result in data loss.
648 -- care, as this could result in data loss.
649− deriving (Show, Eq, Ord)
649+ deriving (Show, Eq, Generic, Ord)
650
650
651{-| 'DocumentParent' is used to specify a parent document.
651{-| 'DocumentParent' is used to specify a parent document.
652-}
652-}
653newtype DocumentParent = DocumentParent DocId
653newtype DocumentParent = DocumentParent DocId
654− deriving (Eq, Show)
654+ deriving (Eq, Show, Generic)
655
655
656{-| 'IndexDocumentSettings' are special settings supplied when indexing
656{-| 'IndexDocumentSettings' are special settings supplied when indexing
657a document. For the best backwards compatiblity when new fields are
657a document. For the best backwards compatiblity when new fields are
@@ -660,7 +660,7 @@ added, you should probably prefer to start with 'defaultIndexDocumentSettings'
660data IndexDocumentSettings =
660data IndexDocumentSettings =
661 IndexDocumentSettings { idsVersionControl :: VersionControl
661 IndexDocumentSettings { idsVersionControl :: VersionControl
662 , idsParent :: Maybe DocumentParent
662 , idsParent :: Maybe DocumentParent
663− } deriving (Eq, Show)
663+ } deriving (Eq, Show, Generic)
664
664
665{-| Reasonable default settings. Chooses no version control and no parent.
665{-| Reasonable default settings. Chooses no version control and no parent.
666-}
666-}
@@ -680,7 +680,7 @@ type Sort = [SortSpec]
680<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
680<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
681-}
681-}
682data SortSpec = DefaultSortSpec DefaultSort
682data SortSpec = DefaultSortSpec DefaultSort
683− | GeoDistanceSortSpec SortOrder GeoPoint DistanceUnit deriving (Eq, Show)
683+ | GeoDistanceSortSpec SortOrder GeoPoint DistanceUnit deriving (Eq, Show, Generic)
684
684
685{-| 'DefaultSort' is usually the kind of 'SortSpec' you'll want. There's a
685{-| 'DefaultSort' is usually the kind of 'SortSpec' you'll want. There's a
686 'mkSort' convenience function for when you want to specify only the most
686 'mkSort' convenience function for when you want to specify only the most
@@ -695,7 +695,7 @@ data DefaultSort =
695 , ignoreUnmapped :: Bool
695 , ignoreUnmapped :: Bool
696 , sortMode :: Maybe SortMode
696 , sortMode :: Maybe SortMode
697 , missingSort :: Maybe Missing
697 , missingSort :: Maybe Missing
698− , nestedFilter :: Maybe Filter } deriving (Eq, Show)
698+ , nestedFilter :: Maybe Filter } deriving (Eq, Show, Generic)
699
699
700{-| 'SortOrder' is 'Ascending' or 'Descending', as you might expect. These get
700{-| 'SortOrder' is 'Ascending' or 'Descending', as you might expect. These get
701 encoded into "asc" or "desc" when turned into JSON.
701 encoded into "asc" or "desc" when turned into JSON.
@@ -703,7 +703,7 @@ data DefaultSort =
703<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
703<http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#search-request-sort>
704-}
704-}
705data SortOrder = Ascending
705data SortOrder = Ascending
706− | Descending deriving (Eq, Show)
706+ | Descending deriving (Eq, Show, Generic)
707
707
708{-| 'Missing' prescribes how to handle missing fields. A missing field can be
708{-| 'Missing' prescribes how to handle missing fields. A missing field can be
709 sorted last, first, or using a custom value as a substitute.
709 sorted last, first, or using a custom value as a substitute.
@@ -712,7 +712,7 @@ data SortOrder = Ascending
712-}
712-}
713data Missing = LastMissing
713data Missing = LastMissing
714 | FirstMissing
714 | FirstMissing
715− | CustomMissing Text deriving (Eq, Show)
715+ | CustomMissing Text deriving (Eq, Show, Generic)
716
716
717{-| 'SortMode' prescribes how to handle sorting array/multi-valued fields.
717{-| 'SortMode' prescribes how to handle sorting array/multi-valued fields.
718
718
@@ -721,7 +721,7 @@ http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-req
721data SortMode = SortMin
721data SortMode = SortMin
722 | SortMax
722 | SortMax
723 | SortSum
723 | SortSum
724− | SortAvg deriving (Eq, Show)
724+ | SortAvg deriving (Eq, Show, Generic)
725
725
726{-| 'mkSort' defaults everything but the 'FieldName' and the 'SortOrder' so
726{-| 'mkSort' defaults everything but the 'FieldName' and the 'SortOrder' so
727 that you can concisely describe the usual kind of 'SortSpec's you want.
727 that you can concisely describe the usual kind of 'SortSpec's you want.
@@ -743,19 +743,19 @@ type PrefixValue = Text
743{-| 'BooleanOperator' is the usual And/Or operators with an ES compatible
743{-| 'BooleanOperator' is the usual And/Or operators with an ES compatible
744 JSON encoding baked in. Used all over the place.
744 JSON encoding baked in. Used all over the place.
745-}
745-}
746−data BooleanOperator = And | Or deriving (Eq, Show, Typeable)
746+data BooleanOperator = And | Or deriving (Eq, Show, Generic, Typeable)
747
747
748{-| 'ShardCount' is part of 'IndexSettings'
748{-| 'ShardCount' is part of 'IndexSettings'
749-}
749-}
750−newtype ShardCount = ShardCount Int deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
750+newtype ShardCount = ShardCount Int deriving (Eq, Show, Generic, ToJSON, Typeable)
751
751
752{-| 'ReplicaCount' is part of 'IndexSettings'
752{-| 'ReplicaCount' is part of 'IndexSettings'
753-}
753-}
754−newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
754+newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic, ToJSON, Typeable)
755
755
756{-| 'Server' is used with the client functions to point at the ES instance
756{-| 'Server' is used with the client functions to point at the ES instance
757-}
757-}
758−newtype Server = Server Text deriving (Eq, Show)
758+newtype Server = Server Text deriving (Eq, Show, Generic)
759
759
760{-| 'IndexName' is used to describe which index to query/create/delete
760{-| 'IndexName' is used to describe which index to query/create/delete
761-}
761-}
@@ -787,27 +787,27 @@ newtype QueryString = QueryString Text deriving (Eq, Generic, Show, ToJSON, From
787{-| 'FieldName' is used all over the place wherever a specific field within
787{-| 'FieldName' is used all over the place wherever a specific field within
788 a document needs to be specified, usually in 'Query's or 'Filter's.
788 a document needs to be specified, usually in 'Query's or 'Filter's.
789-}
789-}
790−newtype FieldName = FieldName Text deriving (Eq, Show, ToJSON, FromJSON, Typeable)
790+newtype FieldName = FieldName Text deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
791
791
792
792
793{-| 'Script' is often used in place of 'FieldName' to specify more
793{-| 'Script' is often used in place of 'FieldName' to specify more
794complex ways of extracting a value from a document.
794complex ways of extracting a value from a document.
795-}
795-}
796−newtype Script = Script { scriptText :: Text } deriving (Eq, Show)
796+newtype Script = Script { scriptText :: Text } deriving (Eq, Show, Generic)
797
797
798{-| 'CacheName' is used in 'RegexpFilter' for describing the
798{-| 'CacheName' is used in 'RegexpFilter' for describing the
799 'CacheKey' keyed caching behavior.
799 'CacheKey' keyed caching behavior.
800-}
800-}
801−newtype CacheName = CacheName Text deriving (Eq, Show, ToJSON, FromJSON, Typeable)
801+newtype CacheName = CacheName Text deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
802
802
803{-| 'CacheKey' is used in 'RegexpFilter' to key regex caching.
803{-| 'CacheKey' is used in 'RegexpFilter' to key regex caching.
804-}
804-}
805newtype CacheKey =
805newtype CacheKey =
806− CacheKey Text deriving (Eq, Show, ToJSON, FromJSON, Typeable)
806+ CacheKey Text deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
807newtype Existence =
807newtype Existence =
808− Existence Bool deriving (Eq, Show, ToJSON, FromJSON, Typeable)
808+ Existence Bool deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
809newtype NullValue =
809newtype NullValue =
810− NullValue Bool deriving (Eq, Show, ToJSON, FromJSON, Typeable)
810+ NullValue Bool deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
811newtype CutoffFrequency =
811newtype CutoffFrequency =
812 CutoffFrequency Double deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
812 CutoffFrequency Double deriving (Eq, Show, Generic, ToJSON, FromJSON, Typeable)
813newtype Analyzer =
813newtype Analyzer =
@@ -900,8 +900,8 @@ unpackId :: DocId -> Text
900unpackId (DocId docId) = docId
900unpackId (DocId docId) = docId
901
901
902type TrackSortScores = Bool
902type TrackSortScores = Bool
903−newtype From = From Int deriving (Eq, Show, ToJSON)
903+newtype From = From Int deriving (Eq, Show, Generic, ToJSON)
904−newtype Size = Size Int deriving (Eq, Show, ToJSON)
904+newtype Size = Size Int deriving (Eq, Show, Generic, ToJSON)
905
905
906data Search = Search { queryBody :: Maybe Query
906data Search = Search { queryBody :: Maybe Query
907 , filterBody :: Maybe Filter
907 , filterBody :: Maybe Filter
@@ -914,7 +914,7 @@ data Search = Search { queryBody :: Maybe Query
914 , size :: Size
914 , size :: Size
915 , searchType :: SearchType
915 , searchType :: SearchType
916 , fields :: Maybe [FieldName]
916 , fields :: Maybe [FieldName]
917− , source :: Maybe Source } deriving (Eq, Show)
917+ , source :: Maybe Source } deriving (Eq, Show, Generic)
918
918
919data SearchType = SearchTypeQueryThenFetch
919data SearchType = SearchTypeQueryThenFetch
920 | SearchTypeDfsQueryThenFetch
920 | SearchTypeDfsQueryThenFetch
@@ -922,40 +922,40 @@ data SearchType = SearchTypeQueryThenFetch
922 | SearchTypeScan
922 | SearchTypeScan
923 | SearchTypeQueryAndFetch
923 | SearchTypeQueryAndFetch
924 | SearchTypeDfsQueryAndFetch
924 | SearchTypeDfsQueryAndFetch
925− deriving (Eq, Show)
925+ deriving (Eq, Show, Generic)
926
926
927data Source =
927data Source =
928 NoSource
928 NoSource
929 | SourcePatterns PatternOrPatterns
929 | SourcePatterns PatternOrPatterns
930 | SourceIncludeExclude Include Exclude
930 | SourceIncludeExclude Include Exclude
931− deriving (Show, Eq)
931+ deriving (Show, Eq, Generic)
932
932
933data PatternOrPatterns = PopPattern Pattern
933data PatternOrPatterns = PopPattern Pattern
934− | PopPatterns [Pattern] deriving (Eq, Show)
934+ | PopPatterns [Pattern] deriving (Eq, Show, Generic)
935
935
936−data Include = Include [Pattern] deriving (Eq, Show)
936+data Include = Include [Pattern] deriving (Eq, Show, Generic)
937−data Exclude = Exclude [Pattern] deriving (Eq, Show)
937+data Exclude = Exclude [Pattern] deriving (Eq, Show, Generic)
938
938
939−newtype Pattern = Pattern Text deriving (Eq, Show)
939+newtype Pattern = Pattern Text deriving (Eq, Show, Generic)
940
940
941data Highlights = Highlights { globalsettings :: Maybe HighlightSettings
941data Highlights = Highlights { globalsettings :: Maybe HighlightSettings
942 , highlightFields :: [FieldHighlight]
942 , highlightFields :: [FieldHighlight]
943− } deriving (Show, Eq)
943+ } deriving (Show, Eq, Generic)
944
944
945data FieldHighlight = FieldHighlight FieldName (Maybe HighlightSettings)
945data FieldHighlight = FieldHighlight FieldName (Maybe HighlightSettings)
946− deriving (Show, Eq)
946+ deriving (Show, Eq, Generic)
947
947
948
948
949data HighlightSettings = Plain PlainHighlight
949data HighlightSettings = Plain PlainHighlight
950 | Postings PostingsHighlight
950 | Postings PostingsHighlight
951 | FastVector FastVectorHighlight
951 | FastVector FastVectorHighlight
952− deriving (Show, Eq)
952+ deriving (Show, Eq, Generic)
953data PlainHighlight =
953data PlainHighlight =
954 PlainHighlight { plainCommon :: Maybe CommonHighlight
954 PlainHighlight { plainCommon :: Maybe CommonHighlight
955− , plainNonPost :: Maybe NonPostings } deriving (Show, Eq)
955+ , plainNonPost :: Maybe NonPostings } deriving (Show, Eq, Generic)
956
956
957 -- This requires that index_options are set to 'offset' in the mapping.
957 -- This requires that index_options are set to 'offset' in the mapping.
958−data PostingsHighlight = PostingsHighlight (Maybe CommonHighlight) deriving (Show, Eq)
958+data PostingsHighlight = PostingsHighlight (Maybe CommonHighlight) deriving (Show, Eq, Generic)
959
959
960-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
960-- This requires that term_vector is set to 'with_positions_offsets' in the mapping.
961data FastVectorHighlight =
961data FastVectorHighlight =
@@ -966,7 +966,7 @@ data FastVectorHighlight =
966 , fragmentOffset :: Maybe Int
966 , fragmentOffset :: Maybe Int
967 , matchedFields :: [Text]
967 , matchedFields :: [Text]
968 , phraseLimit :: Maybe Int
968 , phraseLimit :: Maybe Int
969− } deriving (Show, Eq)
969+ } deriving (Show, Eq, Generic)
970
970
971data CommonHighlight =
971data CommonHighlight =
972 CommonHighlight { order :: Maybe Text
972 CommonHighlight { order :: Maybe Text
@@ -976,21 +976,21 @@ data CommonHighlight =
976 , noMatchSize :: Maybe Int
976 , noMatchSize :: Maybe Int
977 , highlightQuery :: Maybe Query
977 , highlightQuery :: Maybe Query
978 , requireFieldMatch :: Maybe Bool
978 , requireFieldMatch :: Maybe Bool
979− } deriving (Show, Eq)
979+ } deriving (Show, Eq, Generic)
980
980
981-- Settings that are only applicable to FastVector and Plain highlighters.
981-- Settings that are only applicable to FastVector and Plain highlighters.
982data NonPostings =
982data NonPostings =
983 NonPostings { fragmentSize :: Maybe Int
983 NonPostings { fragmentSize :: Maybe Int
984− , numberOfFragments :: Maybe Int} deriving (Show, Eq)
984+ , numberOfFragments :: Maybe Int} deriving (Show, Eq, Generic)
985
985
986data HighlightEncoder = DefaultEncoder
986data HighlightEncoder = DefaultEncoder
987 | HTMLEncoder
987 | HTMLEncoder
988− deriving (Show, Eq)
988+ deriving (Show, Eq, Generic)
989
989
990-- NOTE: Should the tags use some kind of HTML type, rather than Text?
990-- NOTE: Should the tags use some kind of HTML type, rather than Text?
991data HighlightTag = TagSchema Text
991data HighlightTag = TagSchema Text
992 | CustomTags ([Text], [Text]) -- Only uses more than the first value in the lists if fvh
992 | CustomTags ([Text], [Text]) -- Only uses more than the first value in the lists if fvh
993− deriving (Show, Eq)
993+ deriving (Show, Eq, Generic)
994
994
995
995
996data Query =
996data Query =
@@ -1021,19 +1021,19 @@ data Query =
1021 | QuerySimpleQueryStringQuery SimpleQueryStringQuery
1021 | QuerySimpleQueryStringQuery SimpleQueryStringQuery
1022 | QueryRangeQuery RangeQuery
1022 | QueryRangeQuery RangeQuery
1023 | QueryRegexpQuery RegexpQuery
1023 | QueryRegexpQuery RegexpQuery
1024− deriving (Eq, Show, Typeable)
1024+ deriving (Eq, Show, Generic, Typeable)
1025
1025
1026data RegexpQuery =
1026data RegexpQuery =
1027 RegexpQuery { regexpQueryField :: FieldName
1027 RegexpQuery { regexpQueryField :: FieldName
1028 , regexpQuery :: Regexp
1028 , regexpQuery :: Regexp
1029 , regexpQueryFlags :: RegexpFlags
1029 , regexpQueryFlags :: RegexpFlags
1030 , regexpQueryBoost :: Maybe Boost
1030 , regexpQueryBoost :: Maybe Boost
1031− } deriving (Eq, Show, Typeable)
1031+ } deriving (Eq, Show, Generic, Typeable)
1032
1032
1033data RangeQuery =
1033data RangeQuery =
1034 RangeQuery { rangeQueryField :: FieldName
1034 RangeQuery { rangeQueryField :: FieldName
1035 , rangeQueryRange :: RangeValue
1035 , rangeQueryRange :: RangeValue
1036− , rangeQueryBoost :: Boost } deriving (Eq, Show, Typeable)
1036+ , rangeQueryBoost :: Boost } deriving (Eq, Show, Generic, Typeable)
1037
1037
1038mkRangeQuery :: FieldName -> RangeValue -> RangeQuery
1038mkRangeQuery :: FieldName -> RangeValue -> RangeQuery
1039mkRangeQuery f r = RangeQuery f r (Boost 1.0)
1039mkRangeQuery f r = RangeQuery f r (Boost 1.0)
@@ -1047,7 +1047,7 @@ data SimpleQueryStringQuery =
1047 , simpleQueryStringFlags :: Maybe (NonEmpty SimpleQueryFlag)
1047 , simpleQueryStringFlags :: Maybe (NonEmpty SimpleQueryFlag)
1048 , simpleQueryStringLowercaseExpanded :: Maybe LowercaseExpanded
1048 , simpleQueryStringLowercaseExpanded :: Maybe LowercaseExpanded
1049 , simpleQueryStringLocale :: Maybe Locale
1049 , simpleQueryStringLocale :: Maybe Locale
1050− } deriving (Eq, Show, Typeable)
1050+ } deriving (Eq, Show, Generic, Typeable)
1051
1051
1052data SimpleQueryFlag =
1052data SimpleQueryFlag =
1053 SimpleQueryAll
1053 SimpleQueryAll
@@ -1061,7 +1061,7 @@ data SimpleQueryFlag =
1061 | SimpleQueryWhitespace
1061 | SimpleQueryWhitespace
1062 | SimpleQueryFuzzy
1062 | SimpleQueryFuzzy
1063 | SimpleQueryNear
1063 | SimpleQueryNear
1064− | SimpleQuerySlop deriving (Eq, Show, Typeable)
1064+ | SimpleQuerySlop deriving (Eq, Show, Generic, Typeable)
1065
1065
1066-- use_dis_max and tie_breaker when fields are plural?
1066-- use_dis_max and tie_breaker when fields are plural?
1067data QueryStringQuery =
1067data QueryStringQuery =
@@ -1083,7 +1083,7 @@ data QueryStringQuery =
1083 , queryStringMinimumShouldMatch :: Maybe MinimumMatch
1083 , queryStringMinimumShouldMatch :: Maybe MinimumMatch
1084 , queryStringLenient :: Maybe Lenient
1084 , queryStringLenient :: Maybe Lenient
1085 , queryStringLocale :: Maybe Locale
1085 , queryStringLocale :: Maybe Locale
1086− } deriving (Eq, Show, Typeable)
1086+ } deriving (Eq, Show, Generic, Typeable)
1087
1087
1088mkQueryStringQuery :: QueryString -> QueryStringQuery
1088mkQueryStringQuery :: QueryString -> QueryStringQuery
1089mkQueryStringQuery qs =
1089mkQueryStringQuery qs =
@@ -1094,19 +1094,19 @@ mkQueryStringQuery qs =
1094 Nothing Nothing
1094 Nothing Nothing
1095
1095
1096data FieldOrFields = FofField FieldName
1096data FieldOrFields = FofField FieldName
1097− | FofFields (NonEmpty FieldName) deriving (Eq, Show, Typeable)
1097+ | FofFields (NonEmpty FieldName) deriving (Eq, Show, Generic, Typeable)
1098
1098
1099data PrefixQuery =
1099data PrefixQuery =
1100 PrefixQuery
1100 PrefixQuery
1101 { prefixQueryField :: FieldName
1101 { prefixQueryField :: FieldName
1102 , prefixQueryPrefixValue :: Text
1102 , prefixQueryPrefixValue :: Text
1103− , prefixQueryBoost :: Maybe Boost } deriving (Eq, Show, Typeable)
1103+ , prefixQueryBoost :: Maybe Boost } deriving (Eq, Show, Generic, Typeable)
1104
1104
1105data NestedQuery =
1105data NestedQuery =
1106 NestedQuery
1106 NestedQuery
1107 { nestedQueryPath :: QueryPath
1107 { nestedQueryPath :: QueryPath
1108 , nestedQueryScoreType :: ScoreType
1108 , nestedQueryScoreType :: ScoreType
1109− , nestedQuery :: Query } deriving (Eq, Show, Typeable)
1109+ , nestedQuery :: Query } deriving (Eq, Show, Generic, Typeable)
1110
1110
1111data MoreLikeThisFieldQuery =
1111data MoreLikeThisFieldQuery =
1112 MoreLikeThisFieldQuery
1112 MoreLikeThisFieldQuery
@@ -1124,7 +1124,7 @@ data MoreLikeThisFieldQuery =
1124 , moreLikeThisFieldBoostTerms :: Maybe BoostTerms
1124 , moreLikeThisFieldBoostTerms :: Maybe BoostTerms
1125 , moreLikeThisFieldBoost :: Maybe Boost
1125 , moreLikeThisFieldBoost :: Maybe Boost
1126 , moreLikeThisFieldAnalyzer :: Maybe Analyzer
1126 , moreLikeThisFieldAnalyzer :: Maybe Analyzer
1127− } deriving (Eq, Show, Typeable)
1127+ } deriving (Eq, Show, Generic, Typeable)
1128
1128
1129data MoreLikeThisQuery =
1129data MoreLikeThisQuery =
1130 MoreLikeThisQuery
1130 MoreLikeThisQuery
@@ -1142,32 +1142,32 @@ data MoreLikeThisQuery =
1142 , moreLikeThisBoostTerms :: Maybe BoostTerms
1142 , moreLikeThisBoostTerms :: Maybe BoostTerms
1143 , moreLikeThisBoost :: Maybe Boost
1143 , moreLikeThisBoost :: Maybe Boost
1144 , moreLikeThisAnalyzer :: Maybe Analyzer
1144 , moreLikeThisAnalyzer :: Maybe Analyzer
1145− } deriving (Eq, Show, Typeable)
1145+ } deriving (Eq, Show, Generic, Typeable)
1146
1146
1147data IndicesQuery =
1147data IndicesQuery =
1148 IndicesQuery
1148 IndicesQuery
1149 { indicesQueryIndices :: [IndexName]
1149 { indicesQueryIndices :: [IndexName]
1150 , indicesQuery :: Query
1150 , indicesQuery :: Query
1151 -- default "all"
1151 -- default "all"
1152− , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show, Typeable)
1152+ , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show, Generic, Typeable)
1153
1153
1154data HasParentQuery =
1154data HasParentQuery =
1155 HasParentQuery
1155 HasParentQuery
1156 { hasParentQueryType :: TypeName
1156 { hasParentQueryType :: TypeName
1157 , hasParentQuery :: Query
1157 , hasParentQuery :: Query
1158− , hasParentQueryScoreType :: Maybe ScoreType } deriving (Eq, Show, Typeable)
1158+ , hasParentQueryScoreType :: Maybe ScoreType } deriving (Eq, Show, Generic, Typeable)
1159
1159
1160data HasChildQuery =
1160data HasChildQuery =
1161 HasChildQuery
1161 HasChildQuery
1162 { hasChildQueryType :: TypeName
1162 { hasChildQueryType :: TypeName
1163 , hasChildQuery :: Query
1163 , hasChildQuery :: Query
1164− , hasChildQueryScoreType :: Maybe ScoreType } deriving (Eq, Show, Typeable)
1164+ , hasChildQueryScoreType :: Maybe ScoreType } deriving (Eq, Show, Generic, Typeable)
1165
1165
1166data ScoreType =
1166data ScoreType =
1167 ScoreTypeMax
1167 ScoreTypeMax
1168 | ScoreTypeSum
1168 | ScoreTypeSum
1169 | ScoreTypeAvg
1169 | ScoreTypeAvg
1170− | ScoreTypeNone deriving (Eq, Show, Typeable)
1170+ | ScoreTypeNone deriving (Eq, Show, Generic, Typeable)
1171
1171
1172data FuzzyQuery =
1172data FuzzyQuery =
1173 FuzzyQuery { fuzzyQueryField :: FieldName
1173 FuzzyQuery { fuzzyQueryField :: FieldName
@@ -1176,7 +1176,7 @@ data FuzzyQuery =
1176 , fuzzyQueryMaxExpansions :: MaxExpansions
1176 , fuzzyQueryMaxExpansions :: MaxExpansions
1177 , fuzzyQueryFuzziness :: Fuzziness
1177 , fuzzyQueryFuzziness :: Fuzziness
1178 , fuzzyQueryBoost :: Maybe Boost
1178 , fuzzyQueryBoost :: Maybe Boost
1179− } deriving (Eq, Show, Typeable)
1179+ } deriving (Eq, Show, Generic, Typeable)
1180
1180
1181data FuzzyLikeFieldQuery =
1181data FuzzyLikeFieldQuery =
1182 FuzzyLikeFieldQuery
1182 FuzzyLikeFieldQuery
@@ -1189,7 +1189,7 @@ data FuzzyLikeFieldQuery =
1189 , fuzzyLikeFieldPrefixLength :: PrefixLength
1189 , fuzzyLikeFieldPrefixLength :: PrefixLength
1190 , fuzzyLikeFieldBoost :: Boost
1190 , fuzzyLikeFieldBoost :: Boost
1191 , fuzzyLikeFieldAnalyzer :: Maybe Analyzer
1191 , fuzzyLikeFieldAnalyzer :: Maybe Analyzer
1192− } deriving (Eq, Show, Typeable)
1192+ } deriving (Eq, Show, Generic, Typeable)
1193
1193
1194data FuzzyLikeThisQuery =
1194data FuzzyLikeThisQuery =
1195 FuzzyLikeThisQuery
1195 FuzzyLikeThisQuery
@@ -1201,19 +1201,19 @@ data FuzzyLikeThisQuery =
1201 , fuzzyLikePrefixLength :: PrefixLength
1201 , fuzzyLikePrefixLength :: PrefixLength
1202 , fuzzyLikeBoost :: Boost
1202 , fuzzyLikeBoost :: Boost
1203 , fuzzyLikeAnalyzer :: Maybe Analyzer
1203 , fuzzyLikeAnalyzer :: Maybe Analyzer
1204− } deriving (Eq, Show, Typeable)
1204+ } deriving (Eq, Show, Generic, Typeable)
1205
1205
1206data FilteredQuery =
1206data FilteredQuery =
1207 FilteredQuery
1207 FilteredQuery
1208 { filteredQuery :: Query
1208 { filteredQuery :: Query
1209− , filteredFilter :: Filter } deriving (Eq, Show, Typeable)
1209+ , filteredFilter :: Filter } deriving (Eq, Show, Generic, Typeable)
1210
1210
1211data DisMaxQuery =
1211data DisMaxQuery =
1212 DisMaxQuery { disMaxQueries :: [Query]
1212 DisMaxQuery { disMaxQueries :: [Query]
1213 -- default 0.0
1213 -- default 0.0
1214 , disMaxTiebreaker :: Tiebreaker
1214 , disMaxTiebreaker :: Tiebreaker
1215 , disMaxBoost :: Maybe Boost
1215 , disMaxBoost :: Maybe Boost
1216− } deriving (Eq, Show, Typeable)
1216+ } deriving (Eq, Show, Generic, Typeable)
1217
1217
1218data MatchQuery =
1218data MatchQuery =
1219 MatchQuery { matchQueryField :: FieldName
1219 MatchQuery { matchQueryField :: FieldName
@@ -1225,7 +1225,7 @@ data MatchQuery =
1225 , matchQueryAnalyzer :: Maybe Analyzer
1225 , matchQueryAnalyzer :: Maybe Analyzer
1226 , matchQueryMaxExpansions :: Maybe MaxExpansions
1226 , matchQueryMaxExpansions :: Maybe MaxExpansions
1227 , matchQueryLenient :: Maybe Lenient
1227 , matchQueryLenient :: Maybe Lenient
1228− , matchQueryBoost :: Maybe Boost } deriving (Eq, Show, Typeable)
1228+ , matchQueryBoost :: Maybe Boost } deriving (Eq, Show, Generic, Typeable)
1229
1229
1230{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
1230{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
1231 enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
1231 enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
@@ -1235,7 +1235,7 @@ mkMatchQuery field query = MatchQuery field query Or ZeroTermsNone Nothing Nothi
1235
1235
1236data MatchQueryType =
1236data MatchQueryType =
1237 MatchPhrase
1237 MatchPhrase
1238− | MatchPhrasePrefix deriving (Eq, Show, Typeable)
1238+ | MatchPhrasePrefix deriving (Eq, Show, Generic, Typeable)
1239
1239
1240data MultiMatchQuery =
1240data MultiMatchQuery =
1241 MultiMatchQuery { multiMatchQueryFields :: [FieldName]
1241 MultiMatchQuery { multiMatchQueryFields :: [FieldName]
@@ -1247,7 +1247,7 @@ data MultiMatchQuery =
1247 , multiMatchQueryCutoffFrequency :: Maybe CutoffFrequency
1247 , multiMatchQueryCutoffFrequency :: Maybe CutoffFrequency
1248 , multiMatchQueryAnalyzer :: Maybe Analyzer
1248 , multiMatchQueryAnalyzer :: Maybe Analyzer
1249 , multiMatchQueryMaxExpansions :: Maybe MaxExpansions
1249 , multiMatchQueryMaxExpansions :: Maybe MaxExpansions
1250− , multiMatchQueryLenient :: Maybe Lenient } deriving (Eq, Show, Typeable)
1250+ , multiMatchQueryLenient :: Maybe Lenient } deriving (Eq, Show, Generic, Typeable)
1251
1251
1252{-| 'mkMultiMatchQuery' is a convenience function that defaults the less common parameters,
1252{-| 'mkMultiMatchQuery' is a convenience function that defaults the less common parameters,
1253 enabling you to provide only the list of 'FieldName's and 'QueryString' to
1253 enabling you to provide only the list of 'FieldName's and 'QueryString' to
@@ -1264,7 +1264,7 @@ data MultiMatchQueryType =
1264 | MultiMatchMostFields
1264 | MultiMatchMostFields
1265 | MultiMatchCrossFields
1265 | MultiMatchCrossFields
1266 | MultiMatchPhrase
1266 | MultiMatchPhrase
1267− | MultiMatchPhrasePrefix deriving (Eq, Show, Typeable)
1267+ | MultiMatchPhrasePrefix deriving (Eq, Show, Generic, Typeable)
1268
1268
1269data BoolQuery =
1269data BoolQuery =
1270 BoolQuery { boolQueryMustMatch :: [Query]
1270 BoolQuery { boolQueryMustMatch :: [Query]
@@ -1273,7 +1273,7 @@ data BoolQuery =
1273 , boolQueryMinimumShouldMatch :: Maybe MinimumMatch
1273 , boolQueryMinimumShouldMatch :: Maybe MinimumMatch
1274 , boolQueryBoost :: Maybe Boost
1274 , boolQueryBoost :: Maybe Boost
1275 , boolQueryDisableCoord :: Maybe DisableCoord
1275 , boolQueryDisableCoord :: Maybe DisableCoord
1276− } deriving (Eq, Show, Typeable)
1276+ } deriving (Eq, Show, Generic, Typeable)
1277
1277
1278mkBoolQuery :: [Query] -> [Query] -> [Query] -> BoolQuery
1278mkBoolQuery :: [Query] -> [Query] -> [Query] -> BoolQuery
1279mkBoolQuery must mustNot should =
1279mkBoolQuery must mustNot should =
@@ -1282,7 +1282,7 @@ mkBoolQuery must mustNot should =
1282data BoostingQuery =
1282data BoostingQuery =
1283 BoostingQuery { positiveQuery :: Query
1283 BoostingQuery { positiveQuery :: Query
1284 , negativeQuery :: Query
1284 , negativeQuery :: Query
1285− , negativeBoost :: Boost } deriving (Eq, Show, Typeable)
1285+ , negativeBoost :: Boost } deriving (Eq, Show, Generic, Typeable)
1286
1286
1287data CommonTermsQuery =
1287data CommonTermsQuery =
1288 CommonTermsQuery { commonField :: FieldName
1288 CommonTermsQuery { commonField :: FieldName
@@ -1294,16 +1294,16 @@ data CommonTermsQuery =
1294 , commonBoost :: Maybe Boost
1294 , commonBoost :: Maybe Boost
1295 , commonAnalyzer :: Maybe Analyzer
1295 , commonAnalyzer :: Maybe Analyzer
1296 , commonDisableCoord :: Maybe DisableCoord
1296 , commonDisableCoord :: Maybe DisableCoord
1297− } deriving (Eq, Show, Typeable)
1297+ } deriving (Eq, Show, Generic, Typeable)
1298
1298
1299data CommonMinimumMatch =
1299data CommonMinimumMatch =
1300 CommonMinimumMatchHighLow MinimumMatchHighLow
1300 CommonMinimumMatchHighLow MinimumMatchHighLow
1301 | CommonMinimumMatch MinimumMatch
1301 | CommonMinimumMatch MinimumMatch
1302− deriving (Eq, Show, Typeable)
1302+ deriving (Eq, Show, Generic, Typeable)
1303
1303
1304data MinimumMatchHighLow =
1304data MinimumMatchHighLow =
1305 MinimumMatchHighLow { lowFreq :: MinimumMatch
1305 MinimumMatchHighLow { lowFreq :: MinimumMatch
1306− , highFreq :: MinimumMatch } deriving (Eq, Show, Typeable)
1306+ , highFreq :: MinimumMatch } deriving (Eq, Show, Generic, Typeable)
1307
1307
1308data Filter = AndFilter [Filter] Cache
1308data Filter = AndFilter [Filter] Cache
1309 | OrFilter [Filter] Cache
1309 | OrFilter [Filter] Cache
@@ -1323,36 +1323,36 @@ data Filter = AndFilter [Filter] Cache
1323 | RangeFilter FieldName RangeValue RangeExecution Cache
1323 | RangeFilter FieldName RangeValue RangeExecution Cache
1324 | RegexpFilter FieldName Regexp RegexpFlags CacheName Cache CacheKey
1324 | RegexpFilter FieldName Regexp RegexpFlags CacheName Cache CacheKey
1325 | TermFilter Term Cache
1325 | TermFilter Term Cache
1326− deriving (Eq, Show, Typeable)
1326+ deriving (Eq, Show, Generic, Typeable)
1327
1327
1328data ZeroTermsQuery = ZeroTermsNone
1328data ZeroTermsQuery = ZeroTermsNone
1329− | ZeroTermsAll deriving (Eq, Show, Typeable)
1329+ | ZeroTermsAll deriving (Eq, Show, Generic, Typeable)
1330
1330
1331data RangeExecution = RangeExecutionIndex
1331data RangeExecution = RangeExecutionIndex
1332− | RangeExecutionFielddata deriving (Eq, Show, Typeable)
1332+ | RangeExecutionFielddata deriving (Eq, Show, Generic, Typeable)
1333
1333
1334−newtype Regexp = Regexp Text deriving (Eq, Show, FromJSON)
1334+newtype Regexp = Regexp Text deriving (Eq, Show, Generic, FromJSON)
1335
1335
1336data RegexpFlags = AllRegexpFlags
1336data RegexpFlags = AllRegexpFlags
1337 | NoRegexpFlags
1337 | NoRegexpFlags
1338− | SomeRegexpFlags (NonEmpty RegexpFlag) deriving (Eq, Show)
1338+ | SomeRegexpFlags (NonEmpty RegexpFlag) deriving (Eq, Show, Generic)
1339
1339
1340data RegexpFlag = AnyString
1340data RegexpFlag = AnyString
1341 | Automaton
1341 | Automaton
1342 | Complement
1342 | Complement
1343 | Empty
1343 | Empty
1344 | Intersection
1344 | Intersection
1345− | Interval deriving (Eq, Show)
1345+ | Interval deriving (Eq, Show, Generic)
1346
1346
1347−newtype LessThan = LessThan Double deriving (Eq, Show)
1347+newtype LessThan = LessThan Double deriving (Eq, Show, Generic)
1348−newtype LessThanEq = LessThanEq Double deriving (Eq, Show)
1348+newtype LessThanEq = LessThanEq Double deriving (Eq, Show, Generic)
1349−newtype GreaterThan = GreaterThan Double deriving (Eq, Show)
1349+newtype GreaterThan = GreaterThan Double deriving (Eq, Show, Generic)
1350−newtype GreaterThanEq = GreaterThanEq Double deriving (Eq, Show)
1350+newtype GreaterThanEq = GreaterThanEq Double deriving (Eq, Show, Generic)
1351
1351
1352−newtype LessThanD = LessThanD UTCTime deriving (Eq, Show)
1352+newtype LessThanD = LessThanD UTCTime deriving (Eq, Show, Generic)
1353−newtype LessThanEqD = LessThanEqD UTCTime deriving (Eq, Show)
1353+newtype LessThanEqD = LessThanEqD UTCTime deriving (Eq, Show, Generic)
1354−newtype GreaterThanD = GreaterThanD UTCTime deriving (Eq, Show)
1354+newtype GreaterThanD = GreaterThanD UTCTime deriving (Eq, Show, Generic)
1355−newtype GreaterThanEqD = GreaterThanEqD UTCTime deriving (Eq, Show)
1355+newtype GreaterThanEqD = GreaterThanEqD UTCTime deriving (Eq, Show, Generic)
1356
1356
1357data RangeValue = RangeDateLte LessThanEqD
1357data RangeValue = RangeDateLte LessThanEqD
1358 | RangeDateLt LessThanD
1358 | RangeDateLt LessThanD
@@ -1370,7 +1370,7 @@ data RangeValue = RangeDateLte LessThanEqD
1370 | RangeDoubleGteLte GreaterThanEq LessThanEq
1370 | RangeDoubleGteLte GreaterThanEq LessThanEq
1371 | RangeDoubleGteLt GreaterThanEq LessThan
1371 | RangeDoubleGteLt GreaterThanEq LessThan
1372 | RangeDoubleGtLte GreaterThan LessThanEq
1372 | RangeDoubleGtLte GreaterThan LessThanEq
1373− deriving (Eq, Show)
1373+ deriving (Eq, Show, Generic)
1374
1374
1375rangeValueToPair :: RangeValue -> [Pair]
1375rangeValueToPair :: RangeValue -> [Pair]
1376rangeValueToPair rv = case rv of
1376rangeValueToPair rv = case rv of
@@ -1392,33 +1392,33 @@ rangeValueToPair rv = case rv of
1392 RangeDoubleGtLt (GreaterThan l) (LessThan g) -> ["gt" .= l, "lt" .= g]
1392 RangeDoubleGtLt (GreaterThan l) (LessThan g) -> ["gt" .= l, "lt" .= g]
1393
1393
1394data Term = Term { termField :: Text
1394data Term = Term { termField :: Text
1395− , termValue :: Text } deriving (Eq, Show, Typeable)
1395+ , termValue :: Text } deriving (Eq, Show, Generic, Typeable)
1396
1396
1397data BoolMatch = MustMatch Term Cache
1397data BoolMatch = MustMatch Term Cache
1398 | MustNotMatch Term Cache
1398 | MustNotMatch Term Cache
1399− | ShouldMatch [Term] Cache deriving (Eq, Show, Typeable)
1399+ | ShouldMatch [Term] Cache deriving (Eq, Show, Generic, Typeable)
1400
1400
1401-- "memory" or "indexed"
1401-- "memory" or "indexed"
1402data GeoFilterType = GeoFilterMemory
1402data GeoFilterType = GeoFilterMemory
1403− | GeoFilterIndexed deriving (Eq, Show, Typeable)
1403+ | GeoFilterIndexed deriving (Eq, Show, Generic, Typeable)
1404
1404
1405data LatLon = LatLon { lat :: Double
1405data LatLon = LatLon { lat :: Double
1406− , lon :: Double } deriving (Eq, Show, Typeable)
1406+ , lon :: Double } deriving (Eq, Show, Generic, Typeable)
1407
1407
1408data GeoBoundingBox =
1408data GeoBoundingBox =
1409 GeoBoundingBox { topLeft :: LatLon
1409 GeoBoundingBox { topLeft :: LatLon
1410− , bottomRight :: LatLon } deriving (Eq, Show, Typeable)
1410+ , bottomRight :: LatLon } deriving (Eq, Show, Generic, Typeable)
1411
1411
1412data GeoBoundingBoxConstraint =
1412data GeoBoundingBoxConstraint =
1413 GeoBoundingBoxConstraint { geoBBField :: FieldName
1413 GeoBoundingBoxConstraint { geoBBField :: FieldName
1414 , constraintBox :: GeoBoundingBox
1414 , constraintBox :: GeoBoundingBox
1415 , bbConstraintcache :: Cache
1415 , bbConstraintcache :: Cache
1416 , geoType :: GeoFilterType
1416 , geoType :: GeoFilterType
1417− } deriving (Eq, Show, Typeable)
1417+ } deriving (Eq, Show, Generic, Typeable)
1418
1418
1419data GeoPoint =
1419data GeoPoint =
1420 GeoPoint { geoField :: FieldName
1420 GeoPoint { geoField :: FieldName
1421− , latLon :: LatLon} deriving (Eq, Show, Typeable)
1421+ , latLon :: LatLon} deriving (Eq, Show, Generic, Typeable)
1422
1422
1423data DistanceUnit = Miles
1423data DistanceUnit = Miles
1424 | Yards
1424 | Yards
@@ -1428,22 +1428,22 @@ data DistanceUnit = Miles
1428 | Meters
1428 | Meters
1429 | Centimeters
1429 | Centimeters
1430 | Millimeters
1430 | Millimeters
1431− | NauticalMiles deriving (Eq, Show, Typeable)
1431+ | NauticalMiles deriving (Eq, Show, Generic, Typeable)
1432
1432
1433data DistanceType = Arc
1433data DistanceType = Arc
1434 | SloppyArc -- doesn't exist <1.0
1434 | SloppyArc -- doesn't exist <1.0
1435− | Plane deriving (Eq, Show, Typeable)
1435+ | Plane deriving (Eq, Show, Generic, Typeable)
1436
1436
1437data OptimizeBbox = OptimizeGeoFilterType GeoFilterType
1437data OptimizeBbox = OptimizeGeoFilterType GeoFilterType
1438− | NoOptimizeBbox deriving (Eq, Show, Typeable)
1438+ | NoOptimizeBbox deriving (Eq, Show, Generic, Typeable)
1439
1439
1440data Distance =
1440data Distance =
1441 Distance { coefficient :: Double
1441 Distance { coefficient :: Double
1442− , unit :: DistanceUnit } deriving (Eq, Show, Typeable)
1442+ , unit :: DistanceUnit } deriving (Eq, Show, Generic, Typeable)
1443
1443
1444data DistanceRange =
1444data DistanceRange =
1445 DistanceRange { distanceFrom :: Distance
1445 DistanceRange { distanceFrom :: Distance
1446− , distanceTo :: Distance } deriving (Eq, Show)
1446+ , distanceTo :: Distance } deriving (Eq, Show, Generic)
1447
1447
1448data SearchResult a =
1448data SearchResult a =
1449 SearchResult { took :: Int
1449 SearchResult { took :: Int
@@ -1451,16 +1451,16 @@ data SearchResult a =
1451 , shards :: ShardResult
1451 , shards :: ShardResult
1452 , searchHits :: SearchHits a
1452 , searchHits :: SearchHits a
1453 , aggregations :: Maybe AggregationResults
1453 , aggregations :: Maybe AggregationResults
1454− , scrollId :: Maybe ScrollId } deriving (Eq, Show)
1454+ , scrollId :: Maybe ScrollId } deriving (Eq, Show, Generic)
1455
1455
1456−newtype ScrollId = ScrollId Text deriving (Eq, Show, Ord, ToJSON, FromJSON)
1456+newtype ScrollId = ScrollId Text deriving (Eq, Show, Generic, Ord, ToJSON, FromJSON)
1457
1457
1458type Score = Maybe Double
1458type Score = Maybe Double
1459
1459
1460data SearchHits a =
1460data SearchHits a =
1461 SearchHits { hitsTotal :: Int
1461 SearchHits { hitsTotal :: Int
1462 , maxScore :: Score
1462 , maxScore :: Score
1463− , hits :: [Hit a] } deriving (Eq, Show)
1463+ , hits :: [Hit a] } deriving (Eq, Show, Generic)
1464
1464
1465
1465
1466instance Monoid (SearchHits a) where
1466instance Monoid (SearchHits a) where
@@ -1475,7 +1475,7 @@ data Hit a =
1475 , hitDocId :: DocId
1475 , hitDocId :: DocId
1476 , hitScore :: Score
1476 , hitScore :: Score
1477 , hitSource :: Maybe a
1477 , hitSource :: Maybe a
1478− , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show)
1478+ , hitHighlight :: Maybe HitHighlight } deriving (Eq, Show, Generic)
1479
1479
1480data ShardResult =
1480data ShardResult =
1481 ShardResult { shardTotal :: Int
1481 ShardResult { shardTotal :: Int
@@ -1504,19 +1504,19 @@ mkAggregations :: Text -> Aggregation -> Aggregations
1504mkAggregations name aggregation = M.insert name aggregation emptyAggregations
1504mkAggregations name aggregation = M.insert name aggregation emptyAggregations
1505
1505
1506data TermOrder = TermOrder{ termSortField :: Text
1506data TermOrder = TermOrder{ termSortField :: Text
1507− , termSortOrder :: SortOrder } deriving (Eq, Show)
1507+ , termSortOrder :: SortOrder } deriving (Eq, Show, Generic)
1508
1508
1509data TermInclusion = TermInclusion Text
1509data TermInclusion = TermInclusion Text
1510− | TermPattern Text Text deriving (Eq, Show)
1510+ | TermPattern Text Text deriving (Eq, Show, Generic)
1511
1511
1512data CollectionMode = BreadthFirst
1512data CollectionMode = BreadthFirst
1513− | DepthFirst deriving (Eq, Show)
1513+ | DepthFirst deriving (Eq, Show, Generic)
1514
1514
1515data ExecutionHint = Ordinals
1515data ExecutionHint = Ordinals
1516 | GlobalOrdinals
1516 | GlobalOrdinals
1517 | GlobalOrdinalsHash
1517 | GlobalOrdinalsHash
1518 | GlobalOrdinalsLowCardinality
1518 | GlobalOrdinalsLowCardinality
1519− | Map deriving (Eq, Show)
1519+ | Map deriving (Eq, Show, Generic)
1520
1520
1521data TimeInterval = Weeks
1521data TimeInterval = Weeks
1522 | Days
1522 | Days
@@ -1532,13 +1532,13 @@ data Interval = Year
1532 | Hour
1532 | Hour
1533 | Minute
1533 | Minute
1534 | Second
1534 | Second
1535− | FractionalInterval Float TimeInterval deriving (Eq, Show)
1535+ | FractionalInterval Float TimeInterval deriving (Eq, Show, Generic)
1536
1536
1537data Aggregation = TermsAgg TermsAggregation
1537data Aggregation = TermsAgg TermsAggregation
1538 | DateHistogramAgg DateHistogramAggregation
1538 | DateHistogramAgg DateHistogramAggregation
1539 | ValueCountAgg ValueCountAggregation
1539 | ValueCountAgg ValueCountAggregation
1540 | FilterAgg FilterAggregation
1540 | FilterAgg FilterAggregation
1541− | DateRangeAgg DateRangeAggregation deriving (Eq, Show)
1541+ | DateRangeAgg DateRangeAggregation deriving (Eq, Show, Generic)
1542
1542
1543
1543
1544data TermsAggregation = TermsAggregation { term :: Either Text Text
1544data TermsAggregation = TermsAggregation { term :: Either Text Text
@@ -1551,7 +1551,7 @@ data TermsAggregation = TermsAggregation { term :: Either Text Text
1551 , termCollectMode :: Maybe CollectionMode
1551 , termCollectMode :: Maybe CollectionMode
1552 , termExecutionHint :: Maybe ExecutionHint
1552 , termExecutionHint :: Maybe ExecutionHint
1553 , termAggs :: Maybe Aggregations
1553 , termAggs :: Maybe Aggregations
1554− } deriving (Eq, Show)
1554+ } deriving (Eq, Show, Generic)
1555
1555
1556data DateHistogramAggregation = DateHistogramAggregation { dateField :: FieldName
1556data DateHistogramAggregation = DateHistogramAggregation { dateField :: FieldName
1557 , dateInterval :: Interval
1557 , dateInterval :: Interval
@@ -1562,29 +1562,29 @@ data DateHistogramAggregation = DateHistogramAggregation { dateField :: Fie
1562 , datePreOffset :: Maybe Text
1562 , datePreOffset :: Maybe Text
1563 , datePostOffset :: Maybe Text
1563 , datePostOffset :: Maybe Text
1564 , dateAggs :: Maybe Aggregations
1564 , dateAggs :: Maybe Aggregations
1565− } deriving (Eq, Show)
1565+ } deriving (Eq, Show, Generic)
1566
1566
1567
1567
1568data DateRangeAggregation = DateRangeAggregation { draField :: FieldName
1568data DateRangeAggregation = DateRangeAggregation { draField :: FieldName
1569 , draFormat :: Maybe Text
1569 , draFormat :: Maybe Text
1570 , draRanges :: NonEmpty DateRangeAggRange
1570 , draRanges :: NonEmpty DateRangeAggRange
1571− } deriving (Eq, Show)
1571+ } deriving (Eq, Show, Generic)
1572
1572
1573data DateRangeAggRange = DateRangeFrom DateMathExpr
1573data DateRangeAggRange = DateRangeFrom DateMathExpr
1574 | DateRangeTo DateMathExpr
1574 | DateRangeTo DateMathExpr
1575− | DateRangeFromAndTo DateMathExpr DateMathExpr deriving (Eq, Show)
1575+ | DateRangeFromAndTo DateMathExpr DateMathExpr deriving (Eq, Show, Generic)
1576
1576
1577-- | See <https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math> for more information.
1577-- | See <https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math> for more information.
1578−data DateMathExpr = DateMathExpr DateMathAnchor [DateMathModifier] deriving (Eq, Show)
1578+data DateMathExpr = DateMathExpr DateMathAnchor [DateMathModifier] deriving (Eq, Show, Generic)
1579
1579
1580
1580
1581-- | Starting point for a date range. This along with the 'DateMathModifiers' gets you the date ES will start from.
1581-- | Starting point for a date range. This along with the 'DateMathModifiers' gets you the date ES will start from.
1582data DateMathAnchor = DMNow
1582data DateMathAnchor = DMNow
1583− | DMDate Day deriving (Eq, Show)
1583+ | DMDate Day deriving (Eq, Show, Generic)
1584
1584
1585data DateMathModifier = AddTime Int DateMathUnit
1585data DateMathModifier = AddTime Int DateMathUnit
1586 | SubtractTime Int DateMathUnit
1586 | SubtractTime Int DateMathUnit
1587− | RoundDownTo DateMathUnit deriving (Eq, Show)
1587+ | RoundDownTo DateMathUnit deriving (Eq, Show, Generic)
1588
1588
1589data DateMathUnit = DMYear
1589data DateMathUnit = DMYear
1590 | DMMonth
1590 | DMMonth
@@ -1592,15 +1592,15 @@ data DateMathUnit = DMYear
1592 | DMDay
1592 | DMDay
1593 | DMHour
1593 | DMHour
1594 | DMMinute
1594 | DMMinute
1595− | DMSecond deriving (Eq, Show)
1595+ | DMSecond deriving (Eq, Show, Generic)
1596
1596
1597-- | See <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html> for more information.
1597-- | See <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html> for more information.
1598data ValueCountAggregation = FieldValueCount FieldName
1598data ValueCountAggregation = FieldValueCount FieldName
1599− | ScriptValueCount Script deriving (Eq, Show)
1599+ | ScriptValueCount Script deriving (Eq, Show, Generic)
1600
1600
1601-- | 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.
1601-- | 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.
1602data FilterAggregation = FilterAggregation { faFilter :: Filter
1602data FilterAggregation = FilterAggregation { faFilter :: Filter
1603− , faAggs :: Maybe Aggregations} deriving (Eq, Show)
1603+ , faAggs :: Maybe Aggregations} deriving (Eq, Show, Generic)
1604
1604
1605mkTermsAggregation :: Text -> TermsAggregation
1605mkTermsAggregation :: Text -> TermsAggregation
1606mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1606mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
@@ -1756,7 +1756,7 @@ data DateRangeResult = DateRangeResult { dateRangeKey :: Text
1756 , dateRangeTo :: Maybe UTCTime
1756 , dateRangeTo :: Maybe UTCTime
1757 , dateRangeToAsString :: Maybe Text
1757 , dateRangeToAsString :: Maybe Text
1758 , dateRangeDocCount :: Int
1758 , dateRangeDocCount :: Int
1759− , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq)
1759+ , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq, Generic)
1760
1760
1761toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1761toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1762toTerms t a = M.lookup t a >>= deserialize
1762toTerms t a = M.lookup t a >>= deserialize
@@ -2861,7 +2861,7 @@ instance FromJSON UpdatableIndexSetting where
2861 <|> blocksWrite `taggedAt` ["blocks", "write"]
2861 <|> blocksWrite `taggedAt` ["blocks", "write"]
2862 <|> blocksMetaData `taggedAt` ["blocks", "metadata"]
2862 <|> blocksMetaData `taggedAt` ["blocks", "metadata"]
2863 where taggedAt f ks = taggedAt' f (Object o) ks
2863 where taggedAt f ks = taggedAt' f (Object o) ks
2864− taggedAt' f v [] = f =<< parseJSON v
2864+ taggedAt' f v [] = f =<< (parseJSON v <|> (parseJSON =<< unStringlyTypeJSON v))
2865 taggedAt' f v (k:ks) = withObject "Object" (\o -> do v' <- o .: k
2865 taggedAt' f v (k:ks) = withObject "Object" (\o -> do v' <- o .: k
2866 taggedAt' f v' ks) v
2866 taggedAt' f v' ks) v
2867 numberOfReplicas = pure . NumberOfReplicas
2867 numberOfReplicas = pure . NumberOfReplicas
@@ -2896,10 +2896,37 @@ instance FromJSON UpdatableIndexSetting where
2896instance FromJSON IndexSettingsSummary where
2896instance FromJSON IndexSettingsSummary where
2897 parseJSON = withObject "IndexSettingsSummary" parse
2897 parseJSON = withObject "IndexSettingsSummary" parse
2898 where parse o = case HM.toList o of
2898 where parse o = case HM.toList o of
2899− [(ixn, v)] -> IndexSettingsSummary (IndexName ixn)
2899+ [(ixn, v@(Object o'))] -> IndexSettingsSummary (IndexName ixn)
2900− <$> parseJSON v
2900+ <$> parseJSON v
2901− <*> parseJSON v
2901+ <*> (fmap (filter (not . redundant)) . parseSettings =<< o' .: "settings")
2902 _ -> fail "Expected single-key object with index name"
2902 _ -> fail "Expected single-key object with index name"
2903+ redundant (NumberOfReplicas _) = True
2904+ redundant _ = False
2905+
2906+-- | For some reason in the settings API, all leaf values get returned
2907+-- as strings. This function attepmts to recover from this for all
2908+-- non-recursive JSON types. If nothing can be done or the same value
2909+-- would be return, it returns 'mzero'
2910+unStringlyTypeJSON :: MonadPlus m => Value -> m Value
2911+unStringlyTypeJSON (String "true") = return (Bool True)
2912+unStringlyTypeJSON (String "false") = return (Bool False)
2913+unStringlyTypeJSON (String "null") = return Null
2914+unStringlyTypeJSON (String t) = case readMay (T.unpack t) of
2915+ Just n -> return (Number n)
2916+ Nothing -> mzero
2917+unStringlyTypeJSON _ = mzero
2918+
2919+
2920+parseSettings :: Object -> Parser [UpdatableIndexSetting]
2921+parseSettings o = do
2922+ o' <- o .: "index"
2923+ -- slice the index object into singleton hashmaps and try to parse each
2924+ parses <- forM (HM.toList o') $ \(k, v) -> do
2925+ -- blocks are now nested into the "index" key, which is not how they're serialized
2926+ let atRoot = Object (HM.singleton k v)
2927+ let atIndex = Object (HM.singleton "index" atRoot)
2928+ optional (parseJSON atRoot <|> parseJSON atIndex)
2929+ return (catMaybes parses)
2903
2930
2904oPath :: ToJSON a => NonEmpty Text -> a -> Value
2931oPath :: ToJSON a => NonEmpty Text -> a -> Value
2905oPath (k :| []) v = object [k .= v]
2932oPath (k :| []) v = object [k .= v]
@@ -2989,7 +3016,7 @@ instance ToJSON NominalDiffTimeJSON where
2989instance FromJSON NominalDiffTimeJSON where
3016instance FromJSON NominalDiffTimeJSON where
2990 parseJSON = withText "NominalDiffTime" parse
3017 parseJSON = withText "NominalDiffTime" parse
2991 where parse t = case T.takeEnd 1 t of
3018 where parse t = case T.takeEnd 1 t of
2992− "s" -> NominalDiffTimeJSON . fromInteger <$> parseReadText t
3019+ "s" -> NominalDiffTimeJSON . fromInteger <$> parseReadText (T.dropEnd 1 t)
2993 _ -> fail "Invalid or missing NominalDiffTime unit (expected s)"
3020 _ -> fail "Invalid or missing NominalDiffTime unit (expected s)"
2994
3021
2995instance ToJSON IndexTemplate where
3022instance ToJSON IndexTemplate where
@@ -3477,6 +3504,19 @@ instance FromJSON DocVersion where
3477 i <- parseJSON v
3504 i <- parseJSON v
3478 maybe (fail "DocVersion out of range") return $ mkDocVersion i
3505 maybe (fail "DocVersion out of range") return $ mkDocVersion i
3479
3506
3507+-- This insanity is because ES *sometimes* returns Replica/Shard counts as strings
3508+instance FromJSON ReplicaCount where
3509+ parseJSON v = parseAsInt v
3510+ <|> parseAsString v
3511+ where parseAsInt = fmap ReplicaCount . parseJSON
3512+ parseAsString = withText "ReplicaCount" (fmap ReplicaCount . parseReadText)
3513+
3514+instance FromJSON ShardCount where
3515+ parseJSON v = parseAsInt v
3516+ <|> parseAsString v
3517+ where parseAsInt = fmap ShardCount . parseJSON
3518+ parseAsString = withText "ShardCount" (fmap ShardCount . parseReadText)
3519+
3480instance Bounded DocVersion where
3520instance Bounded DocVersion where
3481 minBound = DocVersion 1
3521 minBound = DocVersion 1
3482 maxBound = DocVersion 9200000000000000000 -- 9.2e+18
3522 maxBound = DocVersion 9200000000000000000 -- 9.2e+18
tests/tests.hs+217−6
@@ -1,8 +1,11 @@
1+{-# LANGUAGE DefaultSignatures #-}
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE DeriveGeneric #-}
3+{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE ScopedTypeVariables #-}
6{-# LANGUAGE ScopedTypeVariables #-}
5{-# LANGUAGE TemplateHaskell #-}
7{-# LANGUAGE TemplateHaskell #-}
8+{-# LANGUAGE TypeOperators #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
9{-# OPTIONS_GHC -fno-warn-orphans #-}
7module Main where
10module Main where
8
11
@@ -26,12 +29,12 @@ import Data.Proxy
26import Data.Text (Text)
29import Data.Text (Text)
27import qualified Data.Text as T
30import qualified Data.Text as T
28import Data.Time.Calendar (Day (..), fromGregorian)
31import Data.Time.Calendar (Day (..), fromGregorian)
29−import Data.Time.Clock (UTCTime (..),
32+import Data.Time.Clock (NominalDiffTime, UTCTime (..),
30 secondsToDiffTime)
33 secondsToDiffTime)
31import Data.Typeable
34import Data.Typeable
32import qualified Data.Vector as V
35import qualified Data.Vector as V
33import Database.Bloodhound
36import Database.Bloodhound
34−import GHC.Generics (Generic)
37+import GHC.Generics as G
35import Network.HTTP.Client hiding (Proxy)
38import Network.HTTP.Client hiding (Proxy)
36import qualified Network.HTTP.Types.Status as NHTS
39import qualified Network.HTTP.Types.Status as NHTS
37import Prelude hiding (filter)
40import Prelude hiding (filter)
@@ -40,7 +43,6 @@ import Test.QuickCheck.Property.Monoid (T (..), eq, prop_Monoid)
40
43
41import Test.Hspec.QuickCheck (prop)
44import Test.Hspec.QuickCheck (prop)
42import Test.QuickCheck
45import Test.QuickCheck
43−import Test.QuickCheck.Instances ()
44
46
45testServer :: Server
47testServer :: Server
46testServer = Server "http://localhost:9200"
48testServer = Server "http://localhost:9200"
@@ -111,10 +113,13 @@ is v = testServerBranch >>= \x -> return $ x == Just (serverBranch v)
111when' :: Monad m => m Bool -> m () -> m ()
113when' :: Monad m => m Bool -> m () -> m ()
112when' b f = b >>= \x -> when x f
114when' b f = b >>= \x -> when x f
113
115
116+(==~) :: (ApproxEq a, Show a) => a -> a -> Property
117+a ==~ b = counterexample (show a ++ " !=~ " ++ show b) (a =~ b)
118+
114−propJSON :: forall a. (Arbitrary a, ToJSON a, FromJSON a, Show a, Eq a, Typeable a) => Proxy a -> Spec
119+propJSON :: forall a. (Arbitrary a, ToJSON a, FromJSON a, Show a, ApproxEq a, Typeable a) => Proxy a -> Spec
115propJSON _ = prop testName $ \(a :: a) ->
120propJSON _ = prop testName $ \(a :: a) ->
116 let jsonStr = "via " <> BL8.unpack (encode a)
121 let jsonStr = "via " <> BL8.unpack (encode a)
117− in counterexample jsonStr (parseEither parseJSON (toJSON a) === Right a)
122+ in counterexample jsonStr (parseEither parseJSON (toJSON a) ==~ Right a)
118 where testName = show ty <> " FromJSON/ToJSON roundtrips"
123 where testName = show ty <> " FromJSON/ToJSON roundtrips"
119 ty = typeOf (undefined :: a)
124 ty = typeOf (undefined :: a)
120
125
@@ -279,9 +284,202 @@ instance FromJSON BulkTest where
279instance ToJSON BulkTest where
284instance ToJSON BulkTest where
280 toJSON = genericToJSON defaultOptions
285 toJSON = genericToJSON defaultOptions
281
286
287+class GApproxEq f where
288+ gApproxEq :: f a -> f a -> Bool
289+
290+-- | Unit type
291+instance GApproxEq U1 where
292+ gApproxEq U1 U1 = True
293+
294+-- | Sum type, ensure same constructors, recurse
295+instance (GApproxEq a, GApproxEq b) => GApproxEq (a :+: b) where
296+ gApproxEq (L1 a) (L1 b) = gApproxEq a b
297+ gApproxEq (R1 a) (R1 b) = gApproxEq a b
298+ gApproxEq _ _ = False
299+
300+-- | Product type, ensure each field is approx eq
301+instance (GApproxEq a, GApproxEq b) => GApproxEq (a :*: b) where
302+ gApproxEq (a1 :*: b1) (a2 :*: b2) = gApproxEq a1 a2 && gApproxEq b1 b2
303+
304+-- | Value type, actually check the values for approx equality
305+instance (ApproxEq a) => GApproxEq (K1 i a) where
306+ gApproxEq (K1 a) (K1 b) = a =~ b
307+
308+instance (GApproxEq f) => GApproxEq (M1 i t f) where
309+ gApproxEq (M1 a) (M1 b) = gApproxEq a b
310+
311+-- | Typeclass for "equal where it matters". Use this to specify
312+-- less-strict equivalence for things such as lists that can wind up
313+-- in an unpredictable order
314+class ApproxEq a where
315+ (=~) :: a -> a -> Bool
316+ default (=~) :: (Generic a, GApproxEq (Rep a)) => a -> a -> Bool
317+ a =~ b = gApproxEq (G.from a) (G.from b)
318+
319+instance ApproxEq NominalDiffTime where (=~) = (==)
320+instance ApproxEq UTCTime where (=~) = (==)
321+instance ApproxEq Text where (=~) = (==)
322+instance ApproxEq Bool where (=~) = (==)
323+instance ApproxEq Int where (=~) = (==)
324+instance ApproxEq Double where (=~) = (==)
325+instance ApproxEq a => ApproxEq (NonEmpty a)
326+instance ApproxEq a => ApproxEq (Maybe a)
327+instance ApproxEq GeoPoint
328+instance ApproxEq Regexp
329+instance ApproxEq RangeValue
330+instance ApproxEq LessThan
331+instance ApproxEq LessThanEq
332+instance ApproxEq LessThanD
333+instance ApproxEq LessThanEqD
334+instance ApproxEq GreaterThan
335+instance ApproxEq GreaterThanEq
336+instance ApproxEq GreaterThanD
337+instance ApproxEq GreaterThanEqD
338+instance ApproxEq MinimumMatchHighLow
339+instance ApproxEq RegexpFlag
340+instance ApproxEq RegexpFlags
341+instance ApproxEq NullValue
342+instance ApproxEq Version
343+instance ApproxEq DistanceRange
344+instance ApproxEq IndexName
345+instance ApproxEq MappingName
346+instance ApproxEq DocId
347+instance ApproxEq IndexAliasRouting
348+instance ApproxEq RoutingValue
349+instance ApproxEq ShardCount
350+instance ApproxEq ReplicaCount
351+instance ApproxEq TemplateName
352+instance ApproxEq TemplatePattern
353+instance ApproxEq QueryString
354+instance ApproxEq FieldName
355+instance ApproxEq CacheName
356+instance ApproxEq CacheKey
357+instance ApproxEq Existence
358+instance ApproxEq CutoffFrequency
359+instance ApproxEq Analyzer
360+instance ApproxEq Lenient
361+instance ApproxEq Tiebreaker
362+instance ApproxEq Boost
363+instance ApproxEq BoostTerms
364+instance ApproxEq MaxExpansions
365+instance ApproxEq MinimumMatch
366+instance ApproxEq DisableCoord
367+instance ApproxEq IgnoreTermFrequency
368+instance ApproxEq MinimumTermFrequency
369+instance ApproxEq MaxQueryTerms
370+instance ApproxEq Fuzziness
371+instance ApproxEq PrefixLength
372+instance ApproxEq TypeName
373+instance ApproxEq PercentMatch
374+instance ApproxEq StopWord
375+instance ApproxEq QueryPath
376+instance ApproxEq AllowLeadingWildcard
377+instance ApproxEq LowercaseExpanded
378+instance ApproxEq EnablePositionIncrements
379+instance ApproxEq AnalyzeWildcard
380+instance ApproxEq GeneratePhraseQueries
381+instance ApproxEq Locale
382+instance ApproxEq MaxWordLength
383+instance ApproxEq MinWordLength
384+instance ApproxEq PhraseSlop
385+instance ApproxEq MinDocFrequency
386+instance ApproxEq MaxDocFrequency
387+instance ApproxEq Filter
388+instance ApproxEq Query
389+instance ApproxEq SimpleQueryStringQuery
390+instance ApproxEq FieldOrFields
391+instance ApproxEq SimpleQueryFlag
392+instance ApproxEq RegexpQuery
393+instance ApproxEq QueryStringQuery
394+instance ApproxEq RangeQuery
395+instance ApproxEq PrefixQuery
396+instance ApproxEq NestedQuery
397+instance ApproxEq MoreLikeThisFieldQuery
398+instance ApproxEq MoreLikeThisQuery
399+instance ApproxEq IndicesQuery
400+instance ApproxEq HasParentQuery
401+instance ApproxEq HasChildQuery
402+instance ApproxEq FuzzyQuery
403+instance ApproxEq FuzzyLikeFieldQuery
404+instance ApproxEq FuzzyLikeThisQuery
405+instance ApproxEq FilteredQuery
406+instance ApproxEq DisMaxQuery
407+instance ApproxEq CommonTermsQuery
408+instance ApproxEq CommonMinimumMatch
409+instance ApproxEq BoostingQuery
410+instance ApproxEq BoolQuery
411+instance ApproxEq MatchQuery
412+instance ApproxEq MultiMatchQueryType
413+instance ApproxEq BooleanOperator
414+instance ApproxEq ZeroTermsQuery
415+instance ApproxEq MatchQueryType
416+instance ApproxEq AliasRouting
417+instance ApproxEq IndexAliasCreate
418+instance ApproxEq SearchAliasRouting
419+instance ApproxEq ScoreType
420+instance ApproxEq Distance
421+instance ApproxEq DistanceUnit
422+instance ApproxEq DistanceType
423+instance ApproxEq OptimizeBbox
424+instance ApproxEq GeoBoundingBoxConstraint
425+instance ApproxEq GeoFilterType
426+instance ApproxEq GeoBoundingBox
427+instance ApproxEq LatLon
428+instance ApproxEq RangeExecution
429+instance ApproxEq FSType
430+instance ApproxEq CompoundFormat
431+instance ApproxEq InitialShardCount
432+instance ApproxEq Bytes
433+instance ApproxEq ReplicaBounds
434+instance ApproxEq Term
435+instance ApproxEq BoolMatch
436+instance ApproxEq MultiMatchQuery
437+instance ApproxEq IndexSettings
438+instance ApproxEq AllocationPolicy
439+instance ApproxEq Char
440+instance ApproxEq a => ApproxEq [a] where
441+ as =~ bs = and (zipWith (=~) as bs)
442+instance (ApproxEq l, ApproxEq r) => ApproxEq (Either l r) where
443+ Left a =~ Left b = a =~ b
444+ Right a =~ Right b = a =~ b
445+ _ =~ _ = False
446+instance ApproxEq NodeAttrFilter
447+instance ApproxEq NodeAttrName
448+
449+-- | Due to the way nodeattrfilters get serialized here, they may come
450+-- out in a different order, but they are morally equivalent
451+instance ApproxEq UpdatableIndexSetting where
452+ RoutingAllocationInclude a =~ RoutingAllocationInclude b =
453+ NE.sort a =~ NE.sort b
454+ RoutingAllocationExclude a =~ RoutingAllocationExclude b =
455+ NE.sort a =~ NE.sort b
456+ RoutingAllocationRequire a =~ RoutingAllocationRequire b =
457+ NE.sort a =~ NE.sort b
458+ a =~ b = a == b
459+
460+
461+
282noDuplicates :: Eq a => [a] -> Bool
462noDuplicates :: Eq a => [a] -> Bool
283noDuplicates xs = nub xs == xs
463noDuplicates xs = nub xs == xs
284
464
465+instance Arbitrary NominalDiffTime where
466+ arbitrary = fromInteger <$> arbitrary
467+
468+instance (Arbitrary k, Ord k, Arbitrary v) => Arbitrary (M.Map k v) where
469+ arbitrary = M.fromList <$> arbitrary
470+
471+instance Arbitrary Text where
472+ arbitrary = T.pack <$> arbitrary
473+
474+instance Arbitrary UTCTime where
475+ arbitrary = UTCTime
476+ <$> arbitrary
477+ <*> (fromRational . toRational <$> choose (0::Double, 86400))
478+
479+instance Arbitrary Day where
480+ arbitrary = ModifiedJulianDay <$> (2000 +) <$> arbitrary
481+ shrink = (ModifiedJulianDay <$>) . shrink . toModifiedJulianDay
482+
285instance Arbitrary a => Arbitrary (NonEmpty a) where
483instance Arbitrary a => Arbitrary (NonEmpty a) where
286 arbitrary = liftA2 (:|) arbitrary arbitrary
484 arbitrary = liftA2 (:|) arbitrary arbitrary
287
485
@@ -1172,6 +1370,20 @@ main = hspec $ do
1172 L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
1370 L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
1173 Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
1371 Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
1174
1372
1373+ describe "Index Settings" $ do
1374+ it "persists settings" $ withTestEnv $ do
1375+ _ <- deleteExampleIndex
1376+ _ <- createExampleIndex
1377+ let updates = BlocksWrite False :| []
1378+ updateResp <- updateIndexSettings updates testIndex
1379+ liftIO $ validateStatus updateResp 200
1380+ getResp <- getIndexSettings testIndex
1381+ liftIO $
1382+ getResp `shouldBe` Right (IndexSettingsSummary
1383+ testIndex
1384+ (IndexSettings (ShardCount 1) (ReplicaCount 0))
1385+ (NE.toList updates))
1386+
1175 describe "JSON instances" $ do
1387 describe "JSON instances" $ do
1176 propJSON (Proxy :: Proxy Version)
1388 propJSON (Proxy :: Proxy Version)
1177 propJSON (Proxy :: Proxy IndexName)
1389 propJSON (Proxy :: Proxy IndexName)
@@ -1195,7 +1407,6 @@ main = hspec $ do
1195 propJSON (Proxy :: Proxy Tiebreaker)
1407 propJSON (Proxy :: Proxy Tiebreaker)
1196 propJSON (Proxy :: Proxy Boost)
1408 propJSON (Proxy :: Proxy Boost)
1197 propJSON (Proxy :: Proxy BoostTerms)
1409 propJSON (Proxy :: Proxy BoostTerms)
1198− propJSON (Proxy :: Proxy MaxExpansions)
1199 propJSON (Proxy :: Proxy MinimumMatch)
1410 propJSON (Proxy :: Proxy MinimumMatch)
1200 propJSON (Proxy :: Proxy DisableCoord)
1411 propJSON (Proxy :: Proxy DisableCoord)
1201 propJSON (Proxy :: Proxy IgnoreTermFrequency)
1412 propJSON (Proxy :: Proxy IgnoreTermFrequency)