elasticsearch

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 8 Imported by: 1

README

Elasticsearch CLI

Go Reference Go Report Card

A standalone Elasticsearch interactive CLI client for Go applications.

Features

  • 🚀 RESTful API interaction
  • 📊 CAT API support (table format)
  • 🔍 Query DSL support
  • 📝 JSON formatted output
  • 🎯 Index and document management
  • ⏱️ Query timing

Installation

go get github.com/binrchq/elasticsearch-cli

Quick Start

package main

import (
    "log"
    "os"
    
    elasticsearchcli "github.com/binrchq/elasticsearch-cli"
)

func main() {
    cli := elasticsearchcli.NewCLI(
        os.Stdin,
        "localhost",
        9200,
        "elastic",
        "password",
    )
    
    if err := cli.Connect(); err != nil {
        log.Fatal(err)
    }
    defer cli.Close()
    
    if err := cli.Start(); err != nil {
        log.Fatal(err)
    }
}

Command Format

METHOD /path [body]

Usage Examples

Cluster Information
GET /
GET /_cluster/health
CAT API
cat indices
cat nodes
cat shards
Index Operations
PUT /my-index
GET /my-index
DELETE /my-index
Document Operations
POST /my-index/_doc {"field": "value"}
GET /my-index/_doc/id
DELETE /my-index/_doc/id
GET /my-index/_search
GET /my-index/_search {"query": {"match_all": {}}}

Special Commands

  • help - Show help
  • exit, quit - Exit
  • pretty - Toggle pretty print
  • timing - Toggle timing
  • use <index> - Set current index
  • cat <command> - CAT API commands

Requirements

  • Go 1.21 or higher
  • Elasticsearch 7.0 or higher

Dependencies

License

MIT License - see LICENSE file for details.

Author

Maintained by binrc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLI

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

CLI Elasticsearch 交互式命令行客户端

func NewCLI

func NewCLI(term Terminal, host string, port int, username, password string) *CLI

NewCLI 创建新的 Elasticsearch CLI 实例

func NewCLIWithConfig added in v0.1.1

func NewCLIWithConfig(term Terminal, config *Config) *CLI

NewCLIWithConfig 使用配置创建 Elasticsearch CLI 实例

func (*CLI) Close

func (c *CLI) Close() error

Close 关闭连接

func (*CLI) Connect

func (c *CLI) Connect() error

Connect 连接到 Elasticsearch

func (*CLI) Start

func (c *CLI) Start() error

Start 启动交互式命令行

type Config added in v0.1.1

type Config struct {
	Host                 string
	Port                 int
	Username             string
	Password             string
	Scheme               string // http, https
	APIKey               string // API Key 认证
	CertFingerprint      string // 证书指纹
	DisableRetry         bool   // 禁用重试
	MaxRetries           int    // 最大重试次数
	EnableDebugLogger    bool   // 启用调试日志
	CompressRequestBody  bool   // 压缩请求体
	DiscoverNodesOnStart bool   // 启动时发现节点
	// 其他参数
	Params map[string]string
}

Config Elasticsearch 连接配置

type ReadWriteCloser added in v0.1.1

type ReadWriteCloser struct {
	io.ReadWriter
}

ReadWriteCloser wraps io.ReadWriter to add a no-op Close method

func (*ReadWriteCloser) Close added in v0.1.1

func (rwc *ReadWriteCloser) Close() error

type Reader

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

Reader 从终端读取输入(使用 readline 以支持SSH session)

func NewReader

func NewReader(term io.ReadWriter) *Reader

NewReader 创建新的 Reader

func (*Reader) Close

func (r *Reader) Close() error

Close 关闭读取器

func (*Reader) ReadLine

func (r *Reader) ReadLine() (string, error)

ReadLine 读取一行输入

type ServerInfo

type ServerInfo struct {
	Name        string
	ClusterName string
	Version     string
	Lucene      string
}

ServerInfo Elasticsearch 服务器信息

type Terminal

type Terminal interface {
	io.Reader
	io.Writer
}

Terminal 终端接口,用于输入输出

Jump to

Keyboard shortcuts

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