esexporter

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: MIT Imports: 8 Imported by: 1

README

esexporter

dump Elasticsearch documents with streaming JSON decoder, avoid decoding the whole response

Intro (CN)

近期尝试使用 olivere/elastic 库从 Elasticsearch 集群上导出十多T的数据,发现 Scroll 的速度很慢。

跑了下 CPU Profile 发现,是 olivere/elastic 在请求结果 JSON 解析阶段消耗的时间太多了。

我只需要获取 hits.hits 中的 source 字段,结构化解析不仅慢,还非常消耗内存,因此我打造了这个库。

Usage

import (
 "github.com/guoyk93/esexporter"
)

err := esexporter.New(client,exexporter.Options{
    // ...
}, func (src []byte, cursor int64, total int64) error {
    // ...
    return nil
}).Do(context.Background())

Credits

Guo Y.K., MIT License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserCancelled = errors.New("user cancelled")
)

Functions

This section is empty.

Types

type Exporter

type Exporter interface {
	Do(ctx context.Context) error
}

func New

func New(client *elastic.Client, opts Options, handler SourceHandler) Exporter

type Options

type Options struct {
	Index         string
	Type          string
	Query         elastic.Query
	Scroll        string
	BatchByteSize int64
	BatchSize     int64
	NoMappingType bool
}

type SourceHandler added in v1.2.0

type SourceHandler func(buf []byte, id int64, total int64) error

Jump to

Keyboard shortcuts

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