Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
f75e31ffbb | |||
f990923dd8 | |||
91ddffe752 | |||
ff7aa194aa | |||
887f450cf8 | |||
77f0bbebe2 |
11
.github/workflows/build.yml
vendored
11
.github/workflows/build.yml
vendored
@ -13,10 +13,13 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
repository-projects: write
|
repository-projects: write
|
||||||
steps:
|
steps:
|
||||||
|
- name: checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: install golang
|
- name: install golang
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: '1.20'
|
go-version: '1.18'
|
||||||
|
|
||||||
- name: build linux amd64
|
- 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 .
|
run: CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_linux_amd64 .
|
||||||
@ -27,6 +30,9 @@ jobs:
|
|||||||
- name: build windows amd64
|
- 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 .
|
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
|
- 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 .
|
run: CGO_ENABLE=0 GOOS=darwin GOARCH=amd64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_darwin_amd64 .
|
||||||
|
|
||||||
@ -34,7 +40,7 @@ jobs:
|
|||||||
run: CGO_ENABLE=0 GOOS=darwin GOARCH=arm64 go build -ldflags='-s -w' -o dist/esgo2dump_${{ github.ref_name }}_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
|
- name: create releases
|
||||||
id: create_release
|
id: create_releases
|
||||||
uses: "marvinpinto/action-automatic-releases@latest"
|
uses: "marvinpinto/action-automatic-releases@latest"
|
||||||
with:
|
with:
|
||||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
@ -43,6 +49,7 @@ jobs:
|
|||||||
dist/esgo2dump_${{ github.ref_name }}_linux_amd64
|
dist/esgo2dump_${{ github.ref_name }}_linux_amd64
|
||||||
dist/esgo2dump_${{ github.ref_name }}_linux_arm64
|
dist/esgo2dump_${{ github.ref_name }}_linux_arm64
|
||||||
dist/esgo2dump_${{ github.ref_name }}_windows_amd64.exe
|
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_amd64
|
dist/esgo2dump_${{ github.ref_name }}_darwin_amd64
|
||||||
dist/esgo2dump_${{ github.ref_name }}_darwin_arm64
|
dist/esgo2dump_${{ github.ref_name }}_darwin_arm64
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ mapping.json
|
|||||||
setting.json
|
setting.json
|
||||||
output.json
|
output.json
|
||||||
*.txt
|
*.txt
|
||||||
|
dist
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module esgo2dump
|
module github.com/loveuer/esgo2dump
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
|
@ -2,7 +2,8 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"esgo2dump/internal/opt"
|
|
||||||
|
"github.com/loveuer/esgo2dump/internal/opt"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,16 +4,17 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"esgo2dump/internal/interfaces"
|
|
||||||
"esgo2dump/internal/opt"
|
|
||||||
"esgo2dump/internal/xes"
|
|
||||||
"esgo2dump/internal/xfile"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/loveuer/esgo2dump/internal/interfaces"
|
||||||
|
"github.com/loveuer/esgo2dump/internal/opt"
|
||||||
|
"github.com/loveuer/esgo2dump/internal/xes"
|
||||||
|
"github.com/loveuer/esgo2dump/internal/xfile"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run(cmd *cobra.Command, args []string) error {
|
func run(cmd *cobra.Command, args []string) error {
|
||||||
@ -27,6 +28,10 @@ func run(cmd *cobra.Command, args []string) error {
|
|||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if f_limit == 0 || f_limit > 10000 {
|
||||||
|
return fmt.Errorf("invalid limit(1 - 10000)")
|
||||||
|
}
|
||||||
|
|
||||||
switch f_type {
|
switch f_type {
|
||||||
case "data", "mapping", "setting":
|
case "data", "mapping", "setting":
|
||||||
default:
|
default:
|
||||||
@ -55,14 +60,26 @@ func run(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioo.WriteMapping(cmd.Context(), mapping)
|
if err = ioo.WriteMapping(cmd.Context(), mapping); err != nil {
|
||||||
|
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(cmd.Context()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioo.WriteSetting(cmd.Context(), setting)
|
if err = ioo.WriteSetting(cmd.Context(), setting); err != nil {
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
@ -98,7 +115,6 @@ func executeData(ctx context.Context, input, output interfaces.DumpIO) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("Dump: %d docs succeed!!!", succeed)
|
logrus.Infof("Dump: %d docs succeed!!!", succeed)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,18 +5,20 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"esgo2dump/internal/interfaces"
|
|
||||||
"esgo2dump/internal/opt"
|
|
||||||
"esgo2dump/internal/util"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
elastic "github.com/elastic/go-elasticsearch/v7"
|
"net"
|
||||||
"github.com/elastic/go-elasticsearch/v7/esapi"
|
|
||||||
"github.com/elastic/go-elasticsearch/v7/esutil"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
elastic "github.com/elastic/go-elasticsearch/v7"
|
||||||
|
"github.com/elastic/go-elasticsearch/v7/esapi"
|
||||||
|
"github.com/elastic/go-elasticsearch/v7/esutil"
|
||||||
|
"github.com/loveuer/esgo2dump/internal/interfaces"
|
||||||
|
"github.com/loveuer/esgo2dump/internal/opt"
|
||||||
|
"github.com/loveuer/esgo2dump/internal/util"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewClient(url *url.URL, iot interfaces.IO, qm map[string]any) (interfaces.DumpIO, error) {
|
func NewClient(url *url.URL, iot interfaces.IO, qm map[string]any) (interfaces.DumpIO, error) {
|
||||||
@ -55,6 +57,7 @@ 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 {
|
||||||
@ -108,6 +111,7 @@ func (c *client) WriteData(ctx context.Context, docs []*interfaces.ESSource) (in
|
|||||||
err error
|
err error
|
||||||
indexer esutil.BulkIndexer
|
indexer esutil.BulkIndexer
|
||||||
count int
|
count int
|
||||||
|
be error
|
||||||
)
|
)
|
||||||
if indexer, err = esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
|
if indexer, err = esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
|
||||||
Client: c.c,
|
Client: c.c,
|
||||||
@ -131,6 +135,9 @@ func (c *client) WriteData(ctx context.Context, docs []*interfaces.ESSource) (in
|
|||||||
Index: c.index,
|
Index: c.index,
|
||||||
DocumentID: doc.DocId,
|
DocumentID: doc.DocId,
|
||||||
Body: bytes.NewReader(bs),
|
Body: bytes.NewReader(bs),
|
||||||
|
OnFailure: func(ctx context.Context, item esutil.BulkIndexerItem, item2 esutil.BulkIndexerResponseItem, bulkErr error) {
|
||||||
|
be = bulkErr
|
||||||
|
},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@ -141,9 +148,13 @@ func (c *client) WriteData(ctx context.Context, docs []*interfaces.ESSource) (in
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if be != nil {
|
||||||
|
return 0, be
|
||||||
|
}
|
||||||
|
|
||||||
stats := indexer.Stats()
|
stats := indexer.Stats()
|
||||||
if stats.NumFailed > 0 {
|
if stats.NumFailed > 0 {
|
||||||
return count, fmt.Errorf("write to xes failed=%d", stats.NumFailed)
|
return count, fmt.Errorf("write to xes failed_count=%d bulk_count=%d", stats.NumFailed, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
return count, nil
|
return count, nil
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package xes
|
package xes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"esgo2dump/internal/util"
|
|
||||||
elastic "github.com/elastic/go-elasticsearch/v7"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
elastic "github.com/elastic/go-elasticsearch/v7"
|
||||||
|
"github.com/loveuer/esgo2dump/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetESMapping(t *testing.T) {
|
func TestGetESMapping(t *testing.T) {
|
||||||
|
@ -4,10 +4,11 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"esgo2dump/internal/interfaces"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/loveuer/esgo2dump/internal/interfaces"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
|
3
main.go
3
main.go
@ -2,10 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"esgo2dump/internal/cmd"
|
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/loveuer/esgo2dump/internal/cmd"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
32
readme.md
32
readme.md
@ -15,24 +15,28 @@
|
|||||||
|
|
||||||
- download pre-build release:
|
- download pre-build release:
|
||||||
|
|
||||||
[release](https://github.com/loveuer/esgo2dump/releases)
|
[releases](https://github.com/loveuer/esgo2dump/releases)
|
||||||
|
|
||||||
### usage
|
### usage
|
||||||
|
|
||||||
`esgo2dump -h`
|
`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
|
### roadmap
|
||||||
|
|
||||||
[*] data dump
|
- [x] data dump
|
||||||
|
- [x] mapping dump
|
||||||
[*] mapping dump
|
- [x] es to file
|
||||||
|
- [x] es to es
|
||||||
[*] es to file
|
- [x] auto create index with mapping
|
||||||
|
- [ ] auto create index with mapping,setting
|
||||||
[*] es to es
|
- [ ] support es8
|
||||||
|
|
||||||
[*] auto create index with mapping
|
|
||||||
|
|
||||||
[ ] auto create index with mapping,setting
|
|
||||||
|
|
||||||
[ ] support es8
|
|
Reference in New Issue
Block a user