1{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE MultiParamTypeClasses #-}
5{-# LANGUAGE NamedFieldPuns #-}
6{-# LANGUAGE OverloadedStrings #-}
7{-# LANGUAGE RecordWildCards #-}
8{-# LANGUAGE UndecidableInstances #-}
10-------------------------------------------------------------------------------
12-- Module : Database.Bloodhound.Types
13-- Copyright : (C) 2014, 2018 Chris Allen
14-- License : BSD-style (see the file LICENSE)
15-- Maintainer : Chris Allen <cma@bitemyapp.com
16-- Stability : provisional
17-- Portability : RecordWildCards
19-- Data types for describing actions and data structures performed to interact
20-- with Elasticsearch. The two main buckets your queries against Elasticsearch
21-- will fall into are 'Query's and 'Filter's. 'Filter's are more like
22-- traditional database constraints and often have preferable performance
23-- properties. 'Query's support human-written textual queries, such as fuzzy
25-------------------------------------------------------------------------------
29module Database.Bloodhound.Types
31 , defaultIndexSettings
32 , defaultIndexDocumentSettings
43 , mkTermsScriptAggregation
45 , mkCardinalityAggregation
48 , mkExtendedStatsAggregation
71 , UpdatableIndexSetting(..)
72 , IndexSettingsSummary(..)
73 , AllocationPolicy(..)
81 , InitialShardCount(..)
91 , EsProtocolException(..)
94 , IndexAliasAction(..)
95 , IndexAliasCreate(..)
96 , IndexAliasSummary(..)
97 , IndexAliasesSummary(..)
99 , SearchAliasRouting(..)
100 , IndexAliasRouting(..)
103 , ExternalDocVersion(..)
106 , IndexDocumentSettings(..)
117 , PatternOrPatterns(..)
128 , GeoBoundingBoxConstraint(..)
165 , ForceMergeIndexSettings(..)
166 , defaultForceMergeIndexSettings
168 , TemplatePattern(..)
186 , MultiMatchQuery(..)
189 , CommonTermsQuery(..)
190 , FunctionScoreQuery(..)
193 , FunctionScoreFunctions(..)
194 , ComponentFunctionScoreFunction(..)
195 , FunctionScoreFunction(..)
198 , FieldValueFactor(..)
201 , FactorMissingFieldValue(..)
203 , FuzzyLikeThisQuery(..)
204 , FuzzyLikeFieldQuery(..)
209 , MoreLikeThisQuery(..)
210 , MoreLikeThisFieldQuery(..)
213 , QueryStringQuery(..)
214 , SimpleQueryStringQuery(..)
218 , TemplateQueryInline(..)
219 , TemplateQueryKeyValuePairs(..)
221 , BooleanOperator(..)
223 , CutoffFrequency(..)
231 , MultiMatchQueryType(..)
235 , CommonMinimumMatch(..)
236 , MinimumMatchHighLow(..)
239 , IgnoreTermFrequency(..)
248 , MaxDocFrequency(..)
249 , MinDocFrequency(..)
253 , MinimumTermFrequency(..)
255 , FieldDefinition(..)
258 , AllowLeadingWildcard(..)
259 , LowercaseExpanded(..)
260 , GeneratePhraseQueries(..)
262 , AnalyzeWildcard(..)
263 , EnablePositionIncrements(..)
264 , SimpleQueryFlag(..)
274 , SnapshotRepoSelection(..)
275 , GenericSnapshotRepo(..)
277 , SnapshotRepoConversionError(..)
278 , SnapshotRepoType(..)
279 , GenericSnapshotRepoSettings(..)
280 , SnapshotRepoUpdateSettings(..)
281 , defaultSnapshotRepoUpdateSettings
282 , SnapshotRepoName(..)
283 , SnapshotRepoPattern(..)
284 , SnapshotVerification(..)
285 , SnapshotNodeVerification(..)
292 , NodeBreakersStats(..)
293 , NodeBreakerStats(..)
295 , NodeTransportStats(..)
297 , NodeDataPathStats(..)
298 , NodeFSTotalStats(..)
299 , NodeNetworkStats(..)
300 , NodeThreadPoolsStats(..)
301 , NodeThreadPoolStats(..)
303 , JVMBufferPoolStats(..)
306 , NodeProcessStats(..)
309 , NodeIndicesStats(..)
315 , NodeTransportInfo(..)
316 , BoundTransportAddress(..)
317 , NodeNetworkInfo(..)
319 , NetworkInterfaceName(..)
320 , NodeNetworkInterface(..)
321 , NodeThreadPoolsInfo(..)
322 , NodeThreadPoolInfo(..)
332 , NodeProcessInfo(..)
334 , SnapshotCreateSettings(..)
335 , defaultSnapshotCreateSettings
336 , SnapshotSelection(..)
337 , SnapshotPattern(..)
339 , SnapshotShardFailure(..)
343 , SnapshotRestoreSettings(..)
344 , defaultSnapshotRestoreSettings
345 , RestoreRenamePattern(..)
346 , RestoreRenameToken(..)
350 , RestoreIndexSettings(..)
353 , PhraseSuggester(..)
354 , PhraseSuggesterHighlighter(..)
355 , PhraseSuggesterCollate(..)
358 , SuggestResponse(..)
359 , NamedSuggestionResponse(..)
360 , DirectGenerators(..)
362 , DirectGeneratorSuggestModeTypes (..)
369 , BucketAggregation(..)
370 , TermsAggregation(..)
371 , MissingAggregation(..)
372 , ValueCountAggregation(..)
373 , FilterAggregation(..)
374 , CardinalityAggregation(..)
375 , DateHistogramAggregation(..)
376 , DateRangeAggregation(..)
377 , DateRangeAggRange(..)
380 , DateMathModifier(..)
382 , TopHitsAggregation(..)
383 , StatisticsAggregation(..)
388 , HighlightSettings(..)
390 , PostingsHighlight(..)
391 , FastVectorHighlight(..)
392 , CommonHighlight(..)
394 , HighlightEncoder(..)
400 , DateHistogramResult(..)
401 , DateRangeResult(..)
408 , AnalyzerDefinition(..)
409 , TokenizerDefinition(..)
410 , TokenFilterDefinition(..)
411 , CharFilterDefinition(..)
418import Bloodhound.Import
420import Database.Bloodhound.Internal.Aggregation
421import Database.Bloodhound.Internal.Analysis
422import Database.Bloodhound.Internal.Client
423import Database.Bloodhound.Internal.Highlight
424import Database.Bloodhound.Internal.Newtypes
425import Database.Bloodhound.Internal.Query
426import Database.Bloodhound.Internal.Sort
427import Database.Bloodhound.Internal.Suggest
429{-| 'unpackId' is a silly convenience function that gets used once.
431unpackId :: DocId -> Text
432unpackId (DocId docId) = docId
434type TrackSortScores = Bool
436data Search = Search { queryBody :: Maybe Query
437 , filterBody :: Maybe Filter
438 , sortBody :: Maybe Sort
439 , aggBody :: Maybe Aggregations
440 , highlight :: Maybe Highlights
442 , trackSortScores :: TrackSortScores
445 , searchType :: SearchType
446 , searchAfterKey :: Maybe SearchAfterKey
447 , fields :: Maybe [FieldName]
448 , scriptFields :: Maybe ScriptFields
449 , source :: Maybe Source
450 , suggestBody :: Maybe Suggest -- ^ Only one Suggestion request / response per Search is supported.
451 } deriving (Eq, Show)
454instance ToJSON Search where
455 toJSON (Search mquery sFilter sort searchAggs
456 highlight sTrackSortScores sFrom sSize _ sAfter sFields
457 sScriptFields sSource sSuggest) =
458 omitNulls [ "query" .= query'
460 , "aggregations" .= searchAggs
461 , "highlight" .= highlight
464 , "track_scores" .= sTrackSortScores
465 , "search_after" .= sAfter
466 , "fields" .= sFields
467 , "script_fields" .= sScriptFields
468 , "_source" .= sSource
469 , "suggest" .= sSuggest]
471 where query' = case sFilter of
476 $ mkBoolQuery (maybeToList mquery)
479data SearchType = SearchTypeQueryThenFetch
480 | SearchTypeDfsQueryThenFetch
485 | SourcePatterns PatternOrPatterns
486 | SourceIncludeExclude Include Exclude
489instance ToJSON Source where
490 toJSON NoSource = toJSON False
491 toJSON (SourcePatterns patterns) = toJSON patterns
492 toJSON (SourceIncludeExclude incl excl) = object [ "includes" .= incl, "excludes" .= excl ]
494data PatternOrPatterns = PopPattern Pattern
495 | PopPatterns [Pattern] deriving (Eq, Read, Show)
497instance ToJSON PatternOrPatterns where
498 toJSON (PopPattern pattern) = toJSON pattern
499 toJSON (PopPatterns patterns) = toJSON patterns
501data Include = Include [Pattern] deriving (Eq, Read, Show)
502data Exclude = Exclude [Pattern] deriving (Eq, Read, Show)
504instance ToJSON Include where
505 toJSON (Include patterns) = toJSON patterns
507instance ToJSON Exclude where
508 toJSON (Exclude patterns) = toJSON patterns
510newtype Pattern = Pattern Text deriving (Eq, Read, Show)
512instance ToJSON Pattern where
513 toJSON (Pattern pattern) = toJSON pattern
516 SearchResult { took :: Int
518 , shards :: ShardResult
519 , searchHits :: SearchHits a
520 , aggregations :: Maybe AggregationResults
521 , scrollId :: Maybe ScrollId
522 -- ^ Only one Suggestion request / response per
523 -- Search is supported.
524 , suggest :: Maybe NamedSuggestionResponse
528instance (FromJSON a) => FromJSON (SearchResult a) where
529 parseJSON (Object v) = SearchResult <$>
534 v .:? "aggregations" <*>
535 v .:? "_scroll_id" <*>
541 deriving (Eq, Show, Ord, ToJSON, FromJSON)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list