elastic_v6

package
v0.0.0-...-d31617f Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TInsert = 1
	TUpdate = 2
	TDelete = 3
)

批量存储参数(增、删、改)

Functions

This section is empty.

Types

type ESLogger

type ESLogger struct {
}

ESLogger implements the estransport.Logger interface.

func (*ESLogger) LogRoundTrip

func (l *ESLogger) LogRoundTrip(
	req *http.Request,
	res *http.Response,
	err error,
	start time.Time,
	dur time.Duration,
) error

LogRoundTrip prints the information about request and response.

func (*ESLogger) RequestBodyEnabled

func (l *ESLogger) RequestBodyEnabled() bool

RequestBodyEnabled makes the client pass request body to logger

func (*ESLogger) ResponseBodyEnabled

func (l *ESLogger) ResponseBodyEnabled() bool

RequestBodyEnabled makes the client pass response body to logger

type EsContext

type EsContext struct {
	Name     string   `mapstructure:"name"`
	Address  []string `mapstructure:"address"`
	Username string   `mapstructure:"username"`
	Password string   `mapstructure:"password"`
	// contains filtered or unexported fields
}

ElasticSearch上下文

func GetContext

func GetContext(esKey string) (*EsContext, error)

* 获取ES操作对象 * 参数esKey:对应为config.toml中es.db的name值

func NewContext

func NewContext(address []string, username string, password string) (*EsContext, error)

* 构建ES操作对象 * * param address 连接地址,格式:http://ip:porthttps://ip:port * param username 连接用户名 * param password 连接密码 * return ES操作对象

func (EsContext) BatchDeleteData

func (etx EsContext) BatchDeleteData(index string, documentType interface{}, docids []string) (result interface{}, err error)

* 批量删除文档数据 * param index 索引库名称 * param docids 文档ID(需要删除的文档) * return ES响应结果map体

func (EsContext) BatchInsertData

func (etx EsContext) BatchInsertData(index string, documentType interface{}, docids []string, datas ...interface{}) (result interface{}, err error)

* 批量插入文档数据 * param index 索引库名称 * param docids 文档ID(数组数量要与datas的个数一致,数组成员为空字符串代表由系统生成ID) * param datas 数据结构体(支持N个批量插入),标签json标识对应字段名,结构体类型举例: * type User struct { * Userid uint32 `json:"user_id"` * Amount float64 `json:"amount"` * } * return ES响应结果map体

func (EsContext) BatchStoreData

func (etx EsContext) BatchStoreData(index string, documentType interface{}, datas ...TypeBatchData) (result interface{}, err error)

* 批量存储文档数据,包括增、删和改数据 * param index 索引库名称 * param datas 数据体 * return ES响应结果map体

func (EsContext) BatchUpdateData

func (etx EsContext) BatchUpdateData(index string, documentType interface{}, docids []string, datas ...interface{}) (result interface{}, err error)

* 批量更新文档数据 * param index 索引库名称 * param docids 文档ID(数组数量要与datas的个数一致) * param datas 数据结构体(支持N个批量更新),标签json标识对应字段名,结构体类型举例: * type User struct { * Userid uint32 `json:"user_id"` * Amount float64 `json:"amount"` * } * return ES响应结果map体

func (EsContext) CheckIndexExists

func (etx EsContext) CheckIndexExists(indexs []string) (bool, error)

* 判断index是否存在 * param indexs 索引库名称,数组 * return 是否存在

func (EsContext) CountDataByQuery

func (etx EsContext) CountDataByQuery(indexs []string, musts map[string]map[string]interface{}, shoulds map[string]map[string]interface{}, filters map[string]map[string]interface{}, ranges map[string]map[string]interface{}, groupby []string, columnby map[string]map[string]interface{}) (result interface{}, err error)

* 通过检索文档进行统计数据分析 * param indexs 索引库名称,数组 * param musts 与条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:match(模糊匹配), term(全匹配), terms(相当于DB的in查询), match_not(模糊不等于), term_not(全不等于), terms_not(相当于DB的not in查询) * - key为字段名,value为检索值 * param shoulds 或条件检索map体(结构如上musts) * param filters 过滤条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:wildcard(通配符匹配,检索值中带*代表通配), regexp(正则表达式匹配), prefix(前辍匹配) * - key为字段名,value为检索值 * param ranges 范围条件检索map体 * - map体对应的JSON格式为: {"key":{"type":"value"}} * - type取值范围为:gte(大于或等于), lte(小于或等于), 其它(详见官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-range-query.html) * - key为字段名,value为检索值 * param groupby 分组字段名数组 * param columnby 分组统计项map体 * - map体对应的JSON格式为: {"name":{"type":"key"}} * - name自定义统计项名称,key为字段名。一个name只允许有一个type和key * - type取值范围为:sum(求和), max(求最大值), min(求最小值), avg(求平均值), value_count(求记录数), 其它(详见官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-aggregations-metrics.html) * return ES响应结果map体

func (EsContext) CreateIndex

func (etx EsContext) CreateIndex(index string, documentType interface{}, types map[string]interface{}, settings map[string]string) (result interface{}, err error)

* 创建index * param index 索引库名称 * param types 创建index的字段类型map体(支持多级字段属性定义) * - map体对应的JSON格式为: {"字段名":{"type": "类型"} | JSON} * - type为定义类型的键名,类型取值范围:integer, long, text, keyword, 其它(详见:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/mapping-types.html) * - JSON为内嵌字段类型定义,支持多级字段属性定义 * param settings 设置index配置项 * - map体对应的JSON格式为: {"属性名":"值"} * return ES响应结果map体

func (EsContext) DeleteData

func (etx EsContext) DeleteData(index string, documentType interface{}, docid string) (result interface{}, err error)

* 删除文档数据 * param index 索引库名称 * param docid 文档ID * return ES响应结果map体

func (EsContext) DeleteDataByQuery

func (etx EsContext) DeleteDataByQuery(indexs []string, documentType interface{}, musts map[string]map[string]interface{}, shoulds map[string]map[string]interface{}, filters map[string]map[string]interface{}, ranges map[string]map[string]interface{}) (result interface{}, err error)

* 通过检索文档进行删除数据 * param indexs 索引库名称,数组 * param musts 与条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:match(模糊匹配), term(全匹配), terms(相当于DB的in查询), match_not(模糊不等于), term_not(全不等于), terms_not(相当于DB的not in查询) * - key为字段名,value为检索值 * param shoulds 或条件检索map体(结构如上musts) * param filters 过滤条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:wildcard(通配符匹配,检索值中带*代表通配), regexp(正则表达式匹配), prefix(前辍匹配) * - key为字段名,value为检索值 * param ranges 范围条件检索map体 * - map体对应的JSON格式为: {"key":{"type":"value"}} * - type取值范围为:gte(大于或等于), lte(小于或等于), 其它(详见官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-range-query.html) * - key为字段名,value为检索值 * return ES响应结果map体

func (EsContext) DeletePhraseString

func (etx EsContext) DeletePhraseString(indexs []string, documentType interface{}, queryString map[string]interface{}, matchPhrase map[string]string) (result interface{}, err error)

* 通过分词检索删除文档数据 * param indexs 索引库名称,数组 * param queryString 检索map体(Query string query) * - map体对应的JSON格式为: {"type":"value"} * - type取值范围为:query(检索字符串), fields(字段名列表), default_field(默认字段名) * - value为设置内容 * param matchPhrase 检索map体(Match phrase query) * - map体对应的JSON格式为: {"key":"value"} * - key为字段名,value为检索值 * return ES响应结果map体

func (EsContext) GetInfo

func (etx EsContext) GetInfo() (result interface{}, err error)

* 获取ES节点信息

func (EsContext) InsertData

func (etx EsContext) InsertData(index string, documentType interface{}, docid string, data interface{}) (result interface{}, err error)

* 插入文档数据 * param index 索引库名称 * param docid 文档ID,空字符串代表由系统生成ID * param data 数据结构体,标签json标识对应字段名,结构体类型举例: * type User struct { * Userid uint32 `json:"user_id"` * Amount float64 `json:"amount"` * } * return ES响应结果map体

func (EsContext) PageByScroll

func (etx EsContext) PageByScroll(scrollId string, scroll time.Duration) (result interface{}, scrollId2 string, err error)

* 游标接口 * param scrollId 游标ID * param scroll 启用游标时间间隔

func (EsContext) QueryData

func (etx EsContext) QueryData(indexs []string, musts map[string]map[string]interface{}, shoulds map[string]map[string]interface{}, filters map[string]map[string]interface{}, ranges map[string]map[string]interface{}, offset uint32, limit uint32, sorts map[string]interface{}, source ...string) (result interface{}, err error)

* 检索文档数据 * param indexs 索引库名称,数组 * param musts 与条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:match(模糊匹配), term(全匹配), terms(相当于DB的in查询), match_not(模糊不等于), term_not(全不等于), terms_not(相当于DB的not in查询) * - key为字段名,value为检索值 * param shoulds 或条件检索map体(结构如上musts) * param filters 过滤条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:wildcard(通配符匹配,检索值中带*代表通配), regexp(正则表达式匹配), prefix(前辍匹配) * - key为字段名,value为检索值 * param ranges 范围条件检索map体 * - map体对应的JSON格式为: {"key":{"type":"value"}} * - type取值范围为:gte(大于或等于), lte(小于或等于), 其它(详见官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-range-query.html) * - key为字段名,value为检索值 * param offset 记录开始序号(0开始) * param limit 返回记录条数 * param sorts 排序map体 * - map体对应的JSON格式为: {"key":"type"} * - key为字段名,type取值范围为:desc(降序), asc(升序) * param source 要返回的字段,不传返回全部 * return ES响应结果map体

func (EsContext) QueryDataById

func (etx EsContext) QueryDataById(indexs []string, documentType interface{}, docids []string) (result interface{}, err error)

* 根据文档ID检索文档数据 * param indexs 索引库名称,数组 * param docids 文档ID * return ES响应结果map体

func (EsContext) QueryPhraseString

func (etx EsContext) QueryPhraseString(indexs []string, queryString map[string]interface{}, matchPhrase map[string]string, offset uint32, limit uint32, sorts map[string]interface{}, scroll time.Duration, source ...string) (result interface{}, scrollId string, err error)

* 分词检索文档数据 * param indexs 索引库名称,数组 * param queryString 检索map体(Query string query) * - map体对应的JSON格式为: {"type":"value"} * - type取值范围为:query(检索字符串), fields(字段名列表), default_field(默认字段名) * - value为设置内容 * param matchPhrase 检索map体(Match phrase query) * - map体对应的JSON格式为: {"key":"value"} * - key为字段名,value为检索值 * param offset 记录开始序号(0开始) * param limit 返回记录条数 * param sorts 排序map体 * - map体对应的JSON格式为: {"key":"type"} * - key为字段名,type取值范围为:desc(降序), asc(升序) * param scroll 启用游标时间间隔(0为不启用) * param source 要返回的字段,不传返回全部 * return ES响应结果map体

func (EsContext) ScrollQuery

func (etx EsContext) ScrollQuery(indexs []string, musts map[string]map[string]interface{}, shoulds map[string]map[string]interface{}, filters map[string]map[string]interface{}, ranges map[string]map[string]interface{}, offset uint32, limit uint32, sorts map[string]interface{}, scroll time.Duration, source ...string) (result interface{}, scrollId string, err error)

* 检索文档数据 * param indexs 索引库名称,数组 * param musts 与条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:match(模糊匹配), term(全匹配), terms(相当于DB的in查询), match_not(模糊不等于), term_not(全不等于), terms_not(相当于DB的not in查询) * - key为字段名,value为检索值 * param shoulds 或条件检索map体(结构如上musts) * param filters 过滤条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:wildcard(通配符匹配,检索值中带*代表通配), regexp(正则表达式匹配), prefix(前辍匹配) * - key为字段名,value为检索值 * param ranges 范围条件检索map体 * - map体对应的JSON格式为: {"key":{"type":"value"}} * - type取值范围为:gte(大于或等于), lte(小于或等于), 其它(详见官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-range-query.html) * - key为字段名,value为检索值 * param offset 记录开始序号(0开始) * param limit 返回记录条数 * param sorts 排序map体 * - map体对应的JSON格式为: {"key":"type"} * - key为字段名,type取值范围为:desc(降序), asc(升序) * param scroll 启用游标时间间隔(0为不启用) * param source 要返回的字段,不传返回全部 * return ES响应结果map体

func (EsContext) UpdateData

func (etx EsContext) UpdateData(index string, documentType interface{}, docid string, data interface{}) (result interface{}, err error)

* 更新文档数据(局部更新) * param index 索引库名称 * param docid 文档ID * param data 数据结构体 * return ES响应结果map体

func (EsContext) UpdateDataByQuery

func (etx EsContext) UpdateDataByQuery(indexs []string, documentType interface{}, updatas map[string]interface{}, musts map[string]map[string]interface{}, shoulds map[string]map[string]interface{}, filters map[string]map[string]interface{}, ranges map[string]map[string]interface{}) (result interface{}, err error)

* 通过检索文档进行修改数据 * param indexs 索引库名称,数组 * param updatas 修改数据map体,格式为:{"key":"value"} * param musts 与条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:match(模糊匹配), term(全匹配), terms(相当于DB的in查询), match_not(模糊不等于), term_not(全不等于), terms_not(相当于DB的not in查询) * - key为字段名,value为检索值 * param shoulds 或条件检索map体(结构如上musts) * param filters 过滤条件检索map体 * - map体对应的JSON格式为: {"type":{"key":"value"}} * - type取值范围为:wildcard(通配符匹配,检索值中带*代表通配), regexp(正则表达式匹配), prefix(前辍匹配) * - key为字段名,value为检索值 * param ranges 范围条件检索map体 * - map体对应的JSON格式为: {"key":{"type":"value"}} * - type取值范围为:gte(大于或等于), lte(小于或等于), 其它(详见官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-range-query.html) * - key为字段名,value为检索值 * return ES响应结果map体

type TypeBatchData

type TypeBatchData struct {
	Type int
	Doc  string
	Data interface{}
}

Jump to

Keyboard shortcuts

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