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

Error when use synonyms_path #303

Open
wli-chwy opened this issue Aug 5, 2022 · 9 comments
Open

Error when use synonyms_path #303

wli-chwy opened this issue Aug 5, 2022 · 9 comments

Comments

@wli-chwy
Copy link

wli-chwy commented Aug 5, 2022

Hi all, please help me resolve this issue

I try to use AWS open search package feature for dynamic synonym https://docs.aws.amazon.com/opensearch-service/latest/developerguide/custom-packages.html

However, after I upload and associate the package by hand. I get the following error while creating a index using the TF. It does not have more detail. If I change synonyms_path back to an explicit list, that works, however I still cannot use dynamic synonym. (synonyms_path = "analyzers/F34192456" => synonyms = split("\n", file("${path.module}/data/synonyms.txt"). And interestingly, even thought it gives 400 back. The index get created with the right _settings

    synonyms = {
      type     = "synonym"
      lenient  = true
      synonyms_path = "analyzers/F34192456"
      updateable = true
    }
Error: elastic: Error 400 (Bad Request)

  on modules/es-schema-catalog/main.tf line 797, in resource "elasticsearch_index_template" "es_index_catalog_template":
 797: resource "elasticsearch_index_template" "es_index_catalog_template" {
@wli-chwy
Copy link
Author

wli-chwy commented Aug 5, 2022

synonyms_path = "analyzers/F34192456" => synonyms = split("\n", file("${path.module}/data/synonyms.txt"))
will be fine. But I cannot use the dynamic synonym anymore

@phillbaker
Copy link
Owner

Hello, can you please include the following:

  • terraform version
  • provider version
  • elasticsearch version (and opendistro version if relevant)
  • redacted version of the terraform resource configuration
  • terraform logs by setting TF_LOG=info

@wli-chwy
Copy link
Author

wli-chwy commented Aug 8, 2022

Terraform v1.1.6
on darwin_amd64

phillbaker/elasticsearch v2.0.2

Elasticsearch 7.10


@wli-chwy
Copy link
Author

wli-chwy commented Aug 8, 2022

relevant terraform resource

    synonyms = {
      type     = "synonym"
      lenient  = true
      synonyms_path = "analyzers/ "
      updateable = true
    }

    en_query_analyzer = {
      type      = "custom"
      tokenizer = "standard"
      filter    = ["asciifolding", "lowercase", "en_possessive_stemmer", "keywords_no_stem", "en_stop_words", "porter_stem", "synonyms"]
    }

@wli-chwy
Copy link
Author

wli-chwy commented Aug 8, 2022

adding TF_LOG=info doesn't add any new log, just

Error: elastic: Error 400 (Bad Request)

  on modules/es-schema-catalog/main.tf line 797, in resource "elasticsearch_index_template" "es_index_catalog_template":
 797: resource "elasticsearch_index_template" "es_index_catalog_template" {

@wli-chwy
Copy link
Author

wli-chwy commented Aug 8, 2022

I am wondering is it possible to write a custom API request hitting ES directly (instead of using yaml)? So I can workaround the issue in the meantime?

@phillbaker
Copy link
Owner

relevant terraform resource

Can you please include the entire terraform definition? All of resource "elasticsearch_index_template" "es_index_catalog_template"

@wli-chwy
Copy link
Author

wli-chwy commented Aug 15, 2022

Thank you. @phillbaker There is a minimal repro version that still has the same issue

terraform {
  required_providers {
    elasticsearch = {
      source  = "phillbaker/elasticsearch"
      version = ">=1.5.8"
    }
  }
}

provider "elasticsearch" {
  url               = var.es_endpoint
  aws_region        = var.aws_region
  sign_aws_requests = true
}

locals {
  properties = {
    shortdescription = {
      type            = "text"
      store           = true
      search_analyzer = "en_query_analyzer"
    }
  }

  token_filters = {
    synonyms = {
      type          = "synonym"
      lenient       = true
      synonyms_path = "analyzers/F34192456"
      updateable    = true
    }
  }

  analyzers = {
    en_query_analyzer = {
      type      = "custom"
      tokenizer = "standard"
      filter    = ["synonyms"]
    }
  }
}

resource "elasticsearch_index_template" "es_index_catalog_template" {
  name = "catalog"
  body = jsonencode({
    index_patterns = [
      "catalog*"
    ]
    mappings = {
      properties = local.properties
    }
    settings = {
      "index.mapping.total_fields.limit" = 10000
      index = {
        analysis = {
          analyzer = local.analyzers
          filter   = local.token_filters
        }
      }
    }
    template = "catalog*"
  })
}

resource "elasticsearch_index" "es_index_catalog_minirepro" {
  name               = "catalog-minirepro"
  number_of_shards   = 1
  number_of_replicas = var.replicas_count

  depends_on = [elasticsearch_index_template.es_index_catalog_template]
}

@wli-chwy
Copy link
Author

@phillbaker do you know any debugging tips? I tries to see what the web API ends up generated. Do you know how?

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

No branches or pull requests

2 participants