You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: _analyzers/token-filters/hunspell.md
+74-11Lines changed: 74 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,9 @@ The `hunspell` token filter is used for stemming and morphological analysis of w
11
11
12
12
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.
13
13
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).
15
17
16
18
You can download these files from [LibreOffice dictionaries](https://github.com/LibreOffice/dictionaries).
17
19
@@ -22,10 +24,11 @@ The `hunspell` token filter can be configured with the following parameters.
22
24
Parameter | Required/Optional | Data type | Description
23
25
:--- | :--- | :--- | :---
24
26
`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`).
26
28
`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).
28
30
`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.**
29
32
30
33
## Example
31
34
@@ -60,20 +63,23 @@ PUT /my_index
60
63
```
61
64
{% include copy-curl.html %}
62
65
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.
64
69
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}
66
72
67
73
Place dictionary files in the following directory structure:
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/`:
77
83
78
84
```json
79
85
PUT /my_index
@@ -83,7 +89,7 @@ PUT /my_index
83
89
"filter": {
84
90
"my_custom_hunspell": {
85
91
"type": "hunspell",
86
-
"ref_path": "pkg-1234",
92
+
"ref_path": "analyzers/my-dict",
87
93
"locale": "en_US"
88
94
}
89
95
},
@@ -103,7 +109,7 @@ PUT /my_index
103
109
```
104
110
{% include copy-curl.html %}
105
111
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:
107
113
108
114
```json
109
115
PUT /index_medical
@@ -113,7 +119,7 @@ PUT /index_medical
113
119
"filter": {
114
120
"medical_hunspell": {
115
121
"type": "hunspell",
116
-
"ref_path": "medical-dict",
122
+
"ref_path": "analyzers/medical-dict",
117
123
"locale": "en_US"
118
124
}
119
125
}
@@ -131,7 +137,7 @@ PUT /index_legal
131
137
"filter": {
132
138
"legal_hunspell": {
133
139
"type": "hunspell",
134
-
"ref_path": "legal-dict",
140
+
"ref_path": "analyzers/legal-dict",
135
141
"locale": "en_US"
136
142
}
137
143
}
@@ -141,6 +147,63 @@ PUT /index_legal
141
147
```
142
148
{% include copy-curl.html %}
143
149
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
+
144
207
## Generated tokens
145
208
146
209
Use the following request to examine the tokens generated using the analyzer:
Copy file name to clipboardExpand all lines: _im-plugin/refresh-analyzer.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,3 +38,11 @@ To work, the token filter must have an `updateable` flag of `true`:
38
38
}
39
39
}
40
40
```
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