Skip to content

Commit e10ab48

Browse files
Document Hunspell hot-reload and ref_path refactor for 3.7 (#12486)
* Document Hunspell hot-reload and ref_path refactor for 3.7 Update the Hunspell token filter docs to reflect the hot-reload support and ref_path path-resolution change landing in OpenSearch 3.7 (opensearch-project/OpenSearch#21516, #21559 and opensearch-project/index-management#1638): - Add the new `updateable` filter parameter. - Update `ref_path` to resolve under `<OS_PATH_CONF>` directly (was `<OS_PATH_CONF>/analyzers/`) and allow forward slashes for nested paths; add an upgrade note for users coming from 3.6. - Rename "Package-based dictionary loading" to "Custom dictionary loading with ref_path" and refresh examples to use the new layout. - Add a "Hot-reloading Hunspell dictionaries" section covering the `updateable` + `_refresh_search_analyzers?reload_cached_resources=true` workflow. - Document the new `reload_cached_resources` query parameter on the Refresh search analyzer API page. Signed-off-by: shayush622 <ayush5267@gmail.com> * Doc review Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Apply suggestion from @kolchfa-aws Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> --------- Signed-off-by: shayush622 <ayush5267@gmail.com> Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Co-authored-by: Fanit Kolchina <kolchfa@amazon.com> Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com>
1 parent 8e8471a commit e10ab48

2 files changed

Lines changed: 82 additions & 11 deletions

File tree

_analyzers/token-filters/hunspell.md

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ The `hunspell` token filter is used for stemming and morphological analysis of w
1111

1212
The Hunspell dictionary files are automatically loaded at startup from the `<OS_PATH_CONF>/hunspell/<locale>` directory. For example, the `en_GB` locale must have at least one `.aff` file and one or more `.dic` files in the `<OS_PATH_CONF>/hunspell/en_GB/` directory.
1313

14-
Alternatively, you can configure package-based dictionary loading using the `ref_path` parameter to maintain multiple independent dictionary sets for the same locale. For more information, see [Package-based dictionary loading](#package-based-dictionary-loading).
14+
Alternatively, you can load dictionaries from a custom directory by using the `ref_path` parameter to maintain multiple independent dictionary sets for the same locale. For more information, see [Custom dictionary loading with ref_path](#custom-dictionary-loading).
15+
16+
You can also hot-reload Hunspell dictionaries at runtime without restarting the node. For more information, see [Hot-reloading Hunspell dictionaries](#hot-reloading-hunspell-dictionaries).
1517

1618
You can download these files from [LibreOffice dictionaries](https://github.com/LibreOffice/dictionaries).
1719

@@ -22,10 +24,11 @@ The `hunspell` token filter can be configured with the following parameters.
2224
Parameter | Required/Optional | Data type | Description
2325
:--- | :--- | :--- | :---
2426
`language/lang/locale` | At least one of the three is required | String | Specifies the language for the Hunspell dictionary. Can contain only alphanumeric characters, hyphens, and underscores (for example, `en_US`, `de_DE`).
25-
`ref_path` | Optional | String | Specifies a package name used to load dictionaries from the `<OS_PATH_CONF>/analyzers/<ref_path>/hunspell/<locale>/` directory instead of the default `<OS_PATH_CONF>/hunspell/<locale>/` directory. When specified, the `locale` parameter is required. Both `ref_path` and `locale` parameters can contain only alphanumeric characters, hyphens, and underscores. See [Package-based dictionary loading](#package-based-dictionary-loading).
27+
`ref_path` | Optional | String | Specifies a relative path used to load dictionaries from the `<OS_PATH_CONF>/<ref_path>/hunspell/<locale>/` directory instead of the default `<OS_PATH_CONF>/hunspell/<locale>/` directory. When specified, the `locale` parameter is required. The `ref_path` value can contain alphanumeric characters, hyphens, underscores, and forward slashes (for nested paths such as `analyzers/my-dict`). The `locale` value can contain only alphanumeric characters, hyphens, and underscores. See [Custom dictionary loading with ref_path](#custom-dictionary-loading). **Note**: Starting in OpenSearch 3.7, `ref_path` resolves directly under `<OS_PATH_CONF>`. In earlier versions (3.6), it resolved under `<OS_PATH_CONF>/analyzers/`. To preserve the previous layout, prefix your `ref_path` value with `analyzers/` (for example, `analyzers/my-dict`).
2628
`dedup` | Optional | Boolean | Determines whether to remove multiple duplicate stemming terms for the same token. Default is `true`.
27-
`dictionary` | Optional | Array of strings | Configures the dictionary files to be used for the Hunspell dictionary. Default is all files in the `<OS_PATH_CONF>/hunspell/<locale>` directory if `ref_path` is not specified or all files in the `<OS_PATH_CONF>/analyzers/<ref_path>/hunspell/<locale>/` directory when `ref_path` is specified. See [Package-based dictionary loading](#package-based-dictionary-loading).
29+
`dictionary` | Optional | Array of strings | Configures the dictionary files to be used for the Hunspell dictionary. Default is all files in the `<OS_PATH_CONF>/hunspell/<locale>` directory if `ref_path` is not specified or all files in the `<OS_PATH_CONF>/<ref_path>/hunspell/<locale>/` directory when `ref_path` is specified. See [Custom dictionary loading with ref_path](#custom-dictionary-loading).
2830
`longest_only` | Optional | Boolean | Specifies whether only the longest stemmed version of the token should be returned. Default is `false`.
31+
`updateable` | Optional | Boolean | When set to `true`, the filter operates in search-time analysis mode, allowing dictionaries to be hot-reloaded by using the [Refresh search analyzer]({{site.url}}{{site.baseurl}}/im-plugin/refresh-analyzer/) API without restarting the node. Default is `false`. **Introduced 3.7.**
2932

3033
## Example
3134

@@ -60,20 +63,23 @@ PUT /my_index
6063
```
6164
{% include copy-curl.html %}
6265

63-
## Package-based dictionary loading
66+
## Custom dictionary loading
67+
68+
When you specify a `ref_path` parameter, dictionaries are loaded from a custom directory instead of the default directory. This is useful when you need multiple independent dictionary sets for the same locale, for example, when different indexes require different custom dictionaries.
6469

65-
When you specify a `ref_path` parameter, dictionaries are loaded from a package-specific directory instead of the default directory. This is useful when you need multiple independent dictionary sets for the same locale, for example, when different indexes require different custom dictionaries.
70+
Starting in OpenSearch 3.7, `ref_path` is resolved relative to `<OS_PATH_CONF>` and can contain forward slashes for nested paths. In OpenSearch 3.6, `ref_path` was resolved relative to `<OS_PATH_CONF>/analyzers/`. To preserve the previous directory layout when upgrading from 3.6, prefix your existing `ref_path` value with `analyzers/`.
71+
{: .note}
6672

6773
Place dictionary files in the following directory structure:
6874

6975
```xml
70-
<OS_PATH_CONF>/analyzers/<ref_path>/hunspell/<locale>/
76+
<OS_PATH_CONF>/<ref_path>/hunspell/<locale>/
7177
├── <locale>.aff (exactly one .aff file required)
7278
├── <locale>.dic (one or more .dic files)
7379
└── <locale>_custom.dic
7480
```
7581

76-
The following example loads a Hunspell dictionary from the package directory `<OS_PATH_CONF>/analyzers/pkg-1234/hunspell/en_US/`:
82+
The following example loads a Hunspell dictionary from `<OS_PATH_CONF>/analyzers/my-dict/hunspell/en_US/`:
7783

7884
```json
7985
PUT /my_index
@@ -83,7 +89,7 @@ PUT /my_index
8389
"filter": {
8490
"my_custom_hunspell": {
8591
"type": "hunspell",
86-
"ref_path": "pkg-1234",
92+
"ref_path": "analyzers/my-dict",
8793
"locale": "en_US"
8894
}
8995
},
@@ -103,7 +109,7 @@ PUT /my_index
103109
```
104110
{% include copy-curl.html %}
105111

106-
Multiple indexes can use different packages configured for the same locale. Each package maintains its own independent dictionary cache:
112+
Multiple indexes can use different `ref_path` directories configured for the same locale. Each `ref_path` maintains its own independent dictionary cache:
107113

108114
```json
109115
PUT /index_medical
@@ -113,7 +119,7 @@ PUT /index_medical
113119
"filter": {
114120
"medical_hunspell": {
115121
"type": "hunspell",
116-
"ref_path": "medical-dict",
122+
"ref_path": "analyzers/medical-dict",
117123
"locale": "en_US"
118124
}
119125
}
@@ -131,7 +137,7 @@ PUT /index_legal
131137
"filter": {
132138
"legal_hunspell": {
133139
"type": "hunspell",
134-
"ref_path": "legal-dict",
140+
"ref_path": "analyzers/legal-dict",
135141
"locale": "en_US"
136142
}
137143
}
@@ -141,6 +147,63 @@ PUT /index_legal
141147
```
142148
{% include copy-curl.html %}
143149

150+
## Hot-reloading Hunspell dictionaries
151+
**Introduced 3.7**
152+
{: .label .label-purple }
153+
154+
You can update Hunspell dictionaries at runtime without restarting the node. To enable this, set the `updateable` parameter to `true` on the Hunspell token filter. This registers the filter in search-time analysis mode, so it can only be used at search time (for example, in a `search_analyzer`), not at index time.
155+
156+
To hot-reload a Hunspell dictionary, follow these steps:
157+
158+
1. Configure the Hunspell token filter with `updateable` set to `true`. The following example creates an index that uses a hot-reloadable Hunspell filter as a `search_analyzer`:
159+
160+
```json
161+
PUT /my_index
162+
{
163+
"settings": {
164+
"analysis": {
165+
"filter": {
166+
"my_reloadable_hunspell": {
167+
"type": "hunspell",
168+
"ref_path": "analyzers/my-dict",
169+
"locale": "en_US",
170+
"updateable": true
171+
}
172+
},
173+
"analyzer": {
174+
"my_search_analyzer": {
175+
"type": "custom",
176+
"tokenizer": "standard",
177+
"filter": [
178+
"lowercase",
179+
"my_reloadable_hunspell"
180+
]
181+
}
182+
}
183+
}
184+
},
185+
"mappings": {
186+
"properties": {
187+
"content": {
188+
"type": "text",
189+
"analyzer": "standard",
190+
"search_analyzer": "my_search_analyzer"
191+
}
192+
}
193+
}
194+
}
195+
```
196+
{% include copy-curl.html %}
197+
198+
1. Replace the `.aff` and `.dic` files on disk on every node that holds a shard for the index.
199+
200+
1. Call the [Refresh Search Analyzer API]({{site.url}}{{site.baseurl}}/im-plugin/refresh-analyzer/). When `reload_cached_resources` is `false` (the default), the API rebuilds analyzer factories but reuses the previously cached Hunspell dictionary. Specify `reload_cached_resources=true` to force the dictionary to be reloaded from disk:
201+
202+
```json
203+
POST /_plugins/_refresh_search_analyzers/my_index?reload_cached_resources=true
204+
```
205+
{% include copy-curl.html %}
206+
144207
## Generated tokens
145208

146209
Use the following request to examine the tokens generated using the analyzer:

_im-plugin/refresh-analyzer.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ To work, the token filter must have an `updateable` flag of `true`:
3838
}
3939
}
4040
```
41+
42+
## Query parameters
43+
44+
The following table lists the supported query parameters.
45+
46+
Parameter | Data type | Description
47+
:--- | :--- | :---
48+
`reload_cached_resources` | Boolean | When set to `true`, reloads cached resources from disk without rebuilding caches for token filters that load files from disk (for example, the [`hunspell`]({{site.url}}{{site.baseurl}}/analyzers/token-filters/hunspell/) filter's dictionary files). When `false` (the default), analyzer factories are rebuilt but cached resources are reused.

0 commit comments

Comments
 (0)