goelastic

package module
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 13 Imported by: 2

README

GoElastic: A Go Client Wrapper for Elasticsearch

Build Status Go Report Card Docs License

Simple client to query Elasticsearch API using HTTP API documentation.

Usage

See the sample code in the docs folder.

So far the following example code has been created:

  1. Create Index: Go code, ES docs
  2. Index Docs: Go code, ES docs
  3. Bool Query: Go code, ES docs
  4. Terms Aggregation: Go code, ES docs

References

  1. Mapping
    1. An Introduction to Elasticsearch Mapping

Documentation

Index

Constants

View Source
const (
	// DefaultScheme is the HTTP scheme for the default server.
	DefaultScheme string = "https"
	// DefaultHost is the HTTP host for the default server.
	DefaultHost string = "127.0.0.1:9200"
	// DefaultServerURL is the HTTP host for the default server.
	DefaultServerURL string = "https://127.0.0.1:9200"

	MappingFieldKeyword = "keyword" // see: https://www.elastic.co/blog/strings-are-dead-long-live-strings
	MappingFieldRaw     = "raw"

	// SlugCreate is the URL path part for creates.
	SlugCreate  = "_create"
	SlugDoc     = "_doc"
	SlugMapping = "_mapping"
	// SlugSearch is the URL path part for search.
	SlugSearch = "_search"
	// SlugUpdate is the URL path part for updates.
	SlugUpdate = "_update"

	TypeInteger       = "integer" // More at: https://www.elastic.co/guide/en/elasticsearch/reference/current/number.html
	TypeKeyword       = "keyword"
	TypeString        = "string" // Deprecation in ES5: https://www.elastic.co/blog/strings-are-dead-long-live-strings
	TypeText          = "text"
	TypeMatchOnlyText = "match_only_text"
)

Variables

View Source
var (
	ErrClientNotSet     = errors.New("httpsimple.Client not set")
	ErrDocumentIDNotSet = errors.New("document id s be empty")
	ErrRequestNotSet    = errors.New("request cannot be empty")
	ErrTargetNetSet     = errors.New("target cannot be empty")
)

Functions

func NewConfigSimple

func NewConfigSimple(addrURL, username, password string, tlsInsecureSkipVerify bool) elasticsearch.Config

func NewSimpleClient

func NewSimpleClient(serverURL, username, password string, allowInsecure bool) (httpsimple.Client, error)

Types

type Client

type Client struct {
	SimpleClient *httpsimple.Client
}

func (*Client) DocumentCreate

func (c *Client) DocumentCreate(target, id string, body any) (*http.Response, error)

DocumentCreate crates a document with the document id `id`. If `id` is empty, a document id is created.`

func (*Client) DocumentRead

func (c *Client) DocumentRead(target, id string, v any) (*DocumentReadAPIResponse, *http.Response, error)

DocumentRead reads a document. If `v` is a pointer, the resulting `_source` property will be unmarshaled into it. The API is documented at: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html and https://www.elastic.co/guide/en/elasticsearch/client/go-api/current/examples.html#retrieving_document .

func (*Client) DocumentReadSimple added in v0.6.0

func (c *Client) DocumentReadSimple(target, id string) (*http.Response, error)

DocumentRead reads a document. Documented at: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html .

func (*Client) IndexCreate

func (c *Client) IndexCreate(target string, body any) (*http.Response, error)

IndexCreate creates an index. Documented at: https://www.elastic.co/guide/en/elasticsearch/reference/current/explicit-mapping.html .

func (*Client) IndexPatch

func (c *Client) IndexPatch(target string, body any) (*http.Response, error)

IndexPatch patches an index. Documented at: https://www.elastic.co/guide/en/elasticsearch/reference/current/explicit-mapping.html#add-field-mapping .

type DocumentReadAPIResponse added in v0.6.0

type DocumentReadAPIResponse struct {
	Index  string          `json:"_index"`
	ID     string          `json:"_id"`
	Found  bool            `json:"found"`
	Source json.RawMessage `json:"_source"`
}

DocumentReadAPIResponse represents an Elasticsearch document response.

Jump to

Keyboard shortcuts

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