Skip to content

feat(elastic): make the fulltext analyzer configurable via ELASTIC_ANALYZER - #11147

Open
MichaelUray wants to merge 1 commit into
hcengineering:developfrom
MichaelUray:feat/fulltext-analyzer-config
Open

MichaelUray wants to merge 1 commit into
hcengineering:developfrom
MichaelUray:feat/fulltext-analyzer-config

Conversation

@MichaelUray

Copy link
Copy Markdown
Contributor

Fixes #4545

Problem and change

The fulltextSummary field, which holds the extracted text of every indexed
document, was always mapped with the custom English analyzer rebuilt_english.
Non-English deployments therefore got no stemming, so inflected forms of a
word were indexed as unrelated tokens and searches silently missed results.

The analyzer is now read from the ELASTIC_ANALYZER environment variable
(default: rebuilt_english, so existing deployments are unchanged). Any analyzer
known to the cluster can be used, e.g. the built-in russian or german ones.
Since Elasticsearch cannot change the analyzer of an existing field,
initMapping now also compares the analyzer and recreates the index when it
differs instead of failing putMapping in a retry loop; a full reindex is
needed afterwards. The variable is documented in pods/fulltext/README.md.

Tests

New unit tests foundations/server/packages/elastic/src/__tests__/analyzer.test.ts. The default (rebuilt_english) is unchanged. A full check needs a fulltext service with Elasticsearch/OpenSearch: set ELASTIC_ANALYZER=russian, restart (the index is recreated), run a reindex, and search with an inflected word.

…ALYZER

The fulltextSummary field, which holds the extracted text of every indexed
document, was always mapped with the custom English analyzer rebuilt_english.
Non-English deployments therefore got no stemming, so inflected forms of a
word were indexed as unrelated tokens and searches silently missed results.

The analyzer is now read from the ELASTIC_ANALYZER environment variable
(default: rebuilt_english, so existing deployments are unchanged). Any analyzer
known to the cluster can be used, e.g. the built-in russian or german ones.
Since Elasticsearch cannot change the analyzer of an existing field,
initMapping now also compares the analyzer and recreates the index when it
differs instead of failing putMapping in a retry loop; a full reindex is
needed afterwards. The variable is documented in pods/fulltext/README.md.

Fixes hcengineering#4545

Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

Analyzers for ElasticSearch

1 participant