Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dpluger can not check keyword on es6 #392

Merged
merged 6 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
log cleanup
  • Loading branch information
rkspx committed Mar 15, 2022
commit 5d25615d895a8047c4fafdf10ba21b6fbf228227
24 changes: 13 additions & 11 deletions internal/pkg/dpluger/es6client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ func (es *es6Client) CollectPair(plugin Plugin, confFile, sidSource, esFilter, t

query := elastic6.NewBoolQuery()
if esFilter != "" {
coll := strings.Split(esFilter, ";")
for _, v := range coll {
s := strings.Split(v, "=")
filters := strings.Split(esFilter, ";")
for _, filter := range filters {
s := strings.Split(filter, "=")
if len(s) != 2 {
err = errors.New("Cannot split the ES filter term")
return
return tsvRef{}, fmt.Errorf("invalid ES filter term, '%s', expected pair of strings with '=' delimitier", filter)
}
query = query.Must(elastic6.NewTermQuery(s[0], s[1]))
}
Expand All @@ -72,6 +71,7 @@ func (es *es6Client) CollectPair(plugin Plugin, confFile, sidSource, esFilter, t
if err != nil {
return
}

agg, found := searchResult.Aggregations.Terms("finalAgg")
if !found {
err = errors.New("cannot find aggregation finalAgg in ES query result")
Expand All @@ -82,7 +82,8 @@ func (es *es6Client) CollectPair(plugin Plugin, confFile, sidSource, esFilter, t
err = errors.New("cannot find matching entry in field " + sidSource + " on index " + plugin.Index)
return
}
fmt.Println("Found", count, "uniq "+sidSource+".")

fmt.Printf("found %d unique '%s'", count, sidSource)
nID, err := strconv.Atoi(plugin.Fields.PluginID)
if err != nil {
return
Expand Down Expand Up @@ -132,12 +133,11 @@ func (es *es6Client) Collect(plugin Plugin, confFile, sidSource, esFilter, categ

query := elastic6.NewBoolQuery()
if esFilter != "" {
coll := strings.Split(esFilter, ";")
for _, v := range coll {
s := strings.Split(v, "=")
filters := strings.Split(esFilter, ";")
for _, filter := range filters {
s := strings.Split(filter, "=")
if len(s) != 2 {
err = errors.New("Cannot split the ES filter term")
return
return tsvRef{}, fmt.Errorf("invalid ES filter term, '%s', expected pair of strings with '=' delimitier", filter)
}
query = query.Must(elastic6.NewTermQuery(s[0], s[1]))
}
Expand All @@ -152,9 +152,11 @@ func (es *es6Client) Collect(plugin Plugin, confFile, sidSource, esFilter, categ
Aggregation("uniqTerm", terms).
Pretty(true).
Do(ctx)

if err != nil {
return
}

agg, found := searchResult.Aggregations.Terms("uniqTerm")
if !found {
err = errors.New("cannot find aggregation uniqTerm in ES query result")
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/dpluger/tsvref.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ func (c *tsvRef) initWithConfig(configFile string) {
func (c *tsvRef) init(pluginName string, configFile string) {
c.SIDs = make(map[int]PluginSID)
c.setFilename(pluginName, path.Dir(configFile))
// f, err := os.OpenFile(c.filename, os.O_RDONLY, 0600)
f, err := os.OpenFile(c.filename, os.O_RDONLY, 0600)
if err != nil {
return
Expand Down