es

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2019 License: Apache-2.0 Imports: 10 Imported by: 3

README

es

es is minimal, opinionated Elasticsearch utility lib for TXN2 services.

Demo

Setup

Bring up a single node Elasticsearch server and Kibana instance.

docker-compose up

Run Example

go run ./example/es.go

Documentation

Overview

Package es implements a simple Elasticsearch client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Config
}

Client

func CreateClient

func CreateClient(cfg Config) *Client

CreateClient returns an Elasticsearch client object

func (*Client) Get

func (es *Client) Get(url string) (int, []byte, error)

Get uses HTTP Get method to retrieve data from elasticsearch returns a byte array that may be used to unmarshal into a specific type depending on the returned code.

func (*Client) Post

func (es *Client) Post(url string, data []byte) (int, Result, *ErrorResponse, error)

Post uses HTTP POST method to send data to elasticsearch

func (*Client) PostObj

func (es *Client) PostObj(url string, dataObj interface{}) (int, Result, *ErrorResponse, error)

PostObj Marshals and object into json and POSTs it to Elasticsearch

func (*Client) PostObjUnmarshal

func (es *Client) PostObjUnmarshal(url string, dataObj interface{}, retObj interface{}) (int, *ErrorResponse, error)

PostObjUnmarshal Unmarshals results to retObj, likely a overridden es.SearchResults struct

func (*Client) Put

func (es *Client) Put(url string, data []byte) (int, Result, *ErrorResponse, error)

Put uses HTTP Put method to send data to elasticsearch

func (*Client) PutObj

func (es *Client) PutObj(url string, dataObj interface{}) (int, Result, *ErrorResponse, error)

PutObj Marshals and object into json and PUTs it to Elasticsearch

func (*Client) SendEsMapping

func (es *Client) SendEsMapping(mapping IndexTemplate) (int, Result, *ErrorResponse, error)

SendEsMapping

type Config

type Config struct {
	Log           *zap.Logger
	HttpClient    *http.Client
	ElasticServer string
}

Config

type ErrorCause

type ErrorCause struct {
	RootCause    []ErrorCause `json:"root_cause"`
	Type         string       `json:"type"`
	Reason       string       `json:"reason"`
	ResourceType string       `json:"resource.type"`
	ResourceId   string       `json:"resource.id"`
	IndexUuid    string       `json:"index_uuid"`
	Index        string       `json:"index"`
}

ErrorCause

type ErrorResponse

type ErrorResponse struct {
	Message string
}

ErrorResponse

type HitsMeta

type HitsMeta struct {
	Total    int      `json:"total"`
	MaxScore float64  `json:"max_score"`
	Hits     []Result `json:"hits"`
}

HitsMeta

type IndexTemplate

type IndexTemplate struct {
	Name     string
	Template Obj
}

IndexTemplate

type Obj

type Obj map[string]interface{}

Obj represents any structure

type Result

type Result struct {
	Index      string `json:"_index"`
	Type       string `json:"_type"`
	Id         string `json:"_id"`
	Version    int    `json:"_version"`
	ResultType string `json:"result"`
	Found      bool   `json:"found"`
	Shards     struct {
		Total      int `json:"total"`
		Successful int `json:"successful"`
		Failed     int `json:"failed"`
	} `json:"_shards"`
	SeqNo       int                    `json:"_seq_no"`
	PrimaryTerm int                    `json:"_primary_term"`
	Source      map[string]interface{} `json:"_source"`
	Error       string                 `json:"error"`
	Status      int                    `json:"status"`
}

Result

type SearchResults

type SearchResults struct {
	Took     int  `json:"took"`
	TimedOut bool `json:"timed_out"`
	Shards   struct {
		Total      int `json:"total"`
		Successful int `json:"successful"`
		Skipped    int `json:"skipped"`
		Failed     int `json:"failed"`
	} `json:"_shards"`
	Hits   HitsMeta `json:"hits"`
	Error  string   `json:"error"`
	Status int      `json:"status"`
}

SearchResults

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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