elastic

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionCreate = "create"
	ActionUpdate = "update"
	ActionDelete = "delete"
	ActionIndex  = "index"
)

See http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/bulk.html

Variables

This section is empty.

Functions

This section is empty.

Types

type BulkRequest

type BulkRequest struct {
	Action   string
	Index    string
	Type     string
	ID       string
	Parent   string
	Pipeline string

	Data map[string]interface{}
}

BulkRequest is used to send multi request in batch.

type BulkResponse

type BulkResponse struct {
	Code   int
	Took   int  `json:"took"`
	Errors bool `json:"errors"`

	Items []map[string]*BulkResponseItem `json:"items"`
}

BulkResponse is the response for the bulk request.

type BulkResponseItem

type BulkResponseItem struct {
	Index   string          `json:"_index"`
	Type    string          `json:"_type"`
	ID      string          `json:"_id"`
	Version int             `json:"_version"`
	Status  int             `json:"status"`
	Error   json.RawMessage `json:"error"`
	Found   bool            `json:"found"`
}

BulkResponseItem is the item in the bulk response.

type Client

type Client struct {
	Protocol string
	Addr     string
	User     string
	Password string
	// contains filtered or unexported fields
}

Client is the client to communicate with ES. Although there are many Elasticsearch clients with Go, I still want to implement one by myself. Because we only need some very simple usages.

func NewClient

func NewClient(conf *ClientConfig) *Client

NewClient creates the Cient with configuration.

func (*Client) Bulk

func (c *Client) Bulk(items []*BulkRequest) (*BulkResponse, error)

Bulk sends the bulk request. only support parent in 'Bulk' related apis

func (*Client) CreateMapping

func (c *Client) CreateMapping(index string, docType string, mapping map[string]interface{}) error

CreateMapping creates a ES mapping.

func (*Client) Delete

func (c *Client) Delete(index string, docType string, id string) error

Delete deletes the item by id.

func (*Client) DeleteIndex

func (c *Client) DeleteIndex(index string) error

DeleteIndex deletes the index.

func (*Client) Do

func (c *Client) Do(method string, url string, body map[string]interface{}) (*Response, error)

Do sends the request with body to ES.

func (*Client) DoBulk

func (c *Client) DoBulk(url string, items []*BulkRequest) (*BulkResponse, error)

DoBulk sends the bulk request to the ES.

func (*Client) DoRequest

func (c *Client) DoRequest(method string, url string, body *bytes.Buffer) (*http.Response, error)

DoRequest sends a request with body to ES.

func (*Client) Exists

func (c *Client) Exists(index string, docType string, id string) (bool, error)

Exists checks whether id exists or not.

func (*Client) Get

func (c *Client) Get(index string, docType string, id string) (*Response, error)

Get gets the item by id.

func (*Client) GetMapping

func (c *Client) GetMapping(index string, docType string) (*MappingResponse, error)

GetMapping gets the mapping.

func (*Client) IndexBulk

func (c *Client) IndexBulk(index string, items []*BulkRequest) (*BulkResponse, error)

IndexBulk sends the bulk request for index.

func (*Client) IndexTypeBulk

func (c *Client) IndexTypeBulk(index string, docType string, items []*BulkRequest) (*BulkResponse, error)

IndexTypeBulk sends the bulk request for index and doc type.

func (*Client) Update

func (c *Client) Update(index string, docType string, id string, data map[string]interface{}) error

Update creates or updates the data

type ClientConfig

type ClientConfig struct {
	HTTPS    bool
	Addr     string
	User     string
	Password string
}

ClientConfig is the configuration for the client.

type Mapping

type Mapping map[string]struct {
	Mappings map[string]struct {
		Properties map[string]struct {
			Type   string      `json:"type"`
			Fields interface{} `json:"fields"`
		} `json:"properties"`
	} `json:"mappings"`
}

Mapping represents ES mapping.

type MappingResponse

type MappingResponse struct {
	Code    int
	Mapping Mapping
}

MappingResponse is the response for the mapping request.

type Response

type Response struct {
	Code int
	ResponseItem
}

Response is the ES response

type ResponseItem

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

ResponseItem is the ES item in the response.

Jump to

Keyboard shortcuts

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