Skip to content

Commit

Permalink
Merge pull request #2 from zethuman/feature/source
Browse files Browse the repository at this point in the history
Feature/source
  • Loading branch information
zethuman authored Apr 6, 2023
2 parents 8f127f0 + a751958 commit a110373
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 61 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Adds `Err()` function to Response for detailed errors ([#246](https://github.com/opensearch-project/opensearch-go/pull/246))
- Adds Point In Time API ([#253](https://github.com/opensearch-project/opensearch-go/pull/253))
- Adds InfoResp type ([#253](https://github.com/opensearch-project/opensearch-go/pull/253))
- Adds testcases to check upsert functionality ([#207](https://github.com/opensearch-project/opensearch-go/issues/207))
- Adds markdown linter ([#261](https://github.com/opensearch-project/opensearch-go/pull/261))
- Adds testcases to check upsert functionality ([#207](https://github.com/opensearch-project/opensearch-go/issues/207))
- Added @Jakob3xD to co-maintainers ([#270](https://github.com/opensearch-project/opensearch-go/pull/270))
Expand Down
18 changes: 13 additions & 5 deletions opensearchapi/api.bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ type Bulk func(body io.Reader, o ...func(*BulkRequest)) (*Response, error)
// BulkRequest configures the Bulk API request.
//
type BulkRequest struct {
Index string
Index string

Body io.Reader

Pipeline string
Refresh string
RequireAlias *bool
Routing string
Source []string
Source interface{}
SourceExcludes []string
SourceIncludes []string
Timeout time.Duration
Expand Down Expand Up @@ -116,8 +116,16 @@ func (r BulkRequest) Do(ctx context.Context, transport Transport) (*Response, er
params["routing"] = r.Routing
}

if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
if source, ok := r.Source.(bool); ok {
params["_source"] = strconv.FormatBool(source)
}

if source, ok := r.Source.(string); ok && source != "" {
params["_source"] = source
}

if sources, ok := r.Source.([]string); ok && len(sources) > 0 {
params["_source"] = strings.Join(sources, ",")
}

if len(r.SourceExcludes) > 0 {
Expand Down Expand Up @@ -249,7 +257,7 @@ func (f Bulk) WithRouting(v string) func(*BulkRequest) {

// WithSource - true or false to return the _source field or not, or default list of fields to return, can be overridden on each sub-request.
//
func (f Bulk) WithSource(v ...string) func(*BulkRequest) {
func (f Bulk) WithSource(v interface{}) func(*BulkRequest) {
return func(r *BulkRequest) {
r.Source = v
}
Expand Down
18 changes: 13 additions & 5 deletions opensearchapi/api.delete_by_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type DeleteByQuery func(index []string, body io.Reader, o ...func(*DeleteByQuery
// DeleteByQueryRequest configures the Delete By Query API request.
//
type DeleteByQueryRequest struct {
Index []string
Index []string

Body io.Reader

Expand Down Expand Up @@ -84,7 +84,7 @@ type DeleteByQueryRequest struct {
Size *int
Slices interface{}
Sort []string
Source []string
Source interface{}
SourceExcludes []string
SourceIncludes []string
Stats []string
Expand Down Expand Up @@ -219,8 +219,16 @@ func (r DeleteByQueryRequest) Do(ctx context.Context, transport Transport) (*Res
params["sort"] = strings.Join(r.Sort, ",")
}

if len(r.Source) > 0 {
params["_source"] = strings.Join(r.Source, ",")
if source, ok := r.Source.(bool); ok {
params["_source"] = strconv.FormatBool(source)
}

if source, ok := r.Source.(string); ok && source != "" {
params["_source"] = source
}

if sources, ok := r.Source.([]string); ok && len(sources) > 0 {
params["_source"] = strings.Join(sources, ",")
}

if len(r.SourceExcludes) > 0 {
Expand Down Expand Up @@ -520,7 +528,7 @@ func (f DeleteByQuery) WithSort(v ...string) func(*DeleteByQueryRequest) {

// WithSource - true or false to return the _source field or not, or a list of fields to return.
//
func (f DeleteByQuery) WithSource(v ...string) func(*DeleteByQueryRequest) {
func (f DeleteByQuery) WithSource(v interface{}) func(*DeleteByQueryRequest) {
return func(r *DeleteByQueryRequest) {
r.Source = v
}
Expand Down
Loading

0 comments on commit a110373

Please sign in to comment.