Skip to content

Commit

Permalink
Fix discovery search result
Browse files Browse the repository at this point in the history
Fix aggregation filter(left side menu filter) matches, added minimum match criteria to match exact string match for search result.
  • Loading branch information
vicpatel committed Feb 13, 2023
1 parent 4a3001b commit e2c374c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion extra/server-discovery/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ services:
expose:
- "5601"
environment:
OPENSEARCH_HOSTS: '["http://project_name-opensearch:9200","http://project_name-opensearch-node2:9200"]'
OPENSEARCH_HOSTS: '["http://127.0.0.1:9200"]'
DISABLE_SECURITY_DASHBOARDS_PLUGIN: 'true' # disables security dashboards plugin in OpenSearch Dashboards

networks:
Expand Down
14 changes: 8 additions & 6 deletions extra/server-discovery/searcher/rest/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func conv(sr *esSearchResponse, aggregation *esSearchResponse, noHits bool, modu
if aggregation != nil {
aggsRes = aggregation.Aggregations
}
//for _, bucket := range aggsRes.Resource.Buckets {
// for _, bucket := range aggsRes.Resource.Buckets {
// bucketName := getResourceName(bucket.Key)
// if bucketName == "User" {
// continue
Expand Down Expand Up @@ -152,7 +152,7 @@ func conv(sr *esSearchResponse, aggregation *esSearchResponse, noHits bool, modu
// }
// }
// }
//}
// }

nsAggregation := cdAggregation{
Name: "Namespace",
Expand All @@ -171,10 +171,12 @@ func conv(sr *esSearchResponse, aggregation *esSearchResponse, noHits bool, modu
if nsHandleMap != nil {
name = nsHandleMap[resourceName].Name
}
nsTotalHits[resourceName] = cdAggregationHits{
Name: name,
Label: resourceName,
Hits: bucket.DocCount,
if len(name) > 0 {
nsTotalHits[resourceName] = cdAggregationHits{
Name: name,
Label: resourceName,
Hits: bucket.DocCount,
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion extra/server-discovery/searcher/rest/es.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/elastic/go-elasticsearch/v7"
"github.com/elastic/go-elasticsearch/v7/esapi"
"github.com/go-chi/jwtauth"
Expand Down Expand Up @@ -57,7 +58,8 @@ type (
Query string `json:"query"`
Type string `json:"type"`
// Operator string `json:"operator"`
Fields []string `json:"fields"`
Fields []string `json:"fields"`
MinimumShouldMatch string `json:"minimum_should_match"`
} `json:"multi_match"`
}

Expand Down Expand Up @@ -288,6 +290,7 @@ func esSearch(ctx context.Context, log *zap.Logger, esc *elasticsearch.Client, p
for _, mAggs := range p.moduleAggs {
mm.Wrap.Query = mAggs
mm.Wrap.Type = "cross_fields"
mm.Wrap.MinimumShouldMatch = "100%"
mm.Wrap.Fields = []string{"module.name"}
// query.Query.Bool.Must = append(query.Query.Bool.Must, mm)
// query.Query.DisMax.Queries = append(query.Query.DisMax.Queries, mm)
Expand All @@ -307,6 +310,7 @@ func esSearch(ctx context.Context, log *zap.Logger, esc *elasticsearch.Client, p
for _, nAggs := range p.namespaceAggs {
mm.Wrap.Query = nAggs
mm.Wrap.Type = "cross_fields"
mm.Wrap.MinimumShouldMatch = "100%"
mm.Wrap.Fields = []string{"namespace.name"}
// query.Query.Bool.Must = append(query.Query.Bool.Must, mm)
// query.Query.DisMax.Queries = append(query.Query.DisMax.Queries, mm)
Expand Down Expand Up @@ -405,10 +409,12 @@ func esSearch(ctx context.Context, log *zap.Logger, esc *elasticsearch.Client, p
// query.Aggregations = (Aggregations{}).encodeTerms(p.aggregations)
// }

// spew.Dump("query: ", query)
if err = json.NewEncoder(&buf).Encode(query); err != nil {
err = fmt.Errorf("could not encode query: %q", err)
return
}
spew.Dump("buf: ", buf)

log.Debug("searching ",
zap.String("for", p.title),
Expand Down

0 comments on commit e2c374c

Please sign in to comment.