Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for index creation query params #244

Merged
merged 6 commits into from
Jan 16, 2023

Conversation

k-yomo
Copy link
Contributor

@k-yomo k-yomo commented Jan 13, 2023

Resolve #242

This PR adds support for the following query params that we can set for index creation.

📝 master_timeout and timeout are used in the other apis, so it might be better to make it reusable.
https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-put-lifecycle.html#ilm-put-lifecycle-query-params

@k-yomo k-yomo force-pushed the support-index-query-params branch from 518b9b2 to dae0688 Compare January 13, 2023 17:01
@k-yomo k-yomo force-pushed the support-index-query-params branch from dae0688 to 34f654b Compare January 13, 2023 17:05
@k-yomo k-yomo marked this pull request as ready for review January 13, 2023 17:09
Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

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

Nice, couple of minor comments

@@ -208,15 +210,33 @@ func DeleteIndexTemplate(ctx context.Context, apiClient *clients.ApiClient, temp
return diags
}

func PutIndex(ctx context.Context, apiClient *clients.ApiClient, index *models.Index) diag.Diagnostics {
var includeTypeNameUnsupportedVersion = version.Must(version.NewVersion("8.0.0"))
Copy link
Member

Choose a reason for hiding this comment

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

nit: IMO it would be nice to include if this is an upper or lower bound in the name.

Suggested change
var includeTypeNameUnsupportedVersion = version.Must(version.NewVersion("8.0.0"))
var includeTypeNameMinUnsupportedVersion = version.Must(version.NewVersion("8.0.0"))

if diags := elasticsearch.PutIndex(ctx, client, &index); diags.HasError() {
params := models.PutIndexParams{
WaitForActiveShards: d.Get("wait_for_active_shards").(string),
IncludeTypeName: d.Get("include_type_name").(bool),
Copy link
Member

Choose a reason for hiding this comment

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

I think we should throw an error if include_type_name = true when running against an 8.x server. IMO it avoids potential confusion for users.

Personally, I would probably do all the version checking in here, switch the IncludeTypeName struct property to a pointer and then set it in the create request if it's not nil in the params but I don't feel strongly about it.

Copy link
Contributor Author

@k-yomo k-yomo Jan 16, 2023

Choose a reason for hiding this comment

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

Fixed to return error when the version is unsupported!

Personally, I would probably do all the version checking in here, switch the IncludeTypeName struct property to a pointer and then set it in the create request if it's not nil in the params but I don't feel strongly about it.

Agreed, moved the logic here. We don't have a way to know if the value is zero value (false) or not set , I simply make it evaluate and set when include_type_name = true.

@@ -519,6 +520,32 @@ If specified, this mapping can include: field names, [field data types](https://
Type: schema.TypeString,
Computed: true,
},
"include_type_name": {
Type: schema.TypeBool,
Description: "If true, a mapping type is expected in the body of mappings. Defaults to false.",
Copy link
Member

Choose a reason for hiding this comment

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

We should detail the version constraint here

Suggested change
Description: "If true, a mapping type is expected in the body of mappings. Defaults to false.",
Description: "If true, a mapping type is expected in the body of mappings. Defaults to false. Supported for Elasticsearch 7.x",

@k-yomo k-yomo requested a review from tobio January 16, 2023 09:44
Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@tobio tobio merged commit 0693d49 into elastic:main Jan 16, 2023
@k-yomo k-yomo deleted the support-index-query-params branch January 16, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Support index creation query parameters
2 participants