Skip to content

Commit a404633

Browse files
committed
Add mapping_total_fields_limit
1 parent 863d7cf commit a404633

File tree

6 files changed

+274
-84
lines changed

6 files changed

+274
-84
lines changed

internal/elasticsearch/index/index/acc_test.go

Lines changed: 32 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package index_test
22

33
import (
4+
_ "embed"
45
"fmt"
56
"regexp"
67
"testing"
78

89
"github.com/elastic/terraform-provider-elasticstack/internal/acctest"
910
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
11+
"github.com/hashicorp/terraform-plugin-testing/config"
1012
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1113
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1214
"github.com/hashicorp/terraform-plugin-testing/terraform"
@@ -77,6 +79,9 @@ func TestAccResourceIndex(t *testing.T) {
7779
})
7880
}
7981

82+
//go:embed testdata/TestAccResourceIndexFromSDK/index.tf
83+
var sdkCreateTestConfig string
84+
8085
func TestAccResourceIndexFromSDK(t *testing.T) {
8186
indexName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
8287

@@ -92,7 +97,10 @@ func TestAccResourceIndexFromSDK(t *testing.T) {
9297
VersionConstraint: "0.11.3",
9398
},
9499
},
95-
Config: testAccResourceIndexSettingsCreate(indexName),
100+
Config: sdkCreateTestConfig,
101+
ConfigVariables: config.Variables{
102+
"index_name": config.StringVariable(indexName),
103+
},
96104
Check: resource.ComposeTestCheckFunc(
97105
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "name", indexName),
98106
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "number_of_shards", "2"),
@@ -132,7 +140,10 @@ func TestAccResourceIndexFromSDK(t *testing.T) {
132140
},
133141
{
134142
ProtoV6ProviderFactories: acctest.Providers,
135-
Config: testAccResourceIndexSettingsCreate(indexName),
143+
ConfigDirectory: acctest.NamedTestCaseDirectory(""),
144+
ConfigVariables: config.Variables{
145+
"index_name": config.StringVariable(indexName),
146+
},
136147
Check: resource.ComposeTestCheckFunc(
137148
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "name", indexName),
138149
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "number_of_shards", "2"),
@@ -178,12 +189,15 @@ func TestAccResourceIndexSettings(t *testing.T) {
178189
indexName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlphaNum)
179190

