Skip to content

Commit 2bfc864

Browse files
committed
fix: request logs at index level
1 parent d4dacc7 commit 2bfc864

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

plugins/logs/dao.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ func (es *elasticsearch) getRawLogs(ctx context.Context, from, size, filter stri
112112
} else {
113113
query.Filter(elastic.NewMatchAllQuery())
114114
}
115+
116+
if indices != nil && len(indices) > 0 {
117+
var indexQueries []elastic.Query
118+
for _, index := range indices {
119+
query := elastic.NewTermQuery("indices.keyword", index)
120+
indexQueries = append(indexQueries, query)
121+
}
122+
query = query.Must(indexQueries...)
123+
}
124+
115125
response, err := es.client.Search(es.indexName).
116126
Query(query).
117127
From(offset).
@@ -129,21 +139,7 @@ func (es *elasticsearch) getRawLogs(ctx context.Context, from, size, filter stri
129139
if err != nil {
130140
return nil, err
131141
}
132-
rawIndices, ok := source["indices"]
133-
if !ok {
134-
log.Printf(`%s: unable to find "indices" in log record\n`, logTag)
135-
}
136-
logIndices, err := util.ToStringSlice(rawIndices)
137-
if err != nil {
138-
log.Printf("%s: %v\n", logTag, err)
139-
continue
140-
}
141-
142-
if len(indices) == 0 {
143-
hits = append(hits, hit.Source)
144-
} else if util.IsSubset(indices, logIndices) {
145-
hits = append(hits, hit.Source)
146-
}
142+
hits = append(hits, hit.Source)
147143
}
148144

149145
logs := make(map[string]interface{})
@@ -155,6 +151,5 @@ func (es *elasticsearch) getRawLogs(ctx context.Context, from, size, filter stri
155151
if err != nil {
156152
return nil, err
157153
}
158-
159154
return raw, nil
160155
}

0 commit comments

Comments
 (0)