elastic

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: MIT Imports: 7 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

	Data map[string]interface{}
}

type BulkResponse

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

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

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"`
}

type Client

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

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(addr string) *Client

func (*Client) Bulk

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

only support parent in 'Bulk' related apis

func (*Client) CreateMapping

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

func (*Client) Delete

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

func (*Client) DeleteIndex

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

func (*Client) Do

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

func (*Client) DoBulk

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

func (*Client) Exists

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

func (*Client) Get

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

func (*Client) IndexBulk

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

func (*Client) IndexTypeBulk

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

func (*Client) Update

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

Can use Update to create or update the data

type Response

type Response struct {
	Code int
	ResponseItem
}

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"`
}

Jump to

Keyboard shortcuts

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