180191
resource.Test(t, resource.TestCase{
181-
PreCheck: func() { acctest.PreCheck(t) },
182-
CheckDestroy: checkResourceIndexDestroy,
183-
ProtoV6ProviderFactories: acctest.Providers,
192+
PreCheck: func() { acctest.PreCheck(t) },
193+
CheckDestroy: checkResourceIndexDestroy,
184194
Steps: []resource.TestStep{
185195
{
186-
Config: testAccResourceIndexSettingsCreate(indexName),
196+
ProtoV6ProviderFactories: acctest.Providers,
197+
ConfigDirectory: acctest.NamedTestCaseDirectory("create"),
198+
ConfigVariables: config.Variables{
199+
"index_name": config.StringVariable(indexName),
200+
},
187201
Check: resource.ComposeTestCheckFunc(
188202
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "name", indexName),
189203
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "number_of_shards", "2"),
@@ -194,6 +208,7 @@ func TestAccResourceIndexSettings(t *testing.T) {
194208
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "sort_field.0", "sort_key"),
195209
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "sort_order.0", "asc"),
196210
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "mapping_coerce", "true"),
211+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "mapping_total_fields_limit", "2000"),
197212
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "auto_expand_replicas", "0-5"),
198213
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "search_idle_after", "30s"),
199214
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "refresh_interval", "10s"),
@@ -221,6 +236,17 @@ func TestAccResourceIndexSettings(t *testing.T) {
221236
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "settings.0.setting.0.value", "2"),
222237
),
223238
},
239+
{
240+
ProtoV6ProviderFactories: acctest.Providers,
241+
ConfigDirectory: acctest.NamedTestCaseDirectory("update"),
242+
ConfigVariables: config.Variables{
243+
"index_name": config.StringVariable(indexName),
244+
},
245+
Check: resource.ComposeTestCheckFunc(
246+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "name", indexName),
247+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index.test_settings", "mapping_total_fields_limit", "3000"),
248+
),
249+
},
224250
},
225251
})
226252
}
@@ -348,84 +374,6 @@ resource "elasticstack_elasticsearch_index" "test" {
348374
`, name)
349375
}
350376

351-
func testAccResourceIndexSettingsCreate(name string) string {
352-
return fmt.Sprintf(`
353-
provider "elasticstack" {
354-
elasticsearch {}
355-
}
356-
357-
resource "elasticstack_elasticsearch_index" "test_settings" {
358-
name = "%s"
359-
360-
mappings = jsonencode({
361-
properties = {
362-
field1 = { type = "text" }
363-
sort_key = { type = "keyword" }
364-
}
365-
})
366-
367-
number_of_shards = 2
368-
number_of_routing_shards = 2
369-
codec = "best_compression"
370-
routing_partition_size = 1
371-
shard_check_on_startup = "false"
372-
sort_field = ["sort_key"]
373-
sort_order = ["asc"]
374-
mapping_coerce = true
375-
auto_expand_replicas = "0-5"
376-
search_idle_after = "30s"
377-
refresh_interval = "10s"
378-
max_result_window = 5000
379-
max_inner_result_window = 2000
380-
max_rescore_window = 1000
381-
max_docvalue_fields_search = 1500
382-
max_script_fields = 500
383-
max_ngram_diff = 100
384-
max_shingle_diff = 200
385-
max_refresh_listeners = 10
386-
analyze_max_token_count = 500000
387-
highlight_max_analyzed_offset = 1000
388-
max_terms_count = 10000
389-
max_regex_length = 1000
390-
query_default_field = ["field1"]
391-
routing_allocation_enable = "primaries"
392-
routing_rebalance_enable = "primaries"
393-
gc_deletes = "30s"
394-
unassigned_node_left_delayed_timeout = "5m"
395-
396-
analysis_char_filter = jsonencode({
397-
zero_width_spaces = {
398-
type = "mapping"
399-
mappings = ["\\u200C=>\\u0020"]
400-
}
401-
})
402-
analysis_filter = jsonencode({
403-
minimal_english_stemmer = {
404-
type = "stemmer"
405-
language = "minimal_english"
406-
}
407-
})
408-
analysis_analyzer = jsonencode({
409-
text_en = {
410-
type = "custom"
411-
tokenizer = "standard"
412-
char_filter = "zero_width_spaces"
413-
filter = ["lowercase", "minimal_english_stemmer"]
414-
}
415-
})
416-
417-
settings {
418-
setting {
419-
name = "number_of_replicas"
420-
value = "2"
421-
}
422-
}
423-
424-
deletion_protection = false
425-
}
426-
`, name)
427-
}
428-
429377
func testAccResourceIndexRemovingFieldCreate(name string) string {
430378
return fmt.Sprintf(`
431379
provider "elasticstack" {

internal/elasticsearch/index/index/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
"auto_expand_replicas",
3737
"refresh_interval",
3838
"search.idle.after",
39+
"mapping.total_fields.limit",
3940
"max_result_window",
4041
"max_inner_result_window",
4142
"max_rescore_window",
@@ -97,6 +98,7 @@ type tfModel struct {
9798
SortField types.Set `tfsdk:"sort_field"`
9899
SortOrder types.List `tfsdk:"sort_order"`
99100
MappingCoerce types.Bool `tfsdk:"mapping_coerce"`
101+
MappingTotalFieldsLimit types.Int64 `tfsdk:"mapping_total_fields_limit"`
100102
NumberOfReplicas types.Int64 `tfsdk:"number_of_replicas"`
101103
AutoExpandReplicas types.String `tfsdk:"auto_expand_replicas"`
102104
SearchIdleAfter types.String `tfsdk:"search_idle_after"`

internal/elasticsearch/index/index/schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ func getSchema() schema.Schema {
226226
},
227227
},
228228
// Dynamic settings that can be changed at runtime
229+
"mapping_total_fields_limit": schema.Int64Attribute{
230+
Description: "The maximum number of fields in an index. Field type parameters count towards this limit. The default value is 1000.",
231+
Optional: true,
232+
},
229233
"number_of_replicas": schema.Int64Attribute{
230234
Description: "Number of shard replicas.",
231235
Optional: true,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
variable "index_name" {
2+
description = "The index name"
3+
type = string
4+
}
5+
6+
provider "elasticstack" {
7+
elasticsearch {}
8+
}
9+
10+
resource "elasticstack_elasticsearch_index" "test_settings" {
11+
name = var.index_name
12+
13+
mappings = jsonencode({
14+
properties = {
15+
field1 = { type = "text" }
16+
sort_key = { type = "keyword" }
17+
}
18+
})
19+
20+
number_of_shards = 2
21+
number_of_routing_shards = 2
22+
codec = "best_compression"
23+
routing_partition_size = 1
24+
shard_check_on_startup = "false"
25+
sort_field = ["sort_key"]
26+
sort_order = ["asc"]
27+
mapping_coerce = true
28+
auto_expand_replicas = "0-5"
29+
search_idle_after = "30s"
30+
refresh_interval = "10s"
31+
max_result_window = 5000
32+
max_inner_result_window = 2000
33+
max_rescore_window = 1000
34+
max_docvalue_fields_search = 1500
35+
max_script_fields = 500
36+
max_ngram_diff = 100
37+
max_shingle_diff = 200
38+
max_refresh_listeners = 10
39+
analyze_max_token_count = 500000
40+
highlight_max_analyzed_offset = 1000
41+
max_terms_count = 10000
42+
max_regex_length = 1000
43+
query_default_field = ["field1"]
44+
routing_allocation_enable = "primaries"
45+
routing_rebalance_enable = "primaries"
46+
gc_deletes = "30s"
47+
unassigned_node_left_delayed_timeout = "5m"
48+
49+
analysis_char_filter = jsonencode({
50+
zero_width_spaces = {
51+
type = "mapping"
52+
mappings = ["\\u200C=>\\u0020"]
53+
}
54+
})
55+
analysis_filter = jsonencode({
56+
minimal_english_stemmer = {
57+
type = "stemmer"
58+
language = "minimal_english"
59+
}
60+
})
61+
analysis_analyzer = jsonencode({
62+
text_en = {
63+
type = "custom"
64+
tokenizer = "standard"
65+
char_filter = "zero_width_spaces"
66+
filter = ["lowercase", "minimal_english_stemmer"]
67+
}
68+
})
69+
70+
settings {
71+
setting {
72+
name = "number_of_replicas"
73+
value = "2"
74+
}
75+
}
76+
77+
deletion_protection = false
78+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
variable "index_name" {
2+
description = "The index name"
3+
type = string
4+
}
5+
6+
provider "elasticstack" {
7+
elasticsearch {}
8+
}
9+
10+
resource "elasticstack_elasticsearch_index" "test_settings" {
11+
name = var.index_name
12+
13+
mappings = jsonencode({
14+
properties = {
15+
field1 = { type = "text" }
16+
sort_key = { type = "keyword" }
17+
}
18+
})
19+
20+
number_of_shards = 2
21+
number_of_routing_shards = 2
22+
codec = "best_compression"
23+
routing_partition_size = 1
24+
shard_check_on_startup = "false"
25+
sort_field = ["sort_key"]
26+
sort_order = ["asc"]
27+
mapping_coerce = true
28+
mapping_total_fields_limit = 2000
29+
auto_expand_replicas = "0-5"
30+
search_idle_after = "30s"
31+
refresh_interval = "10s"
32+
max_result_window = 5000
33+
max_inner_result_window = 2000
34+
max_rescore_window = 1000
35+
max_docvalue_fields_search = 1500
36+
max_script_fields = 500
37+
max_ngram_diff = 100
38+
max_shingle_diff = 200
39+
max_refresh_listeners = 10
40+
analyze_max_token_count = 500000
41+
highlight_max_analyzed_offset = 1000
42+
max_terms_count = 10000
43+
max_regex_length = 1000
44+
query_default_field = ["field1"]
45+
routing_allocation_enable = "primaries"
46+
routing_rebalance_enable = "primaries"
47+
gc_deletes = "30s"
48+
unassigned_node_left_delayed_timeout = "5m"
49+
50+
analysis_char_filter = jsonencode({
51+
zero_width_spaces = {
52+
type = "mapping"
53+
mappings = ["\\u200C=>\\u0020"]
54+
}
55+
})
56+
analysis_filter = jsonencode({
57+
minimal_english_stemmer = {
58+
type = "stemmer"
59+
language = "minimal_english"
60+
}
61+
})
62+
analysis_analyzer = jsonencode({
63+
text_en = {
64+
type = "custom"
65+
tokenizer = "standard"
66+
char_filter = "zero_width_spaces"
67+
filter = ["lowercase", "minimal_english_stemmer"]
68+
}
69+
})
70+
71+
settings {
72+
setting {
73+
name = "number_of_replicas"
74+
value = "2"
75+
}
76+
}
77+
78+
deletion_protection = false
79+
}

0 commit comments

Comments
 (0)