Skip to content

Commit

Permalink
Fix copy count
Browse files Browse the repository at this point in the history
  • Loading branch information
rerost committed Nov 11, 2018
1 parent 43abde9 commit 39ab753
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 5 additions & 0 deletions executer/executer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func (e *executerImp) Run(ctx context.Context, operation string, target string,
fmt.Fprintf(os.Stdout, "Done copy")

return Empty{}, nil
case "count":
if len(args) != 1 {
return Empty{}, fail.New(fmt.Sprintf("Invalid arguments expected: %d, %v", 1, args))
}
return e.esBaseClient.CountIndex(ctx, args[0])
}
}

Expand Down
11 changes: 3 additions & 8 deletions infra/es/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strconv"
"strings"

"github.com/rerost/es-cli/setting"
Expand Down Expand Up @@ -316,15 +315,11 @@ func (client baseClientImp) CountIndex(ctx context.Context, indexName string) (C
return Count{}, fail.New(fmt.Sprintf("%v", errMsg))
}

if _, ok := responseMap["count"].(string); !ok {
if _, ok := responseMap["count"].(float64); !ok {
return Count{}, fail.New(fmt.Sprintf("Failed to extract count from json: %s", responseBody))
}

countNum, err := strconv.ParseInt(responseMap["count"].(string), 10, 64)
if err != nil {
return Count{}, fail.Wrap(err)
}
return Count{Num: countNum}, nil
return Count{Num: int64(responseMap["count"].(float64))}, nil
}

// Mapping
Expand Down Expand Up @@ -634,7 +629,7 @@ func (client baseClientImp) aliasURL() string {
return client.baseURL() + "/_aliases"
}
func (client baseClientImp) countURL(indexName string) string {
return client.indexURL(indexName) + "/count"
return client.indexURL(indexName) + "/_count"
}

func addParams(req *http.Request, params map[string]string) *http.Request {
Expand Down

0 comments on commit 39ab753

Please sign in to comment.