Skip to content

INTMDB-341: Fix search_index update #964

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

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mongodbatlas/resource_mongodbatlas_search_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour
}

if d.HasChange("collection_name") {
searchIndex.CollectionName = d.Get("collectionName").(string)
searchIndex.CollectionName = d.Get("collection_name").(string)
}

if d.HasChange("database") {
Expand All @@ -192,7 +192,7 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour
}

if d.HasChange("search_analyzer") {
searchIndex.SearchAnalyzer = d.Get("searchAnalyzer").(string)
searchIndex.SearchAnalyzer = d.Get("search_analyzer").(string)
}

if d.HasChange("mappings_dynamic") {
Expand Down
214 changes: 108 additions & 106 deletions mongodbatlas/resource_mongodbatlas_search_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,39 +162,35 @@ func testAccMongoDBAtlasSearchIndexConfig(projectID, clusterName string) string
project_id = "%[1]s"
name = "%[2]s"
disk_size_gb = 10

cluster_type = "REPLICASET"
replication_specs {
num_shards = 1
regions_config {
region_name = "US_EAST_2"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
num_shards = 1
regions_config {
region_name = "US_EAST_2"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}

backup_enabled = false
auto_scaling_disk_gb_enabled = false

// Provider Settings "block"
provider_name = "AWS"
provider_instance_size_name = "M10"

}

resource "mongodbatlas_search_index" "test" {
project_id = mongodbatlas_cluster.aws_conf.project_id
cluster_name = mongodbatlas_cluster.aws_conf.name
analyzer = "lucene.simple"
collection_name = "collection_test"
database = "database_test"
project_id = mongodbatlas_cluster.aws_conf.project_id
cluster_name = mongodbatlas_cluster.aws_conf.name
analyzer = "lucene.simple"
collection_name = "collection_test"
database = "database_test"
mappings_dynamic = "true"
name = "name_test"
search_analyzer = "lucene.standard"
name = "name_test"
search_analyzer = "lucene.standard"
}


`, projectID, clusterName)
}

Expand All @@ -207,13 +203,13 @@ func testAccMongoDBAtlasSearchIndexConfigAdvanced(projectID, clusterName string)

cluster_type = "REPLICASET"
replication_specs {
num_shards = 1
regions_config {
region_name = "US_EAST_2"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
num_shards = 1
regions_config {
region_name = "US_EAST_2"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}

backup_enabled = false
Expand All @@ -226,69 +222,77 @@ func testAccMongoDBAtlasSearchIndexConfigAdvanced(projectID, clusterName string)
}

resource "mongodbatlas_search_index" "test" {
project_id = mongodbatlas_cluster.aws_conf.project_id
cluster_name = mongodbatlas_cluster.aws_conf.name
project_id = mongodbatlas_cluster.aws_conf.project_id
cluster_name = mongodbatlas_cluster.aws_conf.name

analyzer = "lucene.simple"
collection_name = "collection_test"
database = "database_test"
analyzer = "lucene.simple"
collection_name = "collection_test"
database = "database_test"
mappings_dynamic = false
mappings_fields = <<-EOF
{
"address": {
"type": "document",
"fields": {
"city": {
"type": "string",
"analyzer": "lucene.simple",
"ignoreAbove": 255
},
"state": {
"type": "string",
"analyzer": "lucene.english"
}
mappings_fields = <<-EOF
{
"address":{
"type":"document",
"fields":{
"city":{
"type":"string",
"analyzer":"lucene.simple",
"ignoreAbove":255
},
"state":{
"type":"string",
"analyzer":"lucene.english"
}
}
},
"company": {
"type": "string",
"analyzer": "lucene.whitespace",
"multi": {
"mySecondaryAnalyzer": {
"type": "string",
"analyzer": "lucene.french"
}
},
"company":{
"type":"string",
"analyzer":"lucene.whitespace",
"multi":{
"mySecondaryAnalyzer":{
"type":"string",
"analyzer":"lucene.french"
}
}
},
"employees": {
"type": "string",
"analyzer": "lucene.standard"
}
},
"employees":{
"type":"string",
"analyzer":"lucene.standard"
}
EOF
name = "name_test"
search_analyzer = "lucene.standard"
analyzers = <<-EOF
[{
"name": "index_analyzer_test_name",
"charFilters": [{
"type": "mapping",
"mappings": {"\\" : "/"}
}],
"tokenizer": [{
"type": "nGram",
"minGram": 2,
"maxGram": 5
}],
"tokenFilters": [{
"type": "length",
"min": 20,
"max": 33
}]
}]
}
EOF
name = "name_test"
search_analyzer = "lucene.standard"
analyzers = <<-EOF
[
{
"name":"index_analyzer_test_name",
"charFilters":[
{
"type":"mapping",
"mappings":{
"\\":"/"
}
}
],
"tokenizer":[
{
"type":"nGram",
"minGram":2,
"maxGram":5s
}
],
"tokenFilters":[
{
"type":"length",
"min":20,
"max":33
}
]
}
]
EOF
}


`, projectID, clusterName)
}

Expand All @@ -298,44 +302,42 @@ func testAccMongoDBAtlasSearchIndexConfigSynonyms(projectID, clusterName string)
project_id = "%[1]s"
name = "%[2]s"
disk_size_gb = 10

cluster_type = "REPLICASET"
replication_specs {
num_shards = 1
regions_config {
region_name = "US_EAST_2"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
num_shards = 1
regions_config {
region_name = "US_EAST_2"
electable_nodes = 3
priority = 7
read_only_nodes = 0
}
}

backup_enabled = false
auto_scaling_disk_gb_enabled = false

// Provider Settings "block"
provider_name = "AWS"
provider_instance_size_name = "M10"

}

resource "mongodbatlas_search_index" "test" {
project_id = mongodbatlas_cluster.test_cluster.project_id
cluster_name = mongodbatlas_cluster.test_cluster.name
analyzer = "lucene.standard"
collection_name = "collection_test"
database = "database_test"
project_id = mongodbatlas_cluster.test_cluster.project_id
cluster_name = mongodbatlas_cluster.test_cluster.name
analyzer = "lucene.standard"
collection_name = "collection_test"
database = "database_test"
mappings_dynamic = "true"
name = "name_test"
search_analyzer = "lucene.standard"
name = "name_test"
search_analyzer = "lucene.standard"
synonyms {
analyzer = "lucene.simple"
name = "synonym_test"
analyzer = "lucene.simple"
name = "synonym_test"
source_collection = "collection_test"
}
}


`, projectID, clusterName)
}

Expand Down