Description
What is the bug?
Creating an index
resource with only mappings
and analysis_analyzer
fails with 400 saying analyzers are not defined.
After a lot of debugging and looking through the source, I noticed that the analysis
field does not get sent over the API unless there's at least one more setting passed.
The code that filters this out is here:
terraform-provider-opensearch/provider/resource_opensearch_index.go
Lines 449 to 451 in 59aec32
For a simpler repro, you can just create an index with just analysis_analyzer
. It'll pass, but the index will have no settings
As a workaround, adding any other setting like number_of_replicas = "0"
fixes it
How can one reproduce the bug?
This resource block should work:
resource "opensearch_index" "test_index" {
name = "test-index"
mappings = jsonencode({
"properties": {
"name": {
"type": "text",
"search_analyzer": "name_search_analyzer"
}
}
})
analysis_analyzer = jsonencode({
name_search_analyzer = {
type = "custom"
tokenizer = "standard"
filter = ["lowercase"]
}
})
}
Currently, this errors:
opensearch_index.test-index: Creating...
╷
│ Error: elastic: Error 400 (Bad Request): OpenSearch exception [type=illegal_argument_exception, reason=analyzer [name_search_analyzer] has not been configured in mappings]- server : [envoy] [type=illegal_argument_exception]
│
│ with opensearch_index.test-index,
│ on init.tf line 117, in resource "opensearch_index" "test-index":
│ 117: resource "opensearch_index" "test-index" {
│
What is the expected behavior?
It creates an index with the appropriate settings/mappings
What is your host/environment?
macOS Sequoia 15.3
Do you have any screenshots?
If applicable, add screenshots to help explain your problem.
Do you have any additional context?
Going through the code a bit, I'm 99% sure it's this statement here:
terraform-provider-opensearch/provider/resource_opensearch_index.go
Lines 449 to 451 in 59aec32
If there's no settings in the keys defined above, the settings
block just doesn't get attached to the body, so it doesn't get sent. After I added a setting in that list, it worked