index

package
v0.0.0-...-e86fd7f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InsertOrUpdate = iota
	Delete
)
View Source
const (
	AggregationKeyword = "aggs"
)
View Source
const IndexConfig = `` /* 534-byte string literal not displayed */

Variables

This section is empty.

Functions

func BuildQuery

func BuildQuery(query string) map[string]interface{}

Build an elasticsearch query from a user query.

func KindAggregation

func KindAggregation(maxBuckets int) (string, map[string]interface{})

Return aggregation of results based off of their kinds.

func TimeseriesAggregation

func TimeseriesAggregation() (string, map[string]interface{})

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, indexName string) (*KustomizeIndex, error)

Create index reference to the index containing the kustomize documents.

func (KustomizeIndex) CreateIndex

func (idx KustomizeIndex) CreateIndex(config []byte) error

Create an index providing the config for both the mappings and the settings.

func (*KustomizeIndex) Delete

func (ki *KustomizeIndex) Delete(id string) error

Delete a document with a given id from the kustomize index.

func (KustomizeIndex) DeleteIndex

func (idx KustomizeIndex) DeleteIndex() error

Delete an index.

func (KustomizeIndex) Exists

func (idx KustomizeIndex) Exists(id string) (bool, error)

Check whether a given document id is in the index

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

type specific Put for inserting structured kustomization documents.

func (*KustomizeIndex) Search

Search the index with the given query string. Returns a structured result and possible aggregates.

func (KustomizeIndex) UpdateMapping

func (idx KustomizeIndex) UpdateMapping(mappings []byte) error

Update the elasticsearch index mappings. (describes how to index/search for the documents).

func (KustomizeIndex) UpdateSetting

func (idx KustomizeIndex) UpdateSetting(settings []byte) error

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 occurred.

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 Mode

type Mode int

type SearchOptions

type SearchOptions struct {
	Size int
	From int
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL