Documentation ¶
Index ¶
- func NewEsClient(address []string, user, pwd, cfp string) error
- type Aggregations
- type Buckets
- type ESClient
- func (e *ESClient) CreateIndexDoc(index string, doc any, docid ...string) error
- func (e *ESClient) CreateIndexMapping(index, mapping string) error
- func (e *ESClient) DeleteIndexDoc(index, docid string) error
- func (e *ESClient) IsExistIndex(index []string) (bool, error)
- func (e *ESClient) SearchIndex(index, query string, page int, limit ...int) (*Response, error)
- func (e *ESClient) SetupIndexs(indexs map[string]string) error
- func (e *ESClient) UpdateIndexDoc(index, docid, doc string) error
- func (e *ESClient) UpdateIndexMapping(index []string, mapping string) error
- type ErrorResp
- type Reason
- type Response
- type RootCause
- type SearchHit
- type SearchHits
- type Shards
- type TopN
- type Total
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEsClient ¶
Create a new elasticsearch client.
Types ¶
type Aggregations ¶
type Aggregations struct {
TopN *TopN `json:"topN"`
}
type ESClient ¶
Elasticsearch client
func GetEs ¶
func GetEs() *ESClient
Return elastic singleton instance, it may not connect before setuped.
func (*ESClient) CreateIndexDoc ¶
Create new doc, it will auto create index mapping when index unexist.
func (*ESClient) CreateIndexMapping ¶
Create the new index and setting index mapping, it will return error when index is exist.
The mapping param like :
mapping = ` { "mappings": { "properties": { "title": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, } } }`
func (*ESClient) DeleteIndexDoc ¶
Delete the exist doc indicated by given index and doc id.
func (*ESClient) IsExistIndex ¶
Check indexs whether exist
func (*ESClient) SearchIndex ¶
Search doc by query index, and set page, limit. by default page=0 and limit=10
func (*ESClient) SetupIndexs ¶
Setup search indexs with mapping if the index unexist.
func (*ESClient) UpdateIndexDoc ¶
Update the specified fields in the index.
The doc string like :
doc := ` { "doc": { "fields":"value" } } `
func (*ESClient) UpdateIndexMapping ¶
Update the index mapping, for exmple: add new field or update one.
The mapping param like :
mapping := ` { "properties": { "title": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" } } }`
type Response ¶
type Response struct { Took int `json:"took"` TimeOut bool `json:"timed_out"` Shards *Shards `json:"_shards"` Hits *SearchHits `json:"hits"` Aggregations *Aggregations `json:"aggregations"` }
type SearchHit ¶
type SearchHit struct { Index string `json:"_index"` ID string `json:"_id"` Score *float64 `json:"_score,omitempty"` // computed score Source json.RawMessage `json:"_source,omitempty"` // stored document source }