Skip to content

Commit

Permalink
Fix Indices API to reflect current API
Browse files Browse the repository at this point in the history
This commit fixes several Indices-related APIs to reflect the current
state of the API.
  • Loading branch information
olivere committed Aug 30, 2021
1 parent 4fa5c50 commit a5767e3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 27 deletions.
20 changes: 15 additions & 5 deletions indices_create.go
Expand Up @@ -28,11 +28,12 @@ type IndicesCreateService struct {
filterPath []string // list of filters used to reduce the response
headers http.Header // custom request-level HTTP headers

index string
timeout string
masterTimeout string
bodyJson interface{}
bodyString string
index string
timeout string
masterTimeout string
includeTypeName *bool
bodyJson interface{}
bodyString string
}

// NewIndicesCreateService returns a new IndicesCreateService.
Expand Down Expand Up @@ -98,6 +99,12 @@ func (s *IndicesCreateService) MasterTimeout(masterTimeout string) *IndicesCreat
return s
}

// IncludeTypeName indicates whether a type should be expected in the body of the mappings.
func (s *IndicesCreateService) IncludeTypeName(includeTypeName bool) *IndicesCreateService {
s.includeTypeName = &includeTypeName
return s
}

// Body specifies the configuration of the index as a string.
// It is an alias for BodyString.
func (s *IndicesCreateService) Body(body string) *IndicesCreateService {
Expand Down Expand Up @@ -151,6 +158,9 @@ func (s *IndicesCreateService) Do(ctx context.Context) (*IndicesCreateResult, er
if s.timeout != "" {
params.Set("timeout", s.timeout)
}
if v := s.includeTypeName; v != nil {
params.Set("include_type_name", fmt.Sprint(*v))
}

// Setup HTTP request body
var body interface{}
Expand Down
27 changes: 18 additions & 9 deletions indices_put_mapping.go
Expand Up @@ -33,7 +33,8 @@ type IndicesPutMappingService struct {
ignoreUnavailable *bool
allowNoIndices *bool
expandWildcards string
updateAllTypes *bool
includeTypeName *bool
writeIndexOnly *bool
timeout string
bodyJson map[string]interface{}
bodyString string
Expand Down Expand Up @@ -134,10 +135,15 @@ func (s *IndicesPutMappingService) ExpandWildcards(expandWildcards string) *Indi
return s
}

// UpdateAllTypes, if true, indicates that all fields that span multiple indices
// should be updated (default: false).
func (s *IndicesPutMappingService) UpdateAllTypes(updateAllTypes bool) *IndicesPutMappingService {
s.updateAllTypes = &updateAllTypes
// IncludeTypeName indicates whether a type should be expected in the body of the mappings.
func (s *IndicesPutMappingService) IncludeTypeName(includeTypeName bool) *IndicesPutMappingService {
s.includeTypeName = &includeTypeName
return s
}

// WriteIndexOnly, when true, applies mappings only to the write index of an alias or data stream.
func (s *IndicesPutMappingService) WriteIndexOnly(writeIndexOnly bool) *IndicesPutMappingService {
s.writeIndexOnly = &writeIndexOnly
return s
}

Expand Down Expand Up @@ -177,16 +183,19 @@ func (s *IndicesPutMappingService) buildURL() (string, url.Values, error) {
params.Set("filter_path", strings.Join(s.filterPath, ","))
}
if s.ignoreUnavailable != nil {
params.Set("ignore_unavailable", fmt.Sprintf("%v", *s.ignoreUnavailable))
params.Set("ignore_unavailable", fmt.Sprint(*s.ignoreUnavailable))
}
if s.allowNoIndices != nil {
params.Set("allow_no_indices", fmt.Sprintf("%v", *s.allowNoIndices))
params.Set("allow_no_indices", fmt.Sprint(*s.allowNoIndices))
}
if s.expandWildcards != "" {
params.Set("expand_wildcards", s.expandWildcards)
}
if s.updateAllTypes != nil {
params.Set("update_all_types", fmt.Sprintf("%v", *s.updateAllTypes))
if s.includeTypeName != nil {
params.Set("include_type_name", fmt.Sprint(*s.includeTypeName))
}
if s.writeIndexOnly != nil {
params.Set("write_index_only", fmt.Sprint(*s.writeIndexOnly))
}
if s.timeout != "" {
params.Set("timeout", s.timeout)
Expand Down
36 changes: 23 additions & 13 deletions indices_put_template.go
Expand Up @@ -31,16 +31,17 @@ type IndicesPutTemplateService struct {
filterPath []string // list of filters used to reduce the response
headers http.Header // custom request-level HTTP headers

name string
cause string
order interface{}
version *int
create *bool
timeout string
masterTimeout string
flatSettings *bool
bodyJson interface{}
bodyString string
name string
cause string
order interface{}
version *int
create *bool
timeout string
masterTimeout string
flatSettings *bool
includeTypeName *bool
bodyJson interface{}
bodyString string
}

// NewIndicesPutTemplateService creates a new IndicesPutTemplateService.
Expand Down Expand Up @@ -115,6 +116,12 @@ func (s *IndicesPutTemplateService) MasterTimeout(masterTimeout string) *Indices
return s
}

// IncludeTypeName indicates whether a type should be expected in the body of the mappings.
func (s *IndicesPutTemplateService) IncludeTypeName(includeTypeName bool) *IndicesPutTemplateService {
s.includeTypeName = &includeTypeName
return s
}

// FlatSettings indicates whether to return settings in flat format (default: false).
func (s *IndicesPutTemplateService) FlatSettings(flatSettings bool) *IndicesPutTemplateService {
s.flatSettings = &flatSettings
Expand Down Expand Up @@ -181,10 +188,10 @@ func (s *IndicesPutTemplateService) buildURL() (string, url.Values, error) {
params.Set("order", fmt.Sprintf("%v", s.order))
}
if s.version != nil {
params.Set("version", fmt.Sprintf("%v", *s.version))
params.Set("version", fmt.Sprint(*s.version))
}
if s.create != nil {
params.Set("create", fmt.Sprintf("%v", *s.create))
params.Set("create", fmt.Sprint(*s.create))
}
if s.cause != "" {
params.Set("cause", s.cause)
Expand All @@ -196,7 +203,10 @@ func (s *IndicesPutTemplateService) buildURL() (string, url.Values, error) {
params.Set("master_timeout", s.masterTimeout)
}
if s.flatSettings != nil {
params.Set("flat_settings", fmt.Sprintf("%v", *s.flatSettings))
params.Set("flat_settings", fmt.Sprint(*s.flatSettings))
}
if s.includeTypeName != nil {
params.Set("include_type_name", fmt.Sprint(*s.includeTypeName))
}
return path, params, nil
}
Expand Down

1 comment on commit a5767e3

@aniketp
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olivere It looks like IndicesGetMappingService struct also needs includeTypeName field here.

Please sign in to comment.