es

package module
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: May 13, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

es

es is minimal, opinionated Elasticsearch client for TXN2 services.

Documentation

Overview

Package es implements a simple Elasticsearch client.

Copyright 2019 TXN2

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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, error)

Post uses HTTP POST method to send data to elasticsearch

func (*Client) PostObj

func (es *Client) PostObj(url string, dataObj interface{}) (int, Result, 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, 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, error)

Put uses HTTP Put method to send data to elasticsearch

func (*Client) PutObj

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

PutObj Marshals and object into json and PUTs it to Elasticsearch

func (*Client) SendEsMapping added in v1.3.4

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

SendEsMapping

type Config

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

Config

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

Jump to

Keyboard shortcuts

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