-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: add a count for an opensearch query - without the need to get … (
#130) ## What Added a count only func which does not return any body - only the affected documents
- Loading branch information
Showing
2 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package openSearchClient | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/opensearch-project/opensearch-go/v4" | ||
"github.com/opensearch-project/opensearch-go/v4/opensearchapi" | ||
) | ||
|
||
type CountReq struct { | ||
Indices []string | ||
Body io.Reader | ||
Header http.Header | ||
Params map[string]string | ||
} | ||
|
||
// GetRequest returns the *http.Request that gets executed by the client | ||
func (r CountReq) GetRequest() (*http.Request, error) { | ||
if r.Params == nil { | ||
r.Params = make(map[string]string) | ||
} | ||
var path string | ||
if len(r.Indices) > 0 { | ||
path = fmt.Sprintf("/%s/_search", strings.Join(r.Indices, ",")) | ||
} else { | ||
path = "/_search" | ||
} | ||
|
||
return opensearch.BuildRequest( | ||
"GET", | ||
path, | ||
r.Body, | ||
r.Params, | ||
r.Header, | ||
) | ||
} | ||
|
||
type CountResp struct { | ||
Count int64 `json:"count"` | ||
Shards ShardStats `json:"_shards"` | ||
} | ||
|
||
type ShardStats struct { | ||
Total int `json:"total"` | ||
Successful int `json:"successful"` | ||
Skipped int `json:"skipped"` | ||
Failed int `json:"failed"` | ||
} | ||
|
||
func (r CountResp) Inspect() opensearchapi.Inspect { | ||
return opensearchapi.Inspect{} | ||
} |