Documentation ¶
Index ¶
- Constants
- func WantsField(desired, flag Fields) bool
- type Aggregations
- type Aggs
- type AggsField
- type AggsStats
- type Buckets
- type Client
- type Config
- type Details
- type ElasticInfo
- type Error
- type Field
- type Fields
- type Filter
- type Hit
- type HitSet
- type HitSetTotal
- type HitsCallBack
- type MapStringStringOrMap
- type Mock
- type MultiTerms
- type QFBool
- type Query
- func (q *Query) DateRange() (lt, lte, gte time.Time, err error)
- func (q *Query) DesiredFields() Fields
- func (q *Query) Filters() map[string]string
- func (q *Query) IsScroll() bool
- func (q *Query) Key() string
- func (q *Query) MatchFilters() map[string]string
- func (q *Query) PrefixFilters() map[string]string
- type QueryFilter
- type Result
- type ScriptedMetric
Constants ¶
const ( ErrNoTimestampRange = "no timestamp range found" MaxSize = 10000 SearchPage = "_search" )
const ErrFailedQuery = "elasticsearch query failed"
const (
MaxEncodedDetailsLength = 16 * 1024
)
Variables ¶
This section is empty.
Functions ¶
func WantsField ¶
WantsField takes the output of Query.DesiredFields() and sees if the given field from amongst our Fields* flags is one of the desired fields.
If desired is 0 (the Query had no Source items set), this always returns true.
Types ¶
type Aggregations ¶
type Aggregations struct {
Stats *Buckets `json:"stats,omitempty"`
}
func (Aggregations) MarshalEasyJSON ¶
func (v Aggregations) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Aggregations) UnmarshalEasyJSON ¶
func (v *Aggregations) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Aggregations) UnmarshalJSON ¶
func (v *Aggregations) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type Aggs ¶
type Aggs struct {
Stats interface{} `json:"stats"`
}
Aggs is used to specify an aggregation query.
type AggsField ¶
type AggsField struct { Sum *Field `json:"sum,omitempty"` ScriptedMetric *ScriptedMetric `json:"scripted_metric,omitempty"` }
type AggsStats ¶
type AggsStats struct { MultiTerms *MultiTerms `json:"multi_terms,omitempty"` Terms *Field `json:"terms,omitempty"` Aggs map[string]AggsField `json:"aggs,omitempty"` }
type Buckets ¶
type Buckets struct {
Buckets []interface{} `json:"buckets,omitempty"`
}
func (Buckets) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Buckets) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Buckets) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type Client ¶
type Client struct { Error error // contains filtered or unexported fields }
Client is used to interact with an Elastic Search server.
func NewClient ¶
NewClient returns a Client that can talk to the configured Elastic Search server and will use the configured index for queries.
func (*Client) Info ¶
func (c *Client) Info() (*ElasticInfo, error)
Info tells you the version number info of the server.
type Config ¶
type Config struct { Host string Username string Password string Scheme string Port int Index string // contains filtered or unexported fields }
Config allows you to specify your Elastic Search server details. Currently only basic auth is supported, for an internal network server with "public" access.
type Details ¶
type Details struct { ID string `json:"_id"` AccountingName string `json:"ACCOUNTING_NAME"` AvailCPUTimeSec int64 `json:"AVAIL_CPU_TIME_SEC"` BOM string `json:"BOM"` Command string `json:"Command"` JobName string `json:"JOB_NAME"` Job string `json:"Job"` MemRequestedMB int64 `json:"MEM_REQUESTED_MB"` MemRequestedMBSec int64 `json:"MEM_REQUESTED_MB_SEC"` NumExecProcs int64 `json:"NUM_EXEC_PROCS"` PendingTimeSec int64 `json:"PENDING_TIME_SEC"` QueueName string `json:"QUEUE_NAME"` RunTimeSec int64 `json:"RUN_TIME_SEC"` Timestamp int64 `json:"timestamp"` UserName string `json:"USER_NAME"` WastedCPUSeconds float64 `json:"WASTED_CPU_SECONDS"` WastedMBSeconds float64 `json:"WASTED_MB_SECONDS"` }
Details holds the document information of a Hit.
func DeserializeDetails ¶
DeserializeDetails takes the output of Details.Serialize and converts it back in to a Details. Provide a non-zero Fields (from Query.DesiredFields()) to skip the unmarshalling of undesired fields, for a speed boost.
func (Details) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Details) Serialize ¶
Serialize converts a Details to a byte slice representation suitable for storing on disk.
func (*Details) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Details) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type ElasticInfo ¶
type ElasticInfo struct { Version struct { Number string } }
ElasticInfo is the type returned by an Info() request. It just tells you the version number of the server.
type Error ¶
type Error struct { Msg string // contains filtered or unexported fields }
Error is an error type that has a Msg with one of our const Err* messages.
type Filter ¶
type Filter []map[string]MapStringStringOrMap
type Hit ¶
func (Hit) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (*Hit) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Hit) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type HitSet ¶
type HitSet struct { Total HitSetTotal `json:"total"` Hits []Hit `json:"hits"` }
HitSet is the container of all Hits, plus a Total.Value which may tell you the total number of matching documents.
func (*HitSet) FromJSON ¶
func (v *HitSet) FromJSON(l *jlexer.Lexer, cb HitsCallBack) int
FromJSON is like UnmarshalJSON, but instead of storing all hits on the Result which might need too much memory, it passes each Hit to the given callback and only updates the Total count, but leaves Hits empty.
func (*HitSet) MarshalFields ¶
MarshalFields converts to JSON, but the JSON will only include the given fields of the hit details, even if they're zero value. If the desired map is empty, all fields are included.
func (*HitSet) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*HitSet) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type HitSetTotal ¶
type HitSetTotal struct {
Value int `json:"value"`
}
func (HitSetTotal) MarshalEasyJSON ¶
func (v HitSetTotal) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (*HitSetTotal) UnmarshalEasyJSON ¶
func (v *HitSetTotal) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*HitSetTotal) UnmarshalJSON ¶
func (v *HitSetTotal) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type HitsCallBack ¶
type HitsCallBack func(*Hit)
type MapStringStringOrMap ¶
type MapStringStringOrMap map[string]interface{}
func (MapStringStringOrMap) GetMapString ¶
func (m MapStringStringOrMap) GetMapString(key, subKey string) string
GetMapString returns the string value of the given subKey of the map with the given key in this map. Returns blank string if the keys didn't exist, or the value wasn't a string.
type Mock ¶
type Mock struct { *Client // contains filtered or unexported fields }
Mock helps you test elasticsearch queries without a real elasticsearch server.
func (*Mock) ScrollQuery ¶
ScrollQuery returns a http.Request that is requesting a scroll search. Any args are appended to the search url. Also returns the number of matching documents (which will match the number of hits you get back if your args include the scroll parameter).
type MultiTerms ¶
type Query ¶
type Query struct { Size int `json:"size"` Aggs *Aggs `json:"aggs,omitempty"` Query *QueryFilter `json:"query,omitempty"` Sort []string `json:"sort,omitempty"` Source []string `json:"_source,omitempty"` ScrollParamSet bool `json:"_scroll,omitempty"` }
Query describes the search query you wish to run against Elastic Search.
func NewQuery ¶
NewQuery looks at the given Request method, path, body and parameters to see if it's a search request, and converts it to a Query if so. The booleon will be false if not.
func (*Query) DateRange ¶
DateRange looks at the query's range->timestamp and returns the lt, lte and gte values. Returns an error if none were found.
func (*Query) DesiredFields ¶
DesiredFields returns a Fields bitmask value with all our Source values set. Call eg. WantsField(value, FieldAccountingName) to see if the returned value and thus this Query had a Source entry "ACCOUNTING_NAME".
If no Source values are set, this returns a 0 value which will be treated by WantsField() as wanting all fields.
func (*Query) IsScroll ¶
IsScroll returns true if the http.Request this Query was made from had a scroll parameter.
func (*Query) MatchFilters ¶ added in v1.1.0
MatchFilters returns the match_phrase key value pairs found in the query's filter. Returns an empty map if none found.
func (*Query) PrefixFilters ¶ added in v1.1.0
PrefixFilters returns the prefix key value pairs found in the query's filter. Returns an empty map if none found.
type QueryFilter ¶
type QueryFilter struct {
Bool QFBool `json:"bool"`
}
QueryFilter is used to filter the documents you're interested in.
type Result ¶
type Result struct { ScrollID string `json:"_scroll_id,omitempty"` Took int `json:"took"` TimedOut bool `json:"timed_out"` HitSet *HitSet `json:"hits"` Aggregations *Aggregations `json:"aggregations,omitempty"` PoolKey int `json:"-"` }
Result holds the results of a search query.
func NewResult ¶
func NewResult() *Result
NewResult returns a Result with an empty HitSet in it, suitable for adding hits and errors to.
func (*Result) FromJSON ¶
func (v *Result) FromJSON(data []byte, cb HitsCallBack) (int, error)
FromJSON is like UnmarshalJSON, but instead of storing all hits on the Result which might need too much memory, it passes each Hit to the given callback and only updates the Total count, but leaves Hits empty. Returns the number of Hits passed to the callback.
func (*Result) MarshalFields ¶
MarshalFields converts to JSON, but the JSON will only include the given fields of the hit details, even if they're zero value. If the desired map is empty, all fields are included.
func (*Result) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Result) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface