Documentation ¶
Overview ¶
Package escrud provides simple CRUD operations and search function to work with Elastic Search
Index ¶
- type Client
- func (Es *Client) BulkCreate(datum []byte) error
- func (Es *Client) Create(index string, id string, data []byte) error
- func (Es *Client) Delete(index, id string) (*ResponseBody, error)
- func (Es *Client) Exists(index string, id string) (bool, error)
- func (Es *Client) IncrementField(index string, docID string, fieldName string, incr int) (*ResponseBody, error)
- func (Es *Client) InsertArrayItem(index string, docID string, arrayName string, elem []byte) (*ResponseBody, error)
- func (Es *Client) Read(index, id string) (*ResponseBody, error)
- func (Es *Client) RemoveArrayItem(index string, docID string, arrayName string, itemName string, itemValue int) (*ResponseBody, error)
- func (Es *Client) Source(index, id string) ([]byte, error)
- func (Es *Client) Update(index, id string, data []byte) (*ResponseBody, error)
- func (Es *Client) UpdateArrayItem(index string, docID string, arrayName string, itemName string, itemValue int, ...) (*ResponseBody, error)
- type ResponseBody
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v1.1.1
Client elasticsearch
func (*Client) BulkCreate ¶ added in v1.1.19
BulkCreate let's bulky index multiple entries by single request to Elastic. look full documentation here: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html#docs-bulk-api-example
func (*Client) Create ¶ added in v1.1.1
Create record in elasticsearch should contain a valid JSON with key {..."id":your_unique_id}
func (*Client) Delete ¶ added in v1.1.1
func (Es *Client) Delete(index, id string) (*ResponseBody, error)
Delete record by id in elasticsearch
func (*Client) Exists ¶ added in v1.1.1
Exists checks if there's a document with such id in such an index
func (*Client) IncrementField ¶ added in v1.1.9
func (Es *Client) IncrementField(index string, docID string, fieldName string, incr int) (*ResponseBody, error)
IncrementField пересчитать просмотры в материале аналог запроса POST http://localhost:9200/article/_update/{{id}}/ { "script" : "ctx._source.viewed+={{amount}}" }
func (*Client) InsertArrayItem ¶ added in v1.1.14
func (Es *Client) InsertArrayItem(index string, docID string, arrayName string, elem []byte) (*ResponseBody, error)
InsertArrayItem добавить элемент массива. Массива может не быть - тогда добавить и массив POST http://localhost:9200/mask/_update/_3/ "script": "if (!ctx._source.containsKey(\"attending\")) { ctx._source.attending = newField }",
func (*Client) Read ¶ added in v1.1.1
func (Es *Client) Read(index, id string) (*ResponseBody, error)
func (*Client) RemoveArrayItem ¶ added in v1.1.3
func (Es *Client) RemoveArrayItem(index string, docID string, arrayName string, itemName string, itemValue int) (*ResponseBody, error)
RemoveArrayItem удалить элемент массива по его параметру (пока только числовой ID) POST http://localhost:9200/mask/_update/_3/ { "script": { "source": "ctx._source.mask_articles.removeIf(li -> li.article_id == params.article_id)", "params": { "article_id": 1886746 } } }
func (*Client) Update ¶ added in v1.1.1
func (Es *Client) Update(index, id string, data []byte) (*ResponseBody, error)
Update record by id in elasticsearch
func (*Client) UpdateArrayItem ¶ added in v1.1.4
func (Es *Client) UpdateArrayItem(index string, docID string, arrayName string, itemName string, itemValue int, subst []byte) (*ResponseBody, error)
UpdateArrayItem заменить элемент массива по его параметру (пока только числовой ID) POST http://localhost:9200/mask/_update/_3/ { "script": { "inline": "ctx._source.mask_articles.removeIf(li -> li.article_id == params.article_id);", "lang": "painless", "params": { "article_id": 1886746, "cat": { "article_id": 1886746, "position": 5 } } } }
type ResponseBody ¶ added in v1.1.1
type ResponseBody struct { Index string `json:"_index,omitempty"` ID string `json:"_id,omitempty"` Version int `json:"_version,omitempty"` Source interface{} `json:"_source,omitempty"` Result string `json:"result,omitempty"` Error interface{} `json:"error,omitempty"` Reason string `json:"reason,omitempty"` }
ResponseBody struct from elastic, common for both success and fail answers