Documentation ¶
Index ¶
- Constants
- func BuildQuery(query string) map[string]interface{}
- func KindAggregation(maxBuckets int) (string, map[string]interface{})
- func TimeseriesAggregation() (string, map[string]interface{})
- type ElasticKustomizeResult
- type KustomizeHits
- type KustomizeIndex
- func (idx KustomizeIndex) CreateIndex(mappings []byte, settings []byte) error
- func (idx KustomizeIndex) Delete(id string) error
- func (idx KustomizeIndex) DeleteIndex() error
- func (ki *KustomizeIndex) IterateQuery(query []byte, batchSize int, timeout time.Duration) *KustomizeIterator
- func (ki *KustomizeIndex) Put(id string, doc *doc.KustomizationDocument) (string, error)
- func (ki *KustomizeIndex) Search(query string, opts KustomizeSearchOptions) (*KustomizeResult, error)
- func (idx KustomizeIndex) UpdateMapping(mappings []byte) error
- func (idx KustomizeIndex) UpdateSetting(settings []byte) error
- type KustomizeIterator
- type KustomizeResult
- type KustomizeSearchOptions
- type SearchOptions
Constants ¶
const (
AggregationKeyword = "aggs"
)
Variables ¶
This section is empty.
Functions ¶
func BuildQuery ¶
Build an elasticsearch query from a user query.
func KindAggregation ¶
Return aggregation of results based off of their kinds.
func TimeseriesAggregation ¶
Return a timeseries of kustomization file counts.
Types ¶
type ElasticKustomizeResult ¶
type ElasticKustomizeResult struct { ScrollID *string `json:"_scroll_id,omitempty"` Hits *struct { Total int `json:"total"` Hits []struct { ID string `json:"_id"` Document doc.KustomizationDocument `json:"_source"` } `json:"hits"` } `json:"hits,omitempty"` Aggregations *struct { Timeseries *struct { Buckets []struct { Key string `json:"key_as_string"` Count int `json:"doc_count"` } } `json:"timeseries,omitempty"` Kinds *struct { OtherCount int `json:"sum_other_doc_count"` Buckets []struct { Key string `json:"key"` Count int `json:"doc_count"` } } `json:"kinds,omitempty"` } `json:"aggregations,omitempty"` }
Elasticsearch has some sometimes inconsistent labels, and some pretty ugly label choices. However, the structure seems reasonable, so I wanted to use it if possible. This method needs two copies of the types to make the json strings different. The Copies must be the exact same type/structure, so the types must be declared inline. Go will check that these are convertible at compile time, and converting at runtime is a noop.
type KustomizeHits ¶
type KustomizeHits []struct { ID string `json:"id"` Document doc.KustomizationDocument `json:"result"` }
Redefinition of Hits structure. Must match the json string of KustomizeResult.Hits.Hits. Declared as a convenience for iteration.
type KustomizeIndex ¶
type KustomizeIndex struct {
// contains filtered or unexported fields
}
func NewKustomizeIndex ¶
func NewKustomizeIndex(ctx context.Context) (*KustomizeIndex, error)
Create index reference to the index containing the kustomize documents.
func (KustomizeIndex) CreateIndex ¶
Create an index providing both the mappings and the settings.
func (*KustomizeIndex) IterateQuery ¶
func (ki *KustomizeIndex) IterateQuery(query []byte, batchSize int, timeout time.Duration) *KustomizeIterator
Create an iterator over query. Iterate in chunks of batchSize, each batch should take no longer than timeout to read (otherwise, elasticsearch will delete the context).
XXX Important to set a reasonable amount of time to read the documents. If a lot of processing must be done, consider loading everything in memory before doing it so that, a short timeout period can be set. Scrolling creates a consistent DB context, so this can be costly.
Scrolling is also not meant to be used for real time purposes. If you need results quickly, consider using the From: field in SearchOptions and a normal search. This will not guarantee that the values will not change but is more suitable for lower latencies/long execution timeouts.
func (*KustomizeIndex) Put ¶
func (ki *KustomizeIndex) Put(id string, doc *doc.KustomizationDocument) (string, error)
type specific Put for inserting structured kustomization documents.
func (*KustomizeIndex) Search ¶
func (ki *KustomizeIndex) Search(query string, opts KustomizeSearchOptions) (*KustomizeResult, error)
Search the index with the given query string. Returns a structured result and possible aggregates.
func (KustomizeIndex) UpdateMapping ¶
Update the elasticsearch index mappings. (describes how to index/search for the documents).
func (KustomizeIndex) UpdateSetting ¶
Update the elasticsearch index settings. (describes default parameters and some analyzer definitions, etc.)
type KustomizeIterator ¶
type KustomizeIterator struct {
// contains filtered or unexported fields
}
Iterator based off of the way bufio.Scanner works.
Example:
for it.Next() { for _, doc := range it.Value().Hits { // Handle KustomizationDocument. } } if err := it.Err(); err != nil { // Handle err. }
func (*KustomizeIterator) Err ¶
func (it *KustomizeIterator) Err() error
Check if any errors have occured.
func (*KustomizeIterator) Next ¶
func (it *KustomizeIterator) Next() bool
Get the next batch of results. Note that this returns multiple results that can be iterated.
func (*KustomizeIterator) Value ¶
func (it *KustomizeIterator) Value() KustomizeResult
Get the value from this batch of iterations.
type KustomizeResult ¶
type KustomizeResult struct { ScrollID *string `json:"-"` Hits *struct { Total int `json:"total"` Hits []struct { ID string `json:"id"` Document doc.KustomizationDocument `json:"result"` } `json:"hits"` } `json:"hits,omitempty"` Aggregations *struct { Timeseries *struct { Buckets []struct { Key string `json:"key"` Count int `json:"count"` } `json:"buckets"` } `json:"timeseries,omitempty"` Kinds *struct { OtherCount int `json:"otherResults"` Buckets []struct { Key string `json:"key"` Count int `json:"count"` } `json:"buckets"` } `json:"kinds,omitempty"` } `json:"aggregations,omitempty"` }
type KustomizeSearchOptions ¶
type KustomizeSearchOptions struct { SearchOptions KindAggregation bool TimeseriesAggregation bool }
Kustomize search options: What metrics should be returned? Kind Aggregation, TimeseriesAggregation, etc. Also embedds the SearchOptions field to specify the position in the sorted list of results and the number of results to return.
type SearchOptions ¶
Simple search options. Size is the number of elements to return, From is the rank of the results according to the query. Used as a simple (stateless) pagination technique.