Compare commits
No commits in common. "91ddffe752e89d0cc042e59c194633fa759d126f" and "d3524d0f059ae4fad27ce492a368ecf3c48808fb" have entirely different histories.
91ddffe752
...
d3524d0f05
55
.github/workflows/build.yml
vendored
55
.github/workflows/build.yml
vendored
@ -1,55 +0,0 @@
|
|||||||
name: Auto Build
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-job:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
id-token: write
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
repository-projects: write
|
|
||||||
steps:
|
|
||||||
- name: checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: install golang
|
|
||||||
uses: actions/setup-go@v4
|
|
||||||
with:
|
|
||||||
go-version: '1.18'
|
|
||||||
|
|
||||||
- name: build linux amd64
|
|
||||||
run: CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_linux_amd64 .
|
|
||||||
|
|
||||||
- name: build linux arm64
|
|
||||||
run: CGO_ENABLE=0 GOOS=linux GOARCH=arm64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_linux_arm64 .
|
|
||||||
|
|
||||||
- name: build windows amd64
|
|
||||||
run: CGO_ENABLE=0 GOOS=windows GOARCH=amd64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_windows_amd64.exe .
|
|
||||||
|
|
||||||
- name: build windows arm64
|
|
||||||
run: CGO_ENABLE=0 GOOS=windows GOARCH=arm64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_windows_arm64.exe .
|
|
||||||
|
|
||||||
- name: build darwin amd64
|
|
||||||
run: CGO_ENABLE=0 GOOS=darwin GOARCH=amd64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_darwin_amd64 .
|
|
||||||
|
|
||||||
- name: build darwin arm64
|
|
||||||
run: CGO_ENABLE=0 GOOS=darwin GOARCH=arm64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_darwin_arm64 .
|
|
||||||
|
|
||||||
- name: create releases
|
|
||||||
id: create_releases
|
|
||||||
uses: "marvinpinto/action-automatic-releases@latest"
|
|
||||||
with:
|
|
||||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
title: "Release_${{ github.ref_name }}"
|
|
||||||
files: |
|
|
||||||
dist/esgo2dump_${{ github.ref_name }}_linux_amd64
|
|
||||||
dist/esgo2dump_${{ github.ref_name }}_linux_arm64
|
|
||||||
dist/esgo2dump_${{ github.ref_name }}_windows_amd64.exe
|
|
||||||
dist/esgo2dump_${{ github.ref_name }}_windows_arm64.exe
|
|
||||||
dist/esgo2dump_${{ github.ref_name }}_darwin_amd64
|
|
||||||
dist/esgo2dump_${{ github.ref_name }}_darwin_amd64
|
|
||||||
dist/esgo2dump_${{ github.ref_name }}_darwin_arm64
|
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,5 +5,4 @@ data.json
|
|||||||
mapping.json
|
mapping.json
|
||||||
setting.json
|
setting.json
|
||||||
output.json
|
output.json
|
||||||
*.txt
|
*.txt
|
||||||
dist
|
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module esgo2dump
|
module esgo2dump
|
||||||
|
|
||||||
go 1.18
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/elastic/go-elasticsearch/v7 v7.17.10
|
github.com/elastic/go-elasticsearch/v7 v7.17.10
|
||||||
|
@ -16,8 +16,6 @@ var (
|
|||||||
Example: `
|
Example: `
|
||||||
esgo2dump --input=http://127.0.0.1:9200/some_index --output=./data.json
|
esgo2dump --input=http://127.0.0.1:9200/some_index --output=./data.json
|
||||||
|
|
||||||
esgo2dump --input=http://127.0.0.1:9200/some_index --output=http://192.168.1.1:9200/some_index --limit=5000
|
|
||||||
|
|
||||||
esgo2dump --input=https://username:password@127.0.0.1:9200/some_index --output=./data.json
|
esgo2dump --input=https://username:password@127.0.0.1:9200/some_index --output=./data.json
|
||||||
|
|
||||||
esgo2dump --input=http://127.0.0.1:9200/some_index --output=./data.json --query='{"match": {"name": "some_name"}}'`,
|
esgo2dump --input=http://127.0.0.1:9200/some_index --output=./data.json --query='{"match": {"name": "some_name"}}'`,
|
||||||
|
@ -51,30 +51,18 @@ func run(cmd *cobra.Command, args []string) error {
|
|||||||
return executeData(cmd.Context(), ioi, ioo)
|
return executeData(cmd.Context(), ioi, ioo)
|
||||||
case "mapping":
|
case "mapping":
|
||||||
var mapping map[string]any
|
var mapping map[string]any
|
||||||
if mapping, err = ioi.ReadMapping(cmd.Context()); err != nil {
|
if mapping, err = ioi.ReadMapping(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = ioo.WriteMapping(cmd.Context(), mapping); err != nil {
|
return ioo.WriteMapping(mapping)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Info("Dump: write mapping succeed!!!")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
case "setting":
|
case "setting":
|
||||||
var setting map[string]any
|
var setting map[string]any
|
||||||
if setting, err = ioi.ReadSetting(cmd.Context()); err != nil {
|
if setting, err = ioi.ReadSetting(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = ioo.WriteSetting(cmd.Context(), setting); err != nil {
|
return ioo.WriteSetting(setting)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Info("Dump: write setting succeed!!!")
|
|
||||||
|
|
||||||
return nil
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown type=%s", f_type)
|
return fmt.Errorf("unknown type=%s", f_type)
|
||||||
}
|
}
|
||||||
@ -88,28 +76,33 @@ func executeData(ctx context.Context, input, output interfaces.DumpIO) error {
|
|||||||
)
|
)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
default:
|
||||||
|
|
||||||
if lines, err = input.ReadData(ctx, f_limit); err != nil {
|
if lines, err = input.ReadData(f_limit); err != nil {
|
||||||
if errors.Is(err, io.EOF) {
|
if errors.Is(err, io.EOF) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(lines) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
if succeed, err = output.WriteData(lines); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if succeed != len(lines) {
|
||||||
|
return fmt.Errorf("cmd.run: got lines=%d, only succeed=%d", len(lines), succeed)
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Infof("Dump: %d docs succeed!!!", succeed)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(lines) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if succeed, err = output.WriteData(ctx, lines); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if succeed != len(lines) {
|
|
||||||
return fmt.Errorf("cmd.run: got lines=%d, only succeed=%d", len(lines), succeed)
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Infof("Dump: %d docs succeed!!!", succeed)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +140,7 @@ func newIO(source string, ioType interfaces.IO) (interfaces.DumpIO, error) {
|
|||||||
|
|
||||||
logrus.Debugf("newIO.%s: source as url=%+v", ioType.Code(), *iurl)
|
logrus.Debugf("newIO.%s: source as url=%+v", ioType.Code(), *iurl)
|
||||||
|
|
||||||
return xes.NewClient(iurl, ioType, qm)
|
return xes.NewClient(iurl, qm)
|
||||||
|
|
||||||
ClientByFile:
|
ClientByFile:
|
||||||
if ioType == interfaces.IOOutput {
|
if ioType == interfaces.IOOutput {
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
package interfaces
|
package interfaces
|
||||||
|
|
||||||
import "context"
|
|
||||||
|
|
||||||
type DumpIO interface {
|
type DumpIO interface {
|
||||||
ReadData(context.Context, int) ([]*ESSource, error)
|
ReadData(int) ([]*ESSource, error)
|
||||||
WriteData(ctx context.Context, docs []*ESSource) (int, error)
|
ReadMapping() (map[string]any, error)
|
||||||
|
ReadSetting() (map[string]any, error)
|
||||||
ReadMapping(context.Context) (map[string]any, error)
|
WriteData(docs []*ESSource) (int, error)
|
||||||
WriteMapping(context.Context, map[string]any) error
|
WriteMapping(map[string]any) error
|
||||||
|
WriteSetting(map[string]any) error
|
||||||
ReadSetting(ctx context.Context) (map[string]any, error)
|
|
||||||
WriteSetting(context.Context, map[string]any) error
|
|
||||||
|
|
||||||
Close() error
|
Close() error
|
||||||
|
|
||||||
IOType() IO
|
IsInput() bool
|
||||||
IsFile() bool
|
IsFile() bool
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,3 @@ type ESResponse struct {
|
|||||||
Hits []*ESSource `json:"hits"`
|
Hits []*ESSource `json:"hits"`
|
||||||
} `json:"hits"`
|
} `json:"hits"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ESMapping map[string]struct {
|
|
||||||
Mappings struct {
|
|
||||||
Properties map[string]any `json:"properties"`
|
|
||||||
} `json:"mappings"`
|
|
||||||
}
|
|
||||||
|
@ -15,14 +15,3 @@ func Timeout(seconds ...int) context.Context {
|
|||||||
|
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func TimeoutCtx(ctx context.Context, seconds ...int) context.Context {
|
|
||||||
second := 30
|
|
||||||
if len(seconds) > 0 && seconds[0] > 0 {
|
|
||||||
second = seconds[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout, _ := context.WithTimeout(ctx, time.Duration(second)*time.Second)
|
|
||||||
|
|
||||||
return timeout
|
|
||||||
}
|
|
||||||
|
@ -13,14 +13,13 @@ import (
|
|||||||
"github.com/elastic/go-elasticsearch/v7/esapi"
|
"github.com/elastic/go-elasticsearch/v7/esapi"
|
||||||
"github.com/elastic/go-elasticsearch/v7/esutil"
|
"github.com/elastic/go-elasticsearch/v7/esutil"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"net"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewClient(url *url.URL, iot interfaces.IO, qm map[string]any) (interfaces.DumpIO, error) {
|
func NewClient(url *url.URL, qm map[string]any) (interfaces.DumpIO, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
@ -56,7 +55,6 @@ func NewClient(url *url.URL, iot interfaces.IO, qm map[string]any) (interfaces.D
|
|||||||
RetryBackoff: nil,
|
RetryBackoff: nil,
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
DialContext: (&net.Dialer{Timeout: 5 * time.Second}).DialContext,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
); err != nil {
|
); err != nil {
|
||||||
@ -73,28 +71,46 @@ func NewClient(url *url.URL, iot interfaces.IO, qm map[string]any) (interfaces.D
|
|||||||
return nil, fmt.Errorf("info xes status=%d", infoResp.StatusCode)
|
return nil, fmt.Errorf("info xes status=%d", infoResp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &client{c: c, index: index, queryMap: qm, iot: iot}, nil
|
return &client{c: c, index: index, queryMap: qm}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
c *elastic.Client
|
c *elastic.Client
|
||||||
iot interfaces.IO
|
|
||||||
index string
|
index string
|
||||||
from int
|
from int
|
||||||
scrollId string
|
scrollId string
|
||||||
queryMap map[string]any
|
queryMap map[string]any
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) checkResponse(r *esapi.Response) error {
|
func (c *client) ReadSetting() (map[string]any, error) {
|
||||||
if r.StatusCode == 200 {
|
r, err := c.c.Indices.GetSettings(
|
||||||
return nil
|
c.c.Indices.GetSettings.WithIndex(c.index),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("status=%d msg=%s", r.StatusCode, r.String())
|
if r.StatusCode != 200 {
|
||||||
|
return nil, fmt.Errorf("status=%d, msg=%s", r.StatusCode, r.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
m := make(map[string]any)
|
||||||
|
decoder := json.NewDecoder(r.Body)
|
||||||
|
if err = decoder.Decode(&m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) IOType() interfaces.IO {
|
func (c *client) WriteSetting(m map[string]any) error {
|
||||||
return c.iot
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *client) IsInput() bool {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) IsFile() bool {
|
func (c *client) IsFile() bool {
|
||||||
@ -105,7 +121,7 @@ func (c *client) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) WriteData(ctx context.Context, docs []*interfaces.ESSource) (int, error) {
|
func (c *client) WriteData(docs []*interfaces.ESSource) (int, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
indexer esutil.BulkIndexer
|
indexer esutil.BulkIndexer
|
||||||
@ -139,7 +155,7 @@ func (c *client) WriteData(ctx context.Context, docs []*interfaces.ESSource) (in
|
|||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = indexer.Close(util.TimeoutCtx(ctx, opt.Timeout)); err != nil {
|
if err = indexer.Close(util.Timeout(opt.Timeout)); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +167,7 @@ func (c *client) WriteData(ctx context.Context, docs []*interfaces.ESSource) (in
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ReadData(ctx context.Context, i int) ([]*interfaces.ESSource, error) {
|
func (c *client) ReadData(i int) ([]*interfaces.ESSource, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
resp *esapi.Response
|
resp *esapi.Response
|
||||||
@ -160,7 +176,7 @@ func (c *client) ReadData(ctx context.Context, i int) ([]*interfaces.ESSource, e
|
|||||||
|
|
||||||
if c.scrollId == "" {
|
if c.scrollId == "" {
|
||||||
qs := []func(*esapi.SearchRequest){
|
qs := []func(*esapi.SearchRequest){
|
||||||
c.c.Search.WithContext(util.TimeoutCtx(ctx, opt.Timeout)),
|
c.c.Search.WithContext(util.Timeout(opt.Timeout)),
|
||||||
c.c.Search.WithIndex(c.index),
|
c.c.Search.WithIndex(c.index),
|
||||||
c.c.Search.WithSize(i),
|
c.c.Search.WithSize(i),
|
||||||
c.c.Search.WithFrom(0),
|
c.c.Search.WithFrom(0),
|
||||||
@ -205,7 +221,7 @@ func (c *client) ReadData(ctx context.Context, i int) ([]*interfaces.ESSource, e
|
|||||||
return result.Hits.Hits, nil
|
return result.Hits.Hits, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ReadMapping(ctx context.Context) (map[string]any, error) {
|
func (c *client) ReadMapping() (map[string]any, error) {
|
||||||
r, err := c.c.Indices.GetMapping(
|
r, err := c.c.Indices.GetMapping(
|
||||||
c.c.Indices.GetMapping.WithIndex(c.index),
|
c.c.Indices.GetMapping.WithIndex(c.index),
|
||||||
)
|
)
|
||||||
@ -225,73 +241,7 @@ func (c *client) ReadMapping(ctx context.Context) (map[string]any, error) {
|
|||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
func (c *client) WriteMapping(ctx context.Context, m map[string]any) error {
|
func (c *client) WriteMapping(m map[string]any) error {
|
||||||
var (
|
//TODO implement me
|
||||||
err error
|
panic("implement me")
|
||||||
bs []byte
|
|
||||||
result *esapi.Response
|
|
||||||
)
|
|
||||||
|
|
||||||
for idxKey := range m {
|
|
||||||
if bs, err = json.Marshal(m[idxKey]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if result, err = c.c.Indices.Create(
|
|
||||||
c.index,
|
|
||||||
c.c.Indices.Create.WithContext(util.TimeoutCtx(ctx, opt.Timeout)),
|
|
||||||
c.c.Indices.Create.WithBody(bytes.NewReader(bs)),
|
|
||||||
); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = c.checkResponse(result); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *client) ReadSetting(ctx context.Context) (map[string]any, error) {
|
|
||||||
r, err := c.c.Indices.GetSettings(
|
|
||||||
c.c.Indices.GetSettings.WithContext(util.TimeoutCtx(ctx, opt.Timeout)),
|
|
||||||
c.c.Indices.GetSettings.WithIndex(c.index),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.StatusCode != 200 {
|
|
||||||
return nil, fmt.Errorf("status=%d, msg=%s", r.StatusCode, r.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
m := make(map[string]any)
|
|
||||||
decoder := json.NewDecoder(r.Body)
|
|
||||||
if err = decoder.Decode(&m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return m, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *client) WriteSetting(ctx context.Context, m map[string]any) error {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
bs []byte
|
|
||||||
result *esapi.Response
|
|
||||||
)
|
|
||||||
|
|
||||||
if bs, err = json.Marshal(m); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if result, err = c.c.Indices.PutSettings(
|
|
||||||
bytes.NewReader(bs),
|
|
||||||
c.c.Indices.PutSettings.WithContext(util.TimeoutCtx(ctx, opt.Timeout)),
|
|
||||||
); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.checkResponse(result)
|
|
||||||
}
|
}
|
||||||
|
@ -2,59 +2,28 @@ package xfile
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"esgo2dump/internal/interfaces"
|
"esgo2dump/internal/interfaces"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
f *os.File
|
f *os.File
|
||||||
iot interfaces.IO
|
|
||||||
scanner *bufio.Scanner
|
scanner *bufio.Scanner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ReadMapping(ctx context.Context) (map[string]any, error) {
|
func (c *client) ReadMapping() (map[string]any, error) {
|
||||||
var (
|
//TODO implement me
|
||||||
err error
|
panic("implement me")
|
||||||
bs []byte
|
|
||||||
)
|
|
||||||
|
|
||||||
if bs, err = io.ReadAll(c.f); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
m := make(map[string]any)
|
|
||||||
|
|
||||||
if err = json.Unmarshal(bs, &m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return m, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ReadSetting(ctx context.Context) (map[string]any, error) {
|
func (c *client) ReadSetting() (map[string]any, error) {
|
||||||
var (
|
//TODO implement me
|
||||||
err error
|
panic("implement me")
|
||||||
bs []byte
|
|
||||||
)
|
|
||||||
|
|
||||||
if bs, err = io.ReadAll(c.f); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
m := make(map[string]any)
|
|
||||||
|
|
||||||
if err = json.Unmarshal(bs, &m); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return m, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) WriteMapping(ctx context.Context, m map[string]any) error {
|
func (c *client) WriteMapping(m map[string]any) error {
|
||||||
bs, err := json.Marshal(m)
|
bs, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -65,7 +34,7 @@ func (c *client) WriteMapping(ctx context.Context, m map[string]any) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) WriteSetting(ctx context.Context, m map[string]any) error {
|
func (c *client) WriteSetting(m map[string]any) error {
|
||||||
bs, err := json.Marshal(m)
|
bs, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -76,15 +45,16 @@ func (c *client) WriteSetting(ctx context.Context, m map[string]any) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) IOType() interfaces.IO {
|
func (c *client) IsInput() bool {
|
||||||
return c.iot
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) IsFile() bool {
|
func (c *client) IsFile() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) WriteData(ctx context.Context, docs []*interfaces.ESSource) (int, error) {
|
func (c *client) WriteData(docs []*interfaces.ESSource) (int, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
bs []byte
|
bs []byte
|
||||||
@ -108,7 +78,7 @@ func (c *client) WriteData(ctx context.Context, docs []*interfaces.ESSource) (in
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) ReadData(ctx context.Context, i int) ([]*interfaces.ESSource, error) {
|
func (c *client) ReadData(i int) ([]*interfaces.ESSource, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
count = 0
|
count = 0
|
||||||
@ -145,7 +115,7 @@ func (c *client) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(file *os.File, ioType interfaces.IO) (interfaces.DumpIO, error) {
|
func NewClient(file *os.File, ioType interfaces.IO) (interfaces.DumpIO, error) {
|
||||||
c := &client{f: file, iot: ioType}
|
c := &client{f: file}
|
||||||
|
|
||||||
if ioType == interfaces.IOInput {
|
if ioType == interfaces.IOInput {
|
||||||
c.scanner = bufio.NewScanner(c.f)
|
c.scanner = bufio.NewScanner(c.f)
|
||||||
|
42
readme.md
42
readme.md
@ -1,42 +0,0 @@
|
|||||||
# esgo2dump
|
|
||||||
# dump elasticsearch with golang
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
- 当前仅支持 elasticsearch 7
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### install
|
|
||||||
|
|
||||||
- with golang >= 1.18
|
|
||||||
|
|
||||||
`go install github.com/loveuer/esgo2dump@latest`
|
|
||||||
|
|
||||||
- download pre-build release:
|
|
||||||
|
|
||||||
[releases](https://github.com/loveuer/esgo2dump/releases)
|
|
||||||
|
|
||||||
### usage
|
|
||||||
|
|
||||||
`esgo2dump -h`
|
|
||||||
|
|
||||||
```bash
|
|
||||||
esgo2dump --input=http://127.0.0.1:9200/some_index --output=./data.json
|
|
||||||
|
|
||||||
esgo2dump --input=http://127.0.0.1:9200/some_index --output=http://192.168.1.1:9200/some_index --limit=5000
|
|
||||||
|
|
||||||
esgo2dump --input=https://username:password@127.0.0.1:9200/some_index --output=./data.json
|
|
||||||
|
|
||||||
esgo2dump --input=http://127.0.0.1:9200/some_index --output=./data.json --query='{"match": {"name": "some_name"}}'`,
|
|
||||||
```
|
|
||||||
|
|
||||||
### roadmap
|
|
||||||
|
|
||||||
- [x] data dump
|
|
||||||
- [x] mapping dump
|
|
||||||
- [x] es to file
|
|
||||||
- [x] es to es
|
|
||||||
- [x] auto create index with mapping
|
|
||||||
- [ ] auto create index with mapping,setting
|
|
||||||
- [ ] support es8
|
|
Loading…
x
Reference in New Issue
Block a user