Skip to content

Commit

Permalink
Fix total records response (#113)
Browse files Browse the repository at this point in the history
* Fix total records response

* error handling

* change var name to be more readable
  • Loading branch information
kaplanelad authored Jul 26, 2020
1 parent 7882a97 commit 2c3dc9e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion api/storage/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,21 @@ func (sm *StorageManager) GetResources(resourceType string, executionID string,
ResourceNameQ := elastic.NewMatchQuery("ResourceName", resourceType)
generalQ := elastic.NewBoolQuery()
generalQ = generalQ.Must(componentQ).Must(deploymentQ).Must(ResourceNameQ).Must(dynamicMatchQuery...)
searchResultTotalHits, err := sm.client.Search().
Query(generalQ).
Pretty(true).
Size(0).
Do(context.Background())

if err != nil {
log.WithError(err).Error("elasticsearch query error")
return resources, err
}

searchResult, err := sm.client.Search().
Query(generalQ).
Pretty(true).
Size(100).
Size(int(searchResultTotalHits.TotalHits())).
Do(context.Background())

if err != nil {
Expand Down

0 comments on commit 2c3dc9e

Please # to comment.