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

[BUG] Unnecessary error message when trying to modify an index, even when it succeeds #232

Open
gyaneshgupta96 opened this issue Jan 29, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@gyaneshgupta96
Copy link

gyaneshgupta96 commented Jan 29, 2025

What is the bug?

Index modified successfully using terraform, but still error shows up.

Error: There are documents in the index (or the index could not be , set force_destroy to true to allow destroying.`

How can one reproduce the bug?

If I create an index lets say something like this:

resource "opensearch_index" "sample_index" {
    name               = "sample_index"
    number_of_shards   = "3"
    number_of_replicas = "3"
    refresh_interval   = "-1"
   mappings = jsonencode(
        {
       "properties:{
       "department_id" : {
          "type" : "keyword"
        },
        "document" : {
          "type" : "keyword"
        },
        "text" : {
          "type" : "keyword"
        },
     }
}

If I modify such that

resource "opensearch_index" "sample_index" {
    name               = "sample_index"
    number_of_shards   = "3"
    number_of_replicas = "3"
    refresh_interval   = "-1"
   mappings = jsonencode(
        {
       "properties:{
       "department_id" : {
          "type" : "keyword"
        },
       "department_name" : {
          "type" : "keyword"
        },
        "document" : {
          "type" : "keyword"
        },
        "text" : {
          "type" : "keyword"
        },
     }
}

I see this error coming up.

However, if you do get index?settings, the field department_name gets added. Worst, this error persists.

What is the expected behavior?

The error should not persist. The only way to get rid of the error is by deleting the index, which is unacceptable in production environment. Either it should not make the change (throwing an error) and then reverting the terraform config should fix things. Or make the change and be done with it.

What is your host/environment?

macos, latest version of the provider.

@prudhvigodithi
Copy link
Member

[Triage]
Adding @rblcoder to please provide some details.
Thanks

@rblcoder
Copy link
Collaborator

rblcoder commented Feb 1, 2025

Static settings such as mapping to be only be defined at the index creation time.
https://aws.amazon.com/blogs/big-data/patterns-for-updating-amazon-opensearch-service-index-settings-and-mappings/

@gyaneshgupta96
Copy link
Author

gyaneshgupta96 commented Feb 5, 2025

A followup question? What is the best way then to allow for dynamic mappings and ensure the index state doesn't create an issue? I want to be able to change mappings or atleast have a dynamic mapping. It should not delete the index based on the state.

@rblcoder
Copy link
Collaborator

rblcoder commented Feb 7, 2025

From the documentation -
https://registry.terraform.io/providers/opensearch-project/opensearch/latest/docs/resources/index

mappings (String) A JSON string defining how documents in the index, and the fields they contain, are stored and indexed. To avoid the complexities of field mapping updates, updates of this field are not allowed via this provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants