goo_es

package
v1.1.193 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(conf Config)

Types

type Config

type Config struct {
	Addresses []string `json:"addresses" yaml:"addresses"`
	User      string   `json:"user" yaml:"user"`
	Password  string   `json:"password" yaml:"password"`
	EnableLog bool     `json:"enable_log" yaml:"enable_log"`
}

type ESClient added in v1.1.76

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

func Client

func Client() *ESClient

func New

func New(conf Config) (*ESClient, error)

func (*ESClient) Client added in v1.1.163

func (c *ESClient) Client() *elasticsearch.Client

func (*ESClient) Delete added in v1.1.163

func (c *ESClient) Delete(index, docId string) (*esapi.Response, error)

删除文档

func (*ESClient) DeleteByQuery added in v1.1.163

func (c *ESClient) DeleteByQuery(index []string, b []byte) (*esapi.Response, error)

删除文档

func (*ESClient) Index added in v1.1.163

func (c *ESClient) Index(index, docId string, b []byte) (*esapi.Response, error)

添加、更新文档

func (*ESClient) IndexTemplateDel added in v1.1.163

func (c *ESClient) IndexTemplateDel(name string) (*esapi.Response, error)

删除索引模版

func (*ESClient) IndexTemplatePut added in v1.1.163

func (c *ESClient) IndexTemplatePut(name string, b []byte) (*esapi.Response, error)

创建索引模版

- lifecycle.name: 生命周期策略 - number_of_shards: 索引分片数量 - number_of_replicas: 索引副本数量 - - nested: 嵌套对象 {list: [{id:1, name:”}]}

{
   "index_patterns": ["abc-*"],
   "template": {
       "settings": {
           "number_of_shards": 3,
           "number_of_replicas": 0,
           "index.lifecycle.name": "90-days-default",
           "index.lifecycle.rollover_alias": "abc"
       },
       "mappings": {
           "properties": {
               "id": {"type": "integer"},
               "datetime": {"type": "date", "format": "yyyy-MM-dd HH:mm:ss"},
               "name": {"type": "text"},
               "list": {
                   "type": "nested",
                   "properties": {
                       "id": {"type": "integer"},
                       "name": {"type": "text"},
                   }
               }
           }
       }
   }
}

func (*ESClient) Search added in v1.1.163

func (c *ESClient) Search(index []string, b []byte) (*esapi.Response, error)

搜索

- range: 范围搜索 - match: 匹配搜索 - match_phrase: 全文检索 - nested: 嵌套搜索 - inner_hits: 只返回匹配项 - inner_hits.size: 只返回匹配项的第1项 - highlight: 高亮 - _source.excludes: 不返回字段

GET /abd-*/_search

{
  "from" : 0,
  "size" : 10,
  "query": {
    "bool": {
      "must": [
        {"match": { "user_id": 2716 }},
        {"range": { "datetime": { "gte": "2024-01-14 00:00:00", "lte": "2024-01-14 23:59:59" }}},
        {"range": { "size": { "gte": 60, "lte": 3600 }}},
        {
          "nested": {
            "path": "list",
            "query": {
              "match_phrase": { "list.title": "青岛" }
            },
            "inner_hits": {
              "size": 1
            }
          }
        }
      ]
    }
  },
  "highlight": {
    "pre_tags": "<em>",
    "post_tags": "</em>",
    "fields": {
      "list.title": {}
    }
  },
  "_source": {
    "excludes" : ["list"]
  }
}

Jump to

Keyboard shortcuts

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