elasticsearch

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 13 Imported by: 0

README

主要是提供一些搜索服务客户端,比如常见的 Elasticsearch、solr

Elasticsearch

Elasticsearch 是当前比较流行的 搜索框架,这里提供两个库,第三方和官方的,特点各有千秋。

第三方的这个已经不在维护,所以推荐使用官方的

Compatibility

The client major versions correspond to the compatible Elasticsearch major versions: to connect to Elasticsearch 7.x, use a 7.x version of the client, to connect to Elasticsearch 6.x, use a 6.x version of the client.

Reference

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEsNotFound = errors.New("es: not found")
)

Functions

This section is empty.

Types

type EsClient

type EsClient struct {
	// contains filtered or unexported fields
}

func NewESClient

func NewESClient(hosts []string, username, password string) (client *EsClient, err error)

func (*EsClient) CreateDocument

func (es *EsClient) CreateDocument(ctx context.Context, indexName string, docId string,
	data map[string]interface{}) (map[string]interface{}, error)

CreateDocument create a document

func (*EsClient) CreateIndex

func (es *EsClient) CreateIndex(ctx context.Context, indexName string, body string) (map[string]interface{}, error)

CreateIndex creates an index with the given name and body.

func (*EsClient) DeleteDocument

func (es *EsClient) DeleteDocument(ctx context.Context, indexName string, docId string) error

func (*EsClient) DeleteDocumentByQuery

func (es *EsClient) DeleteDocumentByQuery(ctx context.Context, indexName string, query, data map[string]interface{}) (map[string]interface{}, error)

func (*EsClient) DeleteIndex

func (es *EsClient) DeleteIndex(ctx context.Context, indexName string) error

DeleteIndex deletes an index with the given name.

func (*EsClient) GetDocument

func (es *EsClient) GetDocument(ctx context.Context, indexName, docId string) (map[string]interface{}, error)

GetDocument get a document

func (*EsClient) GetIndex

func (es *EsClient) GetIndex(ctx context.Context, indexName string) (map[string]interface{}, error)

GetIndex gets an index with the given name.

func (*EsClient) IsExistDocument

func (es *EsClient) IsExistDocument(ctx context.Context, indexName, docId string) (bool, error)

IsExistDocument check a document is exist

func (*EsClient) Search

func (es *EsClient) Search(ctx context.Context, indexName string, query, sort map[string]interface{}, offset,
	limit int) (ret []map[string]interface{}, total int, err error)

Search documents by query and sort

func (*EsClient) SearchByAggregations

func (es *EsClient) SearchByAggregations(ctx context.Context, indexName string,
	jsonBody string) (ret map[string]interface{}, err error)

SearchByAggregations documents by body with json format

func (*EsClient) UpdateDocument

func (es *EsClient) UpdateDocument(ctx context.Context, indexName, docId string, data map[string]interface{}) (map[string]interface{}, error)

UpdateDocument update a document

func (*EsClient) UpdateDocumentByQuery

func (es *EsClient) UpdateDocumentByQuery(ctx context.Context, indexName string, query, data map[string]interface{}) (map[string]interface{}, error)

UpdateDocumentByQuery 根据搜索条件更新

Jump to

Keyboard shortcuts

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