opensearch-project / opensearch-py

Python Client for OpenSearch
https://opensearch.org/docs/latest/clients/python/
Apache License 2.0
350 stars 175 forks source link

[BUG] Cannot Register Analyzer #506

Closed mihikjw closed 1 year ago

mihikjw commented 1 year ago

What is the bug?

Registering an analyzer using the example method returns an error when creating the index:

opensearchpy.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'Failed to parse mapping [_doc]: analyzer [whitespace_analyzer] has not been configured in mappings')

It looks like when it goes through the following function:

class Index(object):
   def analyzer(self, *args, **kwargs):
      analyzer = analysis.analyzer(*args, **kwargs)
      d = analyzer.get_analysis_definition()
      # empty custom analyzer, probably already defined out of our control
      if not d:
         return

      # merge the definition
      merge(self._analysis, d, True)

d is always an empty dict taken from BuiltinAnalyzer.get_analysis_definition - resulting in the definition not being merged.

Am I missing a step, or is this a bug?

How can one reproduce the bug?

standards_index = Index("standards")

@standards_index.document
class StandardDocument(Document):
    id = Keyword(required=True)
    name = Text(
        required=True,
        analyzer=ngram_analyzer,
        search_analyzer=whitespace_analyzer,
        fields={"raw": Keyword()},
    )

# ...

whitespace_analyzer = analyzer(
    "whitespace_analyzer",
    tokenizer="whitespace",
    filter=["lowercase", "asciifolding"],
)

# ...

index.analyzer(whitespace_analyzer)
index.create(using=connection)   # this line triggers the exception

What is the expected behavior?

The Analyzer is registered correctly and the index can be created with StandardDocument and not trigger an exception.

What is your host/environment?

WSL2 Ubuntu 18.04.5 LTS

Do you have any screenshots?

N/A

Do you have any additional context?

N/A

dblock commented 1 year ago

@mihikjw What was your issue, and how did you solve it, for the next person?