elastic

package
v0.0.0-...-ab4a820 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterInstance

func RegisterInstance(elastic string, cfg ElasticsearchConfig, handler API)

Types

type API

type API interface {
	ScrollAPI
	MappingAPI
	TemplateAPI

	Init()

	GetMajorVersion() int

	ClusterHealth() *ClusterHealth

	ClusterVersion() string

	CreateIndex(name string, settings map[string]interface{}) error

	Index(indexName string, id interface{}, data interface{}) (*InsertResponse, error)

	Bulk(data *bytes.Buffer)

	Get(indexName, id string) (*GetResponse, error)
	Delete(indexName, id string) (*DeleteResponse, error)
	Count(indexName string) (*CountResponse, error)
	Search(indexName string, query *SearchRequest) (*SearchResponse, error)
	SearchWithRawQueryDSL(indexName string, queryDSL []byte) (*SearchResponse, error)

	GetIndexSettings(indexNames string) (*Indexes, error)
	UpdateIndexSettings(indexName string, settings map[string]interface{}) error

	IndexExists(indexName string) (bool, error)
	DeleteIndex(name string) error

	Refresh(name string) (err error)
}

func GetClient

func GetClient(k string) API

type Aggregation

type Aggregation struct {
}

type AggregationRequest

type AggregationRequest struct {
	Aggregations map[string]Aggregation `json:"aggregations,omitempty"`
}

type AggregationResponse

type AggregationResponse struct {
	Buckets []Bucket `json:"buckets,omitempty"`
}

type BoolQuery

type BoolQuery struct {
	Must    []interface{} `json:"must,omitempty"`
	MustNot []interface{} `json:"must_not,omitempty"`
	Should  []interface{} `json:"should,omitempty"`
}

BoolQuery wrapper queries

type Bucket

type Bucket struct {
	Key      string `json:"key,omitempty"`
	DocCount int    `json:"doc_count,omitempty"`
}

type ClusterHealth

type ClusterHealth struct {
	Name   string `json:"cluster_name"`
	Status string `json:"status"`
}

type ClusterInformation

type ClusterInformation struct {
	Name        string `json:"name"`
	ClusterName string `json:"cluster_name"`
	Version     struct {
		Number        string `json:"number"`
		LuceneVersion string `json:"lucene_version"`
	} `json:"version"`
}

type CountResponse

type CountResponse struct {
	Count int `json:"count"`
}

CountResponse is a count response object

type DeleteResponse

type DeleteResponse struct {
	Result  string `json:"result"`
	Index   string `json:"_index"`
	Type    string `json:"_type"`
	ID      string `json:"_id"`
	Version int    `json:"_version"`
}

DeleteResponse is a delete response object

type ElasticsearchConfig

type ElasticsearchConfig struct {
	ID           string `json:"id,omitempty" index:"id"`
	Name         string `json:"name,omitempty" config:"name"`
	Enabled      bool   `json:"enabled,omitempty" config:"enabled"`
	HttpProxy    string `config:"http_proxy"`
	Endpoint     string `config:"endpoint"`
	Version      string `config:"version"`
	TemplateName string `config:"template_name"`
	IndexPrefix  string `config:"index_prefix"`
	BasicAuth    *struct {
		Username string `config:"username"`
		Password string `config:"password"`
	} `config:"basic_auth"`
}

ElasticsearchConfig contains common settings for elasticsearch

func GetConfig

func GetConfig(k string) ElasticsearchConfig

func (*ElasticsearchConfig) GetHost

func (config *ElasticsearchConfig) GetHost() string

format: host:port

func (*ElasticsearchConfig) IsTLS

func (config *ElasticsearchConfig) IsTLS() bool

type GetResponse

type GetResponse struct {
	Found   bool                   `json:"found"`
	Index   string                 `json:"_index"`
	Type    string                 `json:"_type"`
	ID      string                 `json:"_id"`
	Version int                    `json:"_version"`
	Source  map[string]interface{} `json:"_source"`
}

GetResponse is a get response object

type IndexDocument

type IndexDocument struct {
	Index     string                   `json:"_index,omitempty"`
	Type      string                   `json:"_type,omitempty"`
	ID        interface{}              `json:"_id,omitempty"`
	Routing   string                   `json:"_routing,omitempty"`
	Source    map[string]interface{}   `json:"_source,omitempty"`
	Highlight map[string][]interface{} `json:"highlight,omitempty"`
}

IndexDocument used to construct indexing document

type Indexes

type Indexes map[string]interface{}

type InsertResponse

type InsertResponse struct {
	Result  string `json:"result"`
	Index   string `json:"_index"`
	Type    string `json:"_type"`
	ID      string `json:"_id"`
	Version int    `json:"_version"`
}

InsertResponse is a index response object

type MappingAPI

type MappingAPI interface {
	GetMapping(copyAllIndexes bool, indexNames string) (string, int, *Indexes, error)
	UpdateMapping(indexName string, mappings []byte) ([]byte, error)
}

type MatchQuery

type MatchQuery struct {
	Match map[string]interface{} `json:"match,omitempty"`
}

func (*MatchQuery) Set

func (match *MatchQuery) Set(field string, v interface{})

Init match query's condition

type Query

type Query struct {
	BoolQuery *BoolQuery `json:"bool"`
}

Query is the root query object

type QueryStringQuery

type QueryStringQuery struct {
	Query map[string]interface{} `json:"query_string,omitempty"`
}

func NewQueryString

func NewQueryString(q string) *QueryStringQuery

func (*QueryStringQuery) DefaultOperator

