feat: add es version 6 support

This commit is contained in:
loveuer
2024-05-08 23:14:06 +08:00
parent 2bac049856
commit 63b9abbc76
8 changed files with 420 additions and 11 deletions

View File

@ -19,6 +19,10 @@ 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=http://127.0.0.1:9200/some_index --i-version 6 --output=./data.json
esgo2dump --output=http://127.0.0.1:9200/some_index --o-version 6 --input=./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 --source='id;name;age;address' --output=./data.json
@ -38,6 +42,8 @@ esgo2dump --input=http://127.0.0.1:9200/some_index --output=./data.json --query_
f_query_file string
f_version bool
es_iversion, es_oversion string
)
func init() {
@ -47,6 +53,8 @@ func init() {
rootCommand.Flags().StringVarP(&f_input, "input", "i", "", "*required: input file or es url (example :data.json / http://127.0.0.1:9200/my_index)")
rootCommand.Flags().StringVarP(&f_output, "output", "o", "output.json", "")
rootCommand.Flags().StringVar(&es_iversion, "i-version", "7", "input(es) version")
rootCommand.Flags().StringVar(&es_oversion, "o-version", "7", "output(es) version")
rootCommand.Flags().StringVarP(&f_type, "type", "t", "data", "data/mapping/setting")
rootCommand.Flags().StringVarP(&f_source, "source", "s", "", "query source, use ';' to separate")
rootCommand.Flags().StringVarP(&f_query, "query", "q", "", `query dsl, example: {"bool":{"must":[{"term":{"name":{"value":"some_name"}}}],"must_not":[{"range":{"age":{"gte":18,"lt":60}}}]}}`)

View File

@ -4,6 +4,7 @@ import (
"bufio"
"context"
"encoding/json"
"errors"
"fmt"
"net/url"
"os"
@ -50,6 +51,8 @@ func run(cmd *cobra.Command, args []string) error {
if opt.Debug {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetReportCaller(true)
logrus.SetFormatter(&logrus.TextFormatter{})
}
if f_version {
@ -61,11 +64,11 @@ func run(cmd *cobra.Command, args []string) error {
return err
}
if ioi, err = newIO(f_input, interfaces.IOInput); err != nil {
if ioi, err = newIO(f_input, interfaces.IOInput, es_iversion); err != nil {
return err
}
if ioo, err = newIO(f_output, interfaces.IOOutput); err != nil {
if ioo, err = newIO(f_output, interfaces.IOOutput, es_oversion); err != nil {
return err
}
@ -260,7 +263,7 @@ func executeData(ctx context.Context, input, output interfaces.DumpIO) error {
}
}
func newIO(source string, ioType interfaces.IO) (interfaces.DumpIO, error) {
func newIO(source string, ioType interfaces.IO, esv string) (interfaces.DumpIO, error) {
var (
err error
iurl *url.URL
@ -292,9 +295,18 @@ 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 version=%s", ioType.Code(), *iurl, esv)
return xes.NewClient(iurl, ioType)
switch esv {
case "7":
return xes.NewClient(iurl, ioType)
case "6":
return xes.NewClientV6(iurl, ioType)
case "8":
return nil, errors.New("es version 8 comming soon")
default:
return nil, fmt.Errorf("unknown es version=%s", esv)
}
ClientByFile:
if ioType == interfaces.IOOutput {