Skip to content

Commit

Permalink
Merge pull request #25 from toughnoah/qa
Browse files Browse the repository at this point in the history
add template msearch bulk
  • Loading branch information
toughnoah authored Jul 10, 2021
2 parents e9983c3 + 98fcd31 commit 94bfc5a
Show file tree
Hide file tree
Showing 25 changed files with 775 additions and 71 deletions.
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ The blackbean is a command tool for elasticsearch operations by using cobra. Bes
* 5.10. [User](#User)
* 5.11. [Role](#Role)
* 5.12. [Explain](#Explain)
* 5.13. [Watcher](#Watcher)
* 5.13. [Template](#Template)
* 5.14. [Watcher](#Watcher)
* 6. [Contact Me](#ContactMe)

<!-- vscode-markdown-toc-config
Expand Down Expand Up @@ -243,14 +244,29 @@ Usage:
blackbean index [command]

Available Commands:
bulk send bulk request
create create index from command
delete delete index from command
get get index from cluster
msearch send msearch request
reindex do reindex
search search index from cluster

write write index from command
...
```
```console
[root@noah ~]# blackbean index msearch -h
send msearch request ... wordless

Usage:
blackbean index msearch [flags]

Flags:
-d, --data string the path to raw file with request body (default "{}")
-h, --help help for msearch
--max_concurrent_searches int ID of the pipeline to use to preprocess incoming documents.
--max_concurrent_shard_requests int if true, the request’s actions must target an index alias.
--raw_file string the path to raw file with request body
```
```console
[root@noah ~]# blackbean index search test-* -f query.json
Expand Down Expand Up @@ -362,7 +378,22 @@ Flags:
...
```

### 5.13. <a name='Watcher'></a>Watcher
### 5.13. <a name='Template'></a>Template
```console
[root@noah ~]# blackbean template
template operations ... wordless

Usage:
blackbean template [command]

Available Commands:
apply create or update template
delete delete or update template
get get template
...
```

### 5.14. <a name='Watcher'></a>Watcher
```console
[root@noah ~]# blackbean watcher
operate watcherr ... wordless
Expand Down
8 changes: 5 additions & 3 deletions cmd/ailas.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func createAlias(cli *elasticsearch.Client, out io.Writer) *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
res, err := a.createAlias(args[0], args[1], req)
fmt.Fprintf(out, "%s\n", res)
fmt.Fprintln(out, res)
return err
},
}
Expand All @@ -60,6 +60,7 @@ func getAlias(cli *elasticsearch.Client, out io.Writer) *cobra.Command {
Use: "get [index/alias]",
Short: "get alias for index or get alias list",
Long: "get alias for index or get alias list",
Args: cobra.ExactArgs(1),
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
Expand All @@ -70,7 +71,7 @@ func getAlias(cli *elasticsearch.Client, out io.Writer) *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
res, err := a.getAlias(args[0], isAlias)
fmt.Fprintf(out, "%s\n", res)
fmt.Fprintln(out, res)
return err
},
}
Expand All @@ -97,7 +98,7 @@ func deleteAlias(cli *elasticsearch.Client, out io.Writer) *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
res, err := a.deleteAlias(args[0], args[1])
fmt.Fprintf(out, "%s\n", res)
fmt.Fprintln(out, res)
return err
},
}
Expand All @@ -112,6 +113,7 @@ type Alias struct {
func (a *Alias) createAlias(indices, alias string, req *es.RequestBody) (res *esapi.Response, err error) {
body, err := es.GetRawRequestBody(req)
if err != nil {
log.Println("failed to get raw request body")
return nil, err
}
return a.client.Indices.PutAlias(splitWords(indices), alias, a.client.Indices.PutAlias.WithBody(bytes.NewReader(body)))
Expand Down
6 changes: 3 additions & 3 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func applySettings(cli *elasticsearch.Client, out io.Writer, osArgs []string) *c
o := applyObject{Client: cli}
res, err := o.putSettings(req)
if err == nil {
fmt.Fprintf(out, "%s\n", res)
fmt.Fprintln(out, res)
}
return err
},
Expand Down Expand Up @@ -100,7 +100,7 @@ func applyFlushed(cli *elasticsearch.Client, out io.Writer) *cobra.Command {
o := applyObject{Client: cli}
res, err := o.flush()
if err == nil {
fmt.Fprintf(out, "%s\n", res)
fmt.Fprintln(out, res)
}
return err
},
Expand All @@ -121,7 +121,7 @@ func applyClearCache(cli *elasticsearch.Client, out io.Writer) *cobra.Command {
o := applyObject{Client: cli}
res, err := o.clearCache()
if err == nil {
fmt.Fprintf(out, "%s\n", res)
fmt.Fprintln(out, res)
}
return err
},
Expand Down
16 changes: 1 addition & 15 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
/*
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package cmd /*
package cmd

import (
Expand Down
24 changes: 24 additions & 0 deletions cmd/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,30 @@ func TestCompletion2(t *testing.T) {
ResponseString: `{"nodes":{"A": {"name":"elasticsearch-master-0"}}}`,
},
},
{
name: "test template completion",
cmd: "__complete template get ''",
checkOut: "A",
mock: &fake.MockEsResponse{
ResponseString: `{"A":{}}`,
},
},
{
name: "test template completion",
cmd: "__complete template delete ''",
checkOut: "A",
mock: &fake.MockEsResponse{
ResponseString: `{"A":{}}`,
},
},
{
name: "test template completion",
cmd: "__complete template apply ''",
checkOut: "A",
mock: &fake.MockEsResponse{
ResponseString: `{"A":{}}`,
},
},
}
for _, tc := range testCases {
out, err := executeCommand(tc.cmd, tc.mock)
Expand Down
2 changes: 1 addition & 1 deletion cmd/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func explain(cli *elasticsearch.Client, out io.Writer, args []string) *cobra.Com
RunE: func(cmd *cobra.Command, args []string) error {
res, err := e.allocationExplain(args, shard, node, primary)
if err == nil {
fmt.Fprintf(out, "%s\n", res)
fmt.Fprintln(out, res)
}
return err
},
Expand Down
Loading

0 comments on commit 94bfc5a

Please sign in to comment.