Documentation
¶
Index ¶
- Variables
- func MakeQueryString(andQuery, orQuery string) string
- func MergeOptions(mapping, settings string) (string, error)
- func ParseQueryString(query string) []string
- type Client
- func (c *Client) BatchInsertDocument(ctx context.Context, indexName string, dataSet []interface{}) error
- func (c *Client) CheckConnectStatus() bool
- func (c *Client) Close()
- func (c *Client) CreateIndex(ctx context.Context, indexName string, mapping, settings string) error
- func (c *Client) DeleteDocument(ctx context.Context, indexName, id string) error
- func (c *Client) DeleteIndex(ctx context.Context, indexName string) error
- func (c *Client) GetDocument(ctx context.Context, indexName string, id string, sourceFields []string, ...) error
- func (c *Client) IndexExists(ctx context.Context, indexName string) (bool, error)
- func (c *Client) InsertDocument(ctx context.Context, indexName, id string, data interface{}) error
- func (c *Client) Search(ctx context.Context, indexName string, req *pagination.PagingRequest) (*SearchResult, error)
- func (c *Client) UpdateDocument(ctx context.Context, indexName string, pk string, doc interface{}) error
- type ErrorResponse
- type SearchResult
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrRequestFailed is returned when a request to Elasticsearch fails. ErrRequestFailed = errors.InternalServer("REQUEST_FAILED", "request failed") // ErrIndexNotFound is returned when the specified index does not exist. ErrIndexNotFound = errors.InternalServer("INDEX_NOT_FOUND", "index not found") // ErrIndexAlreadyExists is returned when trying to create an index that already exists. ErrIndexAlreadyExists = errors.InternalServer("INDEX_ALREADY_EXISTS", "index already exists") ErrCreateIndex = errors.InternalServer("CREATE_INDEX_FAILED", "failed to create index") ErrDeleteIndex = errors.InternalServer("DELETE_INDEX_FAILED", "failed to delete index") // ErrDocumentNotFound is returned when a document is not found in the index. ErrDocumentNotFound = errors.InternalServer("DOCUMENT_NOT_FOUND", "document not found") // ErrDocumentAlreadyExists is returned when trying to create a document that already exists. ErrDocumentAlreadyExists = errors.InternalServer("DOCUMENT_ALREADY_EXISTS", "document already exists") // ErrInvalidQuery is returned when the query provided to Elasticsearch is invalid. ErrInvalidQuery = errors.InternalServer("INVALID_QUERY", "invalid query") // ErrUnmarshalResponse is returned when the response from Elasticsearch cannot be unmarshalled. ErrUnmarshalResponse = errors.InternalServer("UNMARSHAL_RESPONSE_FAILED", "failed to unmarshal response") ErrInsertDocument = errors.InternalServer("INSERT_DOCUMENT_FAILED", "failed to insert document") ErrBatchInsertDocument = errors.InternalServer("BATCH_INSERT_DOCUMENT_FAILED", "failed to batch insert documents") ErrGetDocument = errors.InternalServer("GET_DOCUMENT_FAILED", "failed to get document") ErrSearchDocument = errors.InternalServer("SEARCH_DOCUMENT_FAILED", "failed to search document") )
Functions ¶
func MakeQueryString ¶
func MergeOptions ¶
MergeOptions 合并 Elasticsearch 索引的映射和设置
func ParseQueryString ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) BatchInsertDocument ¶
func (c *Client) BatchInsertDocument(ctx context.Context, indexName string, dataSet []interface{}) error
BatchInsertDocument 批量插入数据
func (*Client) CheckConnectStatus ¶
CheckConnectStatus 检查Elasticsearch连接
func (*Client) DeleteDocument ¶
DeleteDocument 删除一条数据
func (*Client) DeleteIndex ¶
DeleteIndex 删除一条索引
func (*Client) GetDocument ¶
func (c *Client) GetDocument( ctx context.Context, indexName string, id string, sourceFields []string, out interface{}, ) error
GetDocument 查询数据
func (*Client) IndexExists ¶
IndexExists 检查索引是否存在
func (*Client) InsertDocument ¶
InsertDocument 插入一条数据
func (*Client) Search ¶
func (c *Client) Search( ctx context.Context, indexName string, req *pagination.PagingRequest, ) (*SearchResult, error)
type ErrorResponse ¶
type ErrorResponse struct {
Error struct {
RootCause []struct {
Type string `json:"type"`
Reason string `json:"reason"`
} `json:"root_cause"`
Type string `json:"type"`
Reason string `json:"reason"`
CausedBy struct {
Type string `json:"type"`
Reason string `json:"reason"`
} `json:"caused_by,omitempty"`
} `json:"error"`
Status int `json:"status"`
}
ErrorResponse 表示 Elasticsearch 错误响应的结构
func ParseErrorMessage ¶
func ParseErrorMessage(body io.ReadCloser) (*ErrorResponse, error)
ParseErrorMessage 解析 Elasticsearch 错误消息
type SearchResult ¶
type SearchResult struct {
Took int `json:"took"`
TimedOut bool `json:"timed_out"`
Hits struct {
Total struct {
Value int `json:"value"`
Relation string `json:"relation"`
} `json:"total"`
Hits []struct {
Index string `json:"_index"`
Type string `json:"_type"`
ID string `json:"_id"`
Score float64 `json:"_score"`
Source json.RawMessage `json:"_source"`
} `json:"hits"`
} `json:"hits"`
}
Click to show internal directories.
Click to hide internal directories.