elastic

package
v0.0.0-...-7ab3369 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEsClient

func NewEsClient(address []string, user, pwd, cfp string) error

Create a new elasticsearch client.

Types

type Aggregations

type Aggregations struct {
	TopN *TopN `json:"topN"`
}

type Buckets

type Buckets struct {
	Key      string `json:"key"`
	DocCount string `json:"doc_count"`
}

type ESClient

type ESClient struct {
	Conn *es.Client
}

Elasticsearch client

func GetEs

func GetEs() *ESClient

Return elastic singleton instance, it may not connect before setuped.

func (*ESClient) CreateIndexDoc

func (e *ESClient) CreateIndexDoc(index string, doc any, docid ...string) error

Create new doc, it will auto create index mapping when index unexist.

func (*ESClient) CreateIndexMapping

func (e *ESClient) CreateIndexMapping(index, mapping string) error

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

func (e *ESClient) DeleteIndexDoc(index, docid string) error

Delete the exist doc indicated by given index and doc id.

func (*ESClient) IsExistIndex

func (e *ESClient) IsExistIndex(index []string) (bool, error)

Check indexs whether exist

func (*ESClient) SearchIndex

func (e *ESClient) SearchIndex(index, query string, page int, limit ...int) (*Response, error)

Search doc by query index, and set page, limit. by default page=0 and limit=10

func (*ESClient) SetupIndexs

func (e *ESClient) SetupIndexs(indexs map[string]string) error

Setup search indexs with mapping if the index unexist.

func (*ESClient) UpdateIndexDoc

func (e *ESClient) UpdateIndexDoc(index, docid, doc string) error

Update the specified fields in the index.

The doc string like :

doc := `
{
	"doc": {
		"fields":"value"
	}
}
`

func (*ESClient) UpdateIndexMapping

func (e *ESClient) UpdateIndexMapping(index []string, mapping string) error

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 ErrorResp

type ErrorResp struct {
	Status      int     `json:"status"`
	ErrorReason *Reason `json:"error"`
}

type Reason

type Reason struct {
	RootCause    []*RootCause `json:"root_cause"`
	Type         string       `json:"type"`
	Reason       string       `json:"reason"`
	ResourceType string       `json:"resource.type"`
	ResourceID   string       `json:"resource.id"`
	IndexUUID    string       `json:"index_uuid"`
	Index        string       `json:"index"`
}

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 RootCause

type RootCause struct {
	Type         string `json:"type"`
	Reason       string `json:"reason"`
	ResourceType string `json:"resource.type"`
	ResourceID   string `json:"resource.id"`
	IndexUUID    string `json:"index_uuid"`
	Index        string `json:"index"`
}

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

}

type SearchHits

type SearchHits struct {
	Total    *Total       `json:"total"`
	MaxScore *float64     `json:"max_score"`
	Hits     []*SearchHit `json:"hits"`
}

type Shards

type Shards struct {
	Total      int `json:"total"`
	Successful int `json:"successful"`
	Skipped    int `json:"skipped"`
	Failed     int `json:"failed"`
}

type TopN

type TopN struct {
	DocCEUB int        `json:"doc_count_error_upper_bound"`
	SumODC  int        `json:"sum_other_doc_count"`
	Buckets []*Buckets `json:"buckets"`
}

type Total

type Total struct {
	Values   int    `json:"value"`
	Relation string `json:"relation"`
}

Jump to

Keyboard shortcuts

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