func (query *QueryStringQuery) DefaultOperator(op string)

func (*QueryStringQuery) Fields

func (query *QueryStringQuery) Fields(fields ...string)

func (*QueryStringQuery) QueryString

func (query *QueryStringQuery) QueryString(q string)

type RangeQuery

type RangeQuery struct {
	Range map[string]map[string]interface{} `json:"range,omitempty"`
}

RangeQuery is used to find value in range

func (*RangeQuery) Gt

func (query *RangeQuery) Gt(field string, value interface{})

func (*RangeQuery) Gte

func (query *RangeQuery) Gte(field string, value interface{})

func (*RangeQuery) Lt

func (query *RangeQuery) Lt(field string, value interface{})

func (*RangeQuery) Lte

func (query *RangeQuery) Lte(field string, value interface{})

type ScrollAPI

type ScrollAPI interface {
	NewScroll(indexNames string, scrollTime string, docBufferCount int, query string, slicedId, maxSlicedCount int, fields string) (interface{}, error)
	NextScroll(scrollTime string, scrollId string) (interface{}, error)
}

type ScrollResponse

type ScrollResponse struct {
	Took     int    `json:"took,omitempty"`
	ScrollId string `json:"_scroll_id,omitempty"`
	TimedOut bool   `json:"timed_out,omitempty"`
	Hits     struct {
		MaxScore float32       `json:"max_score,omitempty"`
		Total    int           `json:"total,omitempty"`
		Docs     []interface{} `json:"hits,omitempty"`
	} `json:"hits"`
	Shards ShardResponse `json:"_shards,omitempty"`
}

func (*ScrollResponse) GetDocs

func (scroll *ScrollResponse) GetDocs() []interface{}

func (*ScrollResponse) GetHitsTotal

func (scroll *ScrollResponse) GetHitsTotal() int

func (*ScrollResponse) GetScrollId

func (scroll *ScrollResponse) GetScrollId() string

func (*ScrollResponse) GetShardResponse

func (scroll *ScrollResponse) GetShardResponse() ShardResponse

func (*ScrollResponse) SetScrollId

func (scroll *ScrollResponse) SetScrollId(id string)

type ScrollResponseAPI

type ScrollResponseAPI interface {
	GetScrollId() string
	SetScrollId(id string)
	GetHitsTotal() int
	GetShardResponse() ShardResponse
	GetDocs() []interface{}
}

type ScrollResponseV7

type ScrollResponseV7 struct {
	ScrollResponse
	Hits struct {
		MaxScore float32 `json:"max_score,omitempty"`
		Total    struct {
			Value    int    `json:"value,omitempty"`
			Relation string `json:"relation,omitempty"`
		} `json:"total,omitempty"`
		Docs []interface{} `json:"hits,omitempty"`
	} `json:"hits"`
}

func (*ScrollResponseV7) GetDocs

func (scroll *ScrollResponseV7) GetDocs() []interface{}

func (*ScrollResponseV7) GetHitsTotal

func (scroll *ScrollResponseV7) GetHitsTotal() int

func (*ScrollResponseV7) GetScrollId

func (scroll *ScrollResponseV7) GetScrollId() string

func (*ScrollResponseV7) GetShardResponse

func (scroll *ScrollResponseV7) GetShardResponse() ShardResponse

func (*ScrollResponseV7) SetScrollId

func (scroll *ScrollResponseV7) SetScrollId(id string)

type SearchRequest

type SearchRequest struct {
	Query              *Query         `json:"query,omitempty"`
	From               int            `json:"from"`
	Size               int            `json:"size"`
	Sort               *[]interface{} `json:"sort,omitempty"`
	AggregationRequest `json:"aggs,omitempty"`
}

SearchRequest is the root search query object

func (*SearchRequest) AddSort

func (request *SearchRequest) AddSort(field string, order string)

AddSort add sort conditions to SearchRequest

type SearchResponse

type SearchResponse struct {
	Took     int  `json:"took"`
	TimedOut bool `json:"timed_out"`
	Hits     struct {
		Total    interface{}     `json:"total"`
		MaxScore float32         `json:"max_score"`
		Hits     []IndexDocument `json:"hits,omitempty"`
	} `json:"hits"`
	Aggregations map[string]AggregationResponse `json:"aggregations,omitempty"`
}

SearchResponse is a count response object

func (*SearchResponse) GetTotal

func (response *SearchResponse) GetTotal() int

type ShardResponse

type ShardResponse struct {
	Total      int `json:"total,omitempty"`
	Successful int `json:"successful,omitempty"`
	Skipped    int `json:"skipped,omitempty"`
	Failed     int `json:"failed,omitempty"`
	Failures   []struct {
		Shard  int         `json:"shard,omitempty"`
		Index  string      `json:"index,omitempty"`
		Status int         `json:"status,omitempty"`
		Reason interface{} `json:"reason,omitempty"`
	} `json:"failures,omitempty"`
}

type TemplateAPI

type TemplateAPI interface {
	TemplateExists(templateName string) (bool, error)
	PutTemplate(templateName string, template []byte) ([]byte, error)
}

type TermsAggregationQuery

type TermsAggregationQuery struct {
	// contains filtered or unexported fields
}

func NewTermsAggregation

func NewTermsAggregation() (query *TermsAggregationQuery)

func (*TermsAggregationQuery) Field

func (query *TermsAggregationQuery) Field(field string) *TermsAggregationQuery

func (*TermsAggregationQuery) Size

func (query *TermsAggregationQuery) Size(size int) *TermsAggregationQuery

Jump to

Keyboard shortcuts

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