escrud

package module
v1.1.19 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2021 License: MIT Imports: 10 Imported by: 0

README

escrud

Simple CRUD and search for Elastic Search

Сделана на основе https://github.com/elastic/go-elasticsearch
Конкретные примеры применения смотри в https://github.com/RGRU/escrud/blob/master/escrud_test.go

Start

Call Connect(host, port) to establish connection.

Documentation

Overview

Package escrud provides simple CRUD operations and search function to work with Elastic Search

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v1.1.1

type Client struct {
	Client *elasticsearch.Client
	Info   *esapi.Response
}

Client elasticsearch

func Connect added in v1.1.1

func Connect(host string, port int, scheme string) (*Client, error)

Connect to a elastic

func (*Client) BulkCreate added in v1.1.19

func (Es *Client) BulkCreate(datum []byte) error

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

func (Es *Client) Create(index string, id string, data []byte) error

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

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

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) Source added in v1.1.1

func (Es *Client) Source(index, id string) ([]byte, error)

Source get source

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

type Transport added in v1.1.10

type Transport struct{}

Transport implements the estransport interface with the github.com/valyala/fasthttp HTTP client.

func (*Transport) RoundTrip added in v1.1.10

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip performs the request and returns a response or error

Jump to

Keyboard shortcuts

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