From e349780304a5b226ee2b83198cf40778c2720afe Mon Sep 17 00:00:00 2001 From: emcgee-work <124061343+emcgee-work@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:09:40 +0100 Subject: [PATCH] ENDPOINT-11006-Hunt-label-counter (#144) Fix counter when a tag label is selected while creating a hunt --- services/indexing/indexing.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/services/indexing/indexing.go b/services/indexing/indexing.go index fa4880a..3d832b3 100644 --- a/services/indexing/indexing.go +++ b/services/indexing/indexing.go @@ -3,7 +3,6 @@ package indexing import ( "context" "errors" - "strings" "sync" cvelo_api "www.velocidex.com/golang/cloudvelo/schema/api" @@ -71,6 +70,22 @@ func (self Indexer) getIndexRecords( } } +const searchlabel = ` +{"sort": [{ + "client_id": {"order": "asc", "unmapped_type": "keyword"} + }], + "query": { + "bool": { + "must": [ + %s, {"match": { + "doc_type": "clients" + }}] + } +} +,"_source":{"includes":["client_id"]} +} +` + // Search the index for clients matching the term func (self Indexer) SearchIndexWithPrefix( ctx context.Context, @@ -97,10 +112,9 @@ func (self Indexer) SearchIndexWithPrefix( return case "label": - terms := []string{json.Format(fieldSearchQuery, "labels", term)} + terms := json.Format(fieldSearchQuery, "labels", term) query := json.Format( - getAllClientsQuery, strings.Join(terms, ","), - `,{"_source":{"includes":["client_id"]}}`) + searchlabel, terms) self.getIndexRecords(ctx, config_obj, query, output_chan) return