@@ -123,60 +123,8 @@ import Prelude hiding (filter, head)
124import Database.V1.Bloodhound.Types
124import Database.V1.Bloodhound.Types
127−-- >>> :set -XOverloadedStrings
128−-- >>> :set -XDeriveGeneric
129−-- >>> import Database.V1.Bloodhound
130−-- >>> let testServer = (Server "http://localhost:9200")
131−-- >>> let runBH' = withBH defaultManagerSettings testServer
132−-- >>> let testIndex = IndexName "twitter"
133−-- >>> let testMapping = MappingName "tweet"
134−-- >>> let defaultIndexSettings = IndexSettings (ShardCount 1) (ReplicaCount 0)
135−-- >>> data TweetMapping = TweetMapping deriving (Eq, Show)
136−-- >>> _ <- runBH' $ deleteIndex testIndex >> deleteMapping testIndex testMapping
137−-- >>> import GHC.Generics
138−-- >>> import Data.Time.Calendar (Day (..))
139−-- >>> import Data.Time.Clock (UTCTime (..), secondsToDiffTime)
141−--instance ToJSON TweetMapping where
142−-- toJSON TweetMapping =
143−-- object ["properties" .=
144−-- object ["location" .=
145−-- object ["type" .= ("geo_point" :: Text)]]]
146−--data Location = Location { lat :: Double
147−-- , lon :: Double } deriving (Eq, Generic, Show)
148−--data Tweet = Tweet { user :: Text
149−-- , postDate :: UTCTime
152−-- , location :: Location } deriving (Eq, Generic, Show)
153−--exampleTweet = Tweet { user = "bitemyapp"
154−-- , postDate = UTCTime
155−-- (ModifiedJulianDay 55000)
156−-- (secondsToDiffTime 10)
157−-- , message = "Use haskell!"
159−-- , location = Location 40.12 (-71.34) }
160−--instance ToJSON Tweet where
161−-- toJSON = genericToJSON defaultOptions
162−--instance FromJSON Tweet where
163−-- parseJSON = genericParseJSON defaultOptions
164−--instance ToJSON Location where
165−-- toJSON = genericToJSON defaultOptions
166−--instance FromJSON Location where
167−-- parseJSON = genericParseJSON defaultOptions
168−--data BulkTest = BulkTest { name :: Text } deriving (Eq, Generic, Show)
169−--instance FromJSON BulkTest where
170−-- parseJSON = genericParseJSON defaultOptions
171−--instance ToJSON BulkTest where
172−-- toJSON = genericToJSON defaultOptions
175-- | 'mkShardCount' is a straight-forward smart constructor for 'ShardCount'
126-- | 'mkShardCount' is a straight-forward smart constructor for 'ShardCount'
176-- which rejects 'Int' values below 1 and above 1000.
127-- which rejects 'Int' values below 1 and above 1000.
178−-- >>> mkShardCount 10
179−-- Just (ShardCount 10)
180mkShardCount :: Int -> Maybe ShardCount
128mkShardCount :: Int -> Maybe ShardCount
181mkShardCount n
129mkShardCount n
182 | n < 1 = Nothing
130 | n < 1 = Nothing
@@ -185,9 +133,6 @@ mkShardCount n
186-- | 'mkReplicaCount' is a straight-forward smart constructor for 'ReplicaCount'
134-- | 'mkReplicaCount' is a straight-forward smart constructor for 'ReplicaCount'
187-- which rejects 'Int' values below 0 and above 1000.
135-- which rejects 'Int' values below 0 and above 1000.
189−-- >>> mkReplicaCount 10
190−-- Just (ReplicaCount 10)
191mkReplicaCount :: Int -> Maybe ReplicaCount
136mkReplicaCount :: Int -> Maybe ReplicaCount
192mkReplicaCount n
137mkReplicaCount n
193 | n < 0 = Nothing
138 | n < 0 = Nothing
@@ -271,10 +216,6 @@ post = dispatch NHTM.methodPost
271-- https://github.com/supki/libjenkins/blob/master/src/Jenkins/Rest/Internal.hs
216-- https://github.com/supki/libjenkins/blob/master/src/Jenkins/Rest/Internal.hs
273-- | 'getStatus' fetches the 'Status' of a 'Server'
218-- | 'getStatus' fetches the 'Status' of a 'Server'
275−-- >>> serverStatus <- runBH' getStatus
276−-- >>> fmap status (serverStatus)
278getStatus :: MonadBH m => m (Maybe Status)
219getStatus :: MonadBH m => m (Maybe Status)
279getStatus = do
220getStatus = do
280 response <- get =<< url
221 response <- get =<< url
@@ -494,12 +435,6 @@ getNodesStats sel = parseEsResponse =<< get =<< url
494 selToSeg (NodeByAttribute (NodeAttrName a) v) = a <> ":" <> v
435 selToSeg (NodeByAttribute (NodeAttrName a) v) = a <> ":" <> v
496-- | 'createIndex' will create an index given a 'Server', 'IndexSettings', and an 'IndexName'.
437-- | 'createIndex' will create an index given a 'Server', 'IndexSettings', and an 'IndexName'.
498−-- >>> response <- runBH' $ createIndex defaultIndexSettings (IndexName "didimakeanindex")
499−-- >>> respIsTwoHunna response
501−-- >>> runBH' $ indexExists (IndexName "didimakeanindex")
503createIndex :: MonadBH m => IndexSettings -> IndexName -> m Reply
438createIndex :: MonadBH m => IndexSettings -> IndexName -> m Reply
504createIndex indexSettings (IndexName indexName) =
439createIndex indexSettings (IndexName indexName) =
505 bindM2 put url (return body)
440 bindM2 put url (return body)
@@ -508,23 +443,11 @@ createIndex indexSettings (IndexName indexName) =
510-- | 'deleteIndex' will delete an index given a 'Server', and an 'IndexName'.
445-- | 'deleteIndex' will delete an index given a 'Server', and an 'IndexName'.
512−-- >>> _ <- runBH' $ createIndex defaultIndexSettings (IndexName "didimakeanindex")
513−-- >>> response <- runBH' $ deleteIndex (IndexName "didimakeanindex")
514−-- >>> respIsTwoHunna response
516−-- >>> runBH' $ indexExists testIndex
518deleteIndex :: MonadBH m => IndexName -> m Reply
446deleteIndex :: MonadBH m => IndexName -> m Reply
519deleteIndex (IndexName indexName) =
447deleteIndex (IndexName indexName) =
520 delete =<< joinPath [indexName]
448 delete =<< joinPath [indexName]
522-- | 'updateIndexSettings' will apply a non-empty list of setting updates to an index
450-- | 'updateIndexSettings' will apply a non-empty list of setting updates to an index
524−-- >>> _ <- runBH' $ createIndex defaultIndexSettings (IndexName "unconfiguredindex")
525−-- >>> response <- runBH' $ updateIndexSettings (BlocksWrite False :| []) (IndexName "unconfiguredindex")
526−-- >>> respIsTwoHunna response
528updateIndexSettings :: MonadBH m => NonEmpty UpdatableIndexSetting -> IndexName -> m Reply
451updateIndexSettings :: MonadBH m => NonEmpty UpdatableIndexSetting -> IndexName -> m Reply
529updateIndexSettings updates (IndexName indexName) =
452updateIndexSettings updates (IndexName indexName) =
530 bindM2 put url (return body)
453 bindM2 put url (return body)
@@ -557,12 +480,6 @@ getIndexSettings (IndexName indexName) = do
557-- almost completely identical forcemerge API. Adding support to that
480-- almost completely identical forcemerge API. Adding support to that
558-- API would be trivial but due to the significant breaking changes,
481-- API would be trivial but due to the significant breaking changes,
559-- this library cannot currently be used with >= 2.0, so that feature was omitted.
482-- this library cannot currently be used with >= 2.0, so that feature was omitted.
561−-- >>> let ixn = IndexName "unoptimizedindex"
562−-- >>> _ <- runBH' $ deleteIndex ixn >> createIndex defaultIndexSettings ixn
563−-- >>> response <- runBH' $ optimizeIndex (IndexList (ixn :| [])) (defaultIndexOptimizationSettings { maxNumSegments = Just 1, onlyExpungeDeletes = True })
564−-- >>> respIsTwoHunna response
566optimizeIndex :: MonadBH m => IndexSelection -> IndexOptimizationSettings -> m Reply
483optimizeIndex :: MonadBH m => IndexSelection -> IndexOptimizationSettings -> m Reply
567optimizeIndex ixs IndexOptimizationSettings {..} =
484optimizeIndex ixs IndexOptimizationSettings {..} =
568 bindM2 post url (return body)
485 bindM2 post url (return body)
@@ -617,8 +534,6 @@ parseEsResponse reply
618-- | 'indexExists' enables you to check if an index exists. Returns 'Bool'
535-- | 'indexExists' enables you to check if an index exists. Returns 'Bool'
621−-- >>> exists <- runBH' $ indexExists testIndex
622indexExists :: MonadBH m => IndexName -> m Bool
537indexExists :: MonadBH m => IndexName -> m Bool
623indexExists (IndexName indexName) = do
538indexExists (IndexName indexName) = do
624 (_, exists) <- existentialQuery =<< joinPath [indexName]
539 (_, exists) <- existentialQuery =<< joinPath [indexName]
@@ -626,9 +541,6 @@ indexExists (IndexName indexName) = do
627-- | 'refreshIndex' will force a refresh on an index. You must
542-- | 'refreshIndex' will force a refresh on an index. You must
628-- do this if you want to read what you wrote.
543-- do this if you want to read what you wrote.
630−-- >>> _ <- runBH' $ createIndex defaultIndexSettings testIndex
631−-- >>> _ <- runBH' $ refreshIndex testIndex
632refreshIndex :: MonadBH m => IndexName -> m Reply
544refreshIndex :: MonadBH m => IndexName -> m Reply
633refreshIndex (IndexName indexName) =
545refreshIndex (IndexName indexName) =
634 bindM2 post url (return Nothing)
546 bindM2 post url (return Nothing)
@@ -655,15 +567,11 @@ openOrCloseIndexes oci (IndexName indexName) =
656-- | 'openIndex' opens an index given a 'Server' and an 'IndexName'. Explained in further detail at
568-- | 'openIndex' opens an index given a 'Server' and an 'IndexName'. Explained in further detail at
657-- <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
569-- <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
659−-- >>> reply <- runBH' $ openIndex testIndex
660openIndex :: MonadBH m => IndexName -> m Reply
570openIndex :: MonadBH m => IndexName -> m Reply
661openIndex = openOrCloseIndexes OpenIndex
571openIndex = openOrCloseIndexes OpenIndex
663-- | 'closeIndex' closes an index given a 'Server' and an 'IndexName'. Explained in further detail at
573-- | 'closeIndex' closes an index given a 'Server' and an 'IndexName'. Explained in further detail at
664-- <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
574-- <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
666−-- >>> reply <- runBH' $ closeIndex testIndex
667closeIndex :: MonadBH m => IndexName -> m Reply
575closeIndex :: MonadBH m => IndexName -> m Reply
668closeIndex = openOrCloseIndexes CloseIndex
576closeIndex = openOrCloseIndexes CloseIndex
@@ -684,20 +592,6 @@ listIndices =
684-- | 'updateIndexAliases' updates the server's index alias
592-- | 'updateIndexAliases' updates the server's index alias
685-- table. Operations are atomic. Explained in further detail at
593-- table. Operations are atomic. Explained in further detail at
686-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html>
594-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html>
688−-- >>> let src = IndexName "a-real-index"
689−-- >>> let aliasName = IndexName "an-alias"
690−-- >>> let iAlias = IndexAlias src (IndexAliasName aliasName)
691−-- >>> let aliasCreate = IndexAliasCreate Nothing Nothing
692−-- >>> _ <- runBH' $ deleteIndex src
693−-- >>> respIsTwoHunna <$> runBH' (createIndex defaultIndexSettings src)
695−-- >>> runBH' $ indexExists src
697−-- >>> respIsTwoHunna <$> runBH' (updateIndexAliases (AddAlias iAlias aliasCreate :| []))
699−-- >>> runBH' $ indexExists aliasName
701updateIndexAliases :: MonadBH m => NonEmpty IndexAliasAction -> m Reply
595updateIndexAliases :: MonadBH m => NonEmpty IndexAliasAction -> m Reply
702updateIndexAliases actions = bindM2 post url (return body)
596updateIndexAliases actions = bindM2 post url (return body)
703 where url = joinPath ["_aliases"]
597 where url = joinPath ["_aliases"]
@@ -713,9 +607,6 @@ getIndexAliases = parseEsResponse =<< get =<< url
713-- | 'putTemplate' creates a template given an 'IndexTemplate' and a 'TemplateName'.
607-- | 'putTemplate' creates a template given an 'IndexTemplate' and a 'TemplateName'.
714-- Explained in further detail at
608-- Explained in further detail at
715-- <https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices-templates.html>
609-- <https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices-templates.html>
717−-- >>> let idxTpl = IndexTemplate (TemplatePattern "tweet-*") (Just (IndexSettings (ShardCount 1) (ReplicaCount 1))) [toJSON TweetMapping]
718−-- >>> resp <- runBH' $ putTemplate idxTpl (TemplateName "tweet-tpl")
719putTemplate :: MonadBH m => IndexTemplate -> TemplateName -> m Reply
610putTemplate :: MonadBH m => IndexTemplate -> TemplateName -> m Reply
720putTemplate indexTemplate (TemplateName templateName) =
611putTemplate indexTemplate (TemplateName templateName) =
721 bindM2 put url (return body)
612 bindM2 put url (return body)
@@ -723,29 +614,18 @@ putTemplate indexTemplate (TemplateName templateName) =
723 body = Just $ encode indexTemplate
614 body = Just $ encode indexTemplate
725-- | 'templateExists' checks to see if a template exists.
616-- | 'templateExists' checks to see if a template exists.
727−-- >>> exists <- runBH' $ templateExists (TemplateName "tweet-tpl")
728templateExists :: MonadBH m => TemplateName -> m Bool
617templateExists :: MonadBH m => TemplateName -> m Bool
729templateExists (TemplateName templateName) = do
618templateExists (TemplateName templateName) = do
730 (_, exists) <- existentialQuery =<< joinPath ["_template", templateName]
619 (_, exists) <- existentialQuery =<< joinPath ["_template", templateName]
731 return exists
620 return exists
733-- | 'deleteTemplate' is an HTTP DELETE and deletes a template.
622-- | 'deleteTemplate' is an HTTP DELETE and deletes a template.
735−-- >>> let idxTpl = IndexTemplate (TemplatePattern "tweet-*") (Just (IndexSettings (ShardCount 1) (ReplicaCount 1))) [toJSON TweetMapping]
736−-- >>> _ <- runBH' $ putTemplate idxTpl (TemplateName "tweet-tpl")
737−-- >>> resp <- runBH' $ deleteTemplate (TemplateName "tweet-tpl")
738deleteTemplate :: MonadBH m => TemplateName -> m Reply
623deleteTemplate :: MonadBH m => TemplateName -> m Reply
739deleteTemplate (TemplateName templateName) =
624deleteTemplate (TemplateName templateName) =
740 delete =<< joinPath ["_template", templateName]
625 delete =<< joinPath ["_template", templateName]
742-- | 'putMapping' is an HTTP PUT and has upsert semantics. Mappings are schemas
627-- | 'putMapping' is an HTTP PUT and has upsert semantics. Mappings are schemas
743-- for documents in indexes.
628-- for documents in indexes.
745−-- >>> _ <- runBH' $ createIndex defaultIndexSettings testIndex
746−-- >>> resp <- runBH' $ putMapping testIndex testMapping TweetMapping
748−-- Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","21")], responseBody = "{\"acknowledged\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
749putMapping :: (MonadBH m, ToJSON a) => IndexName
629putMapping :: (MonadBH m, ToJSON a) => IndexName
750 -> MappingName -> a -> m Reply
630 -> MappingName -> a -> m Reply
751putMapping (IndexName indexName) (MappingName mappingName) mapping =
631putMapping (IndexName indexName) (MappingName mappingName) mapping =
@@ -757,12 +637,6 @@ putMapping (IndexName indexName) (MappingName mappingName) mapping =
758-- | 'deleteMapping' is an HTTP DELETE and deletes a mapping for a given index.
638-- | 'deleteMapping' is an HTTP DELETE and deletes a mapping for a given index.
759-- Mappings are schemas for documents in indexes.
639-- Mappings are schemas for documents in indexes.
761−-- >>> _ <- runBH' $ createIndex defaultIndexSettings testIndex
762−-- >>> _ <- runBH' $ putMapping testIndex testMapping TweetMapping
763−-- >>> resp <- runBH' $ deleteMapping testIndex testMapping
765−-- Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","21")], responseBody = "{\"acknowledged\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
766deleteMapping :: MonadBH m => IndexName -> MappingName -> m Reply
640deleteMapping :: MonadBH m => IndexName -> MappingName -> m Reply
767deleteMapping (IndexName indexName)
641deleteMapping (IndexName indexName)
768 (MappingName mappingName) =
642 (MappingName mappingName) =
@@ -788,10 +662,6 @@ versionCtlParams cfg =
788-- Elasticsearch. The document itself is simply something we can
662-- Elasticsearch. The document itself is simply something we can
789-- convert into a JSON 'Value'. The 'DocId' will function as the
663-- convert into a JSON 'Value'. The 'DocId' will function as the
790-- primary key for the document.
664-- primary key for the document.
792−-- >>> resp <- runBH' $ indexDocument testIndex testMapping defaultIndexDocumentSettings exampleTweet (DocId "1")
794−-- Response {responseStatus = Status {statusCode = 201, statusMessage = "Created"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","74")], responseBody = "{\"_index\":\"twitter\",\"_type\":\"tweet\",\"_id\":\"1\",\"_version\":1,\"created\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
795indexDocument :: (ToJSON doc, MonadBH m) => IndexName -> MappingName
665indexDocument :: (ToJSON doc, MonadBH m) => IndexName -> MappingName
796 -> IndexDocumentSettings -> doc -> DocId -> m Reply
666 -> IndexDocumentSettings -> doc -> DocId -> m Reply
797indexDocument (IndexName indexName)
667indexDocument (IndexName indexName)
@@ -816,8 +686,6 @@ updateDocument (IndexName indexName)
816 body = Just (encode $ object ["doc" .= toJSON patch])
686 body = Just (encode $ object ["doc" .= toJSON patch])
818-- | 'deleteDocument' is the primary way to delete a single document.
688-- | 'deleteDocument' is the primary way to delete a single document.
820−-- >>> _ <- runBH' $ deleteDocument testIndex testMapping (DocId "1")
821deleteDocument :: MonadBH m => IndexName -> MappingName
689deleteDocument :: MonadBH m => IndexName -> MappingName
822 -> DocId -> m Reply
690 -> DocId -> m Reply
823deleteDocument (IndexName indexName)
691deleteDocument (IndexName indexName)
@@ -830,10 +698,6 @@ deleteDocument (IndexName indexName)
830-- index\/update\/delete\/create operations. You pass a 'V.Vector' of 'BulkOperation's
698-- index\/update\/delete\/create operations. You pass a 'V.Vector' of 'BulkOperation's
831-- and a 'Server' to 'bulk' in order to send those operations up to your Elasticsearch
699-- and a 'Server' to 'bulk' in order to send those operations up to your Elasticsearch
832-- server to be performed. I changed from [BulkOperation] to a Vector due to memory overhead.
700-- server to be performed. I changed from [BulkOperation] to a Vector due to memory overhead.
834−-- >>> let stream = V.fromList [BulkIndex testIndex testMapping (DocId "2") (toJSON (BulkTest "blah"))]
835−-- >>> _ <- runBH' $ bulk stream
836−-- >>> _ <- runBH' $ refreshIndex testIndex
837bulk :: MonadBH m => V.Vector BulkOperation -> m Reply
701bulk :: MonadBH m => V.Vector BulkOperation -> m Reply
838bulk bulkOps = bindM2 post url (return body)
702bulk bulkOps = bindM2 post url (return body)
839 where url = joinPath ["_bulk"]
703 where url = joinPath ["_bulk"]
@@ -841,10 +705,6 @@ bulk bulkOps = bindM2 post url (return body)
842-- | 'encodeBulkOperations' is a convenience function for dumping a vector of 'BulkOperation'
706-- | 'encodeBulkOperations' is a convenience function for dumping a vector of 'BulkOperation'
843-- into an 'L.ByteString'
707-- into an 'L.ByteString'
845−-- >>> let bulkOps = V.fromList [BulkIndex testIndex testMapping (DocId "2") (toJSON (BulkTest "blah"))]
846−-- >>> encodeBulkOperations bulkOps
847−-- "\n{\"index\":{\"_type\":\"tweet\",\"_id\":\"2\",\"_index\":\"twitter\"}}\n{\"name\":\"blah\"}\n"
848encodeBulkOperations :: V.Vector BulkOperation -> L.ByteString
708encodeBulkOperations :: V.Vector BulkOperation -> L.ByteString
849encodeBulkOperations stream = collapsed where
709encodeBulkOperations stream = collapsed where
850 blobs = fmap encodeBulkOperation stream
710 blobs = fmap encodeBulkOperation stream
@@ -863,10 +723,6 @@ mkBulkStreamValue operation indexName mappingName docId =
864-- | 'encodeBulkOperation' is a convenience function for dumping a single 'BulkOperation'
724-- | 'encodeBulkOperation' is a convenience function for dumping a single 'BulkOperation'
865-- into an 'L.ByteString'
725-- into an 'L.ByteString'
867−-- >>> let bulkOp = BulkIndex testIndex testMapping (DocId "2") (toJSON (BulkTest "blah"))
868−-- >>> encodeBulkOperation bulkOp
869−-- "{\"index\":{\"_type\":\"tweet\",\"_id\":\"2\",\"_index\":\"twitter\"}}\n{\"name\":\"blah\"}"
870encodeBulkOperation :: BulkOperation -> L.ByteString
726encodeBulkOperation :: BulkOperation -> L.ByteString
871encodeBulkOperation (BulkIndex (IndexName indexName)
727encodeBulkOperation (BulkIndex (IndexName indexName)
872 (MappingName mappingName)
728 (MappingName mappingName)
@@ -896,8 +752,6 @@ encodeBulkOperation (BulkUpdate (IndexName indexName)
896-- | 'getDocument' is a straight-forward way to fetch a single document from
752-- | 'getDocument' is a straight-forward way to fetch a single document from
897-- Elasticsearch using a 'Server', 'IndexName', 'MappingName', and a 'DocId'.
753-- Elasticsearch using a 'Server', 'IndexName', 'MappingName', and a 'DocId'.
898-- The 'DocId' is the primary key for your Elasticsearch document.
754-- The 'DocId' is the primary key for your Elasticsearch document.
900−-- >>> yourDoc <- runBH' $ getDocument testIndex testMapping (DocId "1")
901getDocument :: MonadBH m => IndexName -> MappingName
755getDocument :: MonadBH m => IndexName -> MappingName
902 -> DocId -> m Reply
756 -> DocId -> m Reply
903getDocument (IndexName indexName)
757getDocument (IndexName indexName)
@@ -906,8 +760,6 @@ getDocument (IndexName indexName)
907-- | 'documentExists' enables you to check if a document exists. Returns 'Bool'
761-- | 'documentExists' enables you to check if a document exists. Returns 'Bool'
910−-- >>> exists <- runBH' $ documentExists testIndex testMapping Nothing (DocId "1")
911documentExists :: MonadBH m => IndexName -> MappingName
763documentExists :: MonadBH m => IndexName -> MappingName
912 -> Maybe DocumentParent -> DocId -> m Bool
764 -> Maybe DocumentParent -> DocId -> m Bool
913documentExists (IndexName indexName) (MappingName mappingName)
765documentExists (IndexName indexName) (MappingName mappingName)
@@ -924,30 +776,18 @@ dispatchSearch url search = post url' (Just (encode search))
925-- | 'searchAll', given a 'Search', will perform that search against all indexes
777-- | 'searchAll', given a 'Search', will perform that search against all indexes
926-- on an Elasticsearch server. Try to avoid doing this if it can be helped.
778-- on an Elasticsearch server. Try to avoid doing this if it can be helped.
928−-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
929−-- >>> let search = mkSearch (Just query) Nothing
930−-- >>> reply <- runBH' $ searchAll search
931searchAll :: MonadBH m => Search -> m Reply
779searchAll :: MonadBH m => Search -> m Reply
932searchAll = bindM2 dispatchSearch url . return
780searchAll = bindM2 dispatchSearch url . return
933 where url = joinPath ["_search"]
781 where url = joinPath ["_search"]
935-- | 'searchByIndex', given a 'Search' and an 'IndexName', will perform that search
783-- | 'searchByIndex', given a 'Search' and an 'IndexName', will perform that search
936-- against all mappings within an index on an Elasticsearch server.
784-- against all mappings within an index on an Elasticsearch server.
938−-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
939−-- >>> let search = mkSearch (Just query) Nothing
940−-- >>> reply <- runBH' $ searchByIndex testIndex search
941searchByIndex :: MonadBH m => IndexName -> Search -> m Reply
785searchByIndex :: MonadBH m => IndexName -> Search -> m Reply
942searchByIndex (IndexName indexName) = bindM2 dispatchSearch url . return
786searchByIndex (IndexName indexName) = bindM2 dispatchSearch url . return
943 where url = joinPath [indexName, "_search"]
787 where url = joinPath [indexName, "_search"]
945-- | 'searchByType', given a 'Search', 'IndexName', and 'MappingName', will perform that
789-- | 'searchByType', given a 'Search', 'IndexName', and 'MappingName', will perform that
946-- search against a specific mapping within an index on an Elasticsearch server.
790-- search against a specific mapping within an index on an Elasticsearch server.
948−-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
949−-- >>> let search = mkSearch (Just query) Nothing
950−-- >>> reply <- runBH' $ searchByType testIndex testMapping search
951searchByType :: MonadBH m => IndexName -> MappingName -> Search
791searchByType :: MonadBH m => IndexName -> MappingName -> Search
952 -> m Reply
792 -> m Reply
953searchByType (IndexName indexName)
793searchByType (IndexName indexName)
@@ -1020,29 +860,16 @@ scanSearch indexName mappingName search = do
1020-- to Nothing in case you only care about your 'Query' and 'Filter'. Use record update
860-- to Nothing in case you only care about your 'Query' and 'Filter'. Use record update
1021-- syntax if you want to add things like aggregations or highlights while still using
861-- syntax if you want to add things like aggregations or highlights while still using
1022-- this helper function.
862-- this helper function.
1024−-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
1025−-- >>> mkSearch (Just query) Nothing
1026−-- Search {queryBody = Just (TermQuery (Term {termField = "user", termValue = "bitemyapp"}) Nothing), filterBody = Nothing, sortBody = Nothing, aggBody = Nothing, highlight = Nothing, trackSortScores = False, from = From 0, size = Size 10, searchType = SearchTypeQueryThenFetch, fields = Nothing, source = Nothing}
1027mkSearch :: Maybe Query -> Maybe Filter -> Search
863mkSearch :: Maybe Query -> Maybe Filter -> Search
1028mkSearch query filter = Search query filter Nothing Nothing Nothing False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing
864mkSearch query filter = Search query filter Nothing Nothing Nothing False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing
1030-- | 'mkAggregateSearch' is a helper function that defaults everything in a 'Search' except for
866-- | 'mkAggregateSearch' is a helper function that defaults everything in a 'Search' except for
1031-- the 'Query' and the 'Aggregation'.
867-- the 'Query' and the 'Aggregation'.
1033−-- >>> let terms = TermsAgg $ (mkTermsAggregation "user") { termCollectMode = Just BreadthFirst }
1035−-- TermsAgg (TermsAggregation {term = Left "user", termInclude = Nothing, termExclude = Nothing, termOrder = Nothing, termMinDocCount = Nothing, termSize = Nothing, termShardSize = Nothing, termCollectMode = Just BreadthFirst, termExecutionHint = Nothing, termAggs = Nothing})
1036−-- >>> let myAggregation = mkAggregateSearch Nothing $ mkAggregations "users" terms
1037mkAggregateSearch :: Maybe Query -> Aggregations -> Search
868mkAggregateSearch :: Maybe Query -> Aggregations -> Search
1038mkAggregateSearch query mkSearchAggs = Search query Nothing Nothing (Just mkSearchAggs) Nothing False (From 0) (Size 0) SearchTypeQueryThenFetch Nothing Nothing
869mkAggregateSearch query mkSearchAggs = Search query Nothing Nothing (Just mkSearchAggs) Nothing False (From 0) (Size 0) SearchTypeQueryThenFetch Nothing Nothing
1040-- | 'mkHighlightSearch' is a helper function that defaults everything in a 'Search' except for
871-- | 'mkHighlightSearch' is a helper function that defaults everything in a 'Search' except for
1041-- the 'Query' and the 'Aggregation'.
872-- the 'Query' and the 'Aggregation'.
1043−-- >>> let query = QueryMatchQuery $ mkMatchQuery (FieldName "_all") (QueryString "haskell")
1044−-- >>> let testHighlight = Highlights Nothing [FieldHighlight (FieldName "message") Nothing]
1045−-- >>> let search = mkHighlightSearch (Just query) testHighlight
1046mkHighlightSearch :: Maybe Query -> Highlights -> Search
873mkHighlightSearch :: Maybe Query -> Highlights -> Search
1047mkHighlightSearch query searchHighlights = Search query Nothing Nothing Nothing (Just searchHighlights) False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing
874mkHighlightSearch query searchHighlights = Search query Nothing Nothing Nothing (Just searchHighlights) False (From 0) (Size 10) SearchTypeQueryThenFetch Nothing Nothing
@@ -1050,13 +877,6 @@ mkHighlightSearch query searchHighlights = Search query Nothing Nothing Nothing
1050-- and size fields for the search. The from parameter defines the offset
877-- and size fields for the search. The from parameter defines the offset
1051-- from the first result you want to fetch. The size parameter allows you to
878-- from the first result you want to fetch. The size parameter allows you to
1052-- configure the maximum amount of hits to be returned.
879-- configure the maximum amount of hits to be returned.
1054−-- >>> let query = QueryMatchQuery $ mkMatchQuery (FieldName "_all") (QueryString "haskell")
1055−-- >>> let search = mkSearch (Just query) Nothing
1057−-- Search {queryBody = Just (QueryMatchQuery (MatchQuery {matchQueryField = FieldName "_all", matchQueryQueryString = QueryString "haskell", matchQueryOperator = Or, matchQueryZeroTerms = ZeroTermsNone, matchQueryCutoffFrequency = Nothing, matchQueryMatchType = Nothing, matchQueryAnalyzer = Nothing, matchQueryMaxExpansions = Nothing, matchQueryLenient = Nothing, matchQueryBoost = Nothing})), filterBody = Nothing, sortBody = Nothing, aggBody = Nothing, highlight = Nothing, trackSortScores = False, from = From 0, size = Size 10, searchType = SearchTypeQueryThenFetch, fields = Nothing, source = Nothing}
1058−-- >>> pageSearch (From 10) (Size 100) search
1059−-- Search {queryBody = Just (QueryMatchQuery (MatchQuery {matchQueryField = FieldName "_all", matchQueryQueryString = QueryString "haskell", matchQueryOperator = Or, matchQueryZeroTerms = ZeroTermsNone, matchQueryCutoffFrequency = Nothing, matchQueryMatchType = Nothing, matchQueryAnalyzer = Nothing, matchQueryMaxExpansions = Nothing, matchQueryLenient = Nothing, matchQueryBoost = Nothing})), filterBody = Nothing, sortBody = Nothing, aggBody = Nothing, highlight = Nothing, trackSortScores = False, from = From 10, size = Size 100, searchType = SearchTypeQueryThenFetch, fields = Nothing, source = Nothing}
1060pageSearch :: From -- ^ The result offset
880pageSearch :: From -- ^ The result offset
1061 -> Size -- ^ The number of results to return
881 -> Size -- ^ The number of results to return
1062 -> Search -- ^ The current seach
882 -> Search -- ^ The current seach