Skip to content

Commit 85eccf4

Browse files
leemthompomarciw
andauthored
[WIP] Update Synonyms page, mention UI option (#2675)
closes elastic/docs-content-internal#201 • **Restructured content flow** - Moved duplicate heading, consolidated sections into logical workflow steps • **Added step-by-step workflow** - Organized synonyms usage into 4 clear steps: create rules and sets → configure analyzers → test → apply • **Enhanced synonym rule documentation** - Added detailed explanation of explicit mappings vs equivalent synonyms with examples • **Added Kibana UI method** - New section documenting UI-based synonym management (serverless only) • **Improved method organization** - Restructured storage options as numbered methods (UI, REST API, File-based, Inline) • **Added warning context** - Enhanced warnings about synonym rule errors and their impact • **Clarified search-time limitation** - Added note that API/UI-created synonym sets only work at search time --------- Co-authored-by: Marci W <[email protected]>
1 parent 13766c0 commit 85eccf4

File tree

1 file changed

+98
-46
lines changed

1 file changed

+98
-46
lines changed

solutions/search/full-text/search-with-synonyms.md

Lines changed: 98 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ products:
88
- id: elasticsearch
99
---
1010

11-
# Search with synonyms
11+
# Search with synonyms [search-with-synonyms]
1212

1313
$$$ece-add-custom-bundle-example-synonyms$$$
1414
::::{note}
15-
Learn about [adding custom synonym bundles](/solutions/search/full-text/search-with-synonyms.md#ece-add-custom-bundle-example-synonyms) to your {{ece}} deployment.
15+
Learn about [adding custom synonym bundles](../../../deploy-manage/deploy/elastic-cloud/upload-custom-plugins-bundles.md) to your {{ece}} deployment.
1616
::::
1717

18-
1918
% TODO: these bundle links do not belong here
2019

2120
$$$ece-add-custom-bundle-example-LDA$$$
@@ -26,41 +25,103 @@ $$$ece-add-custom-bundle-example-cacerts$$$
2625

2726
$$$ece-add-custom-bundle-example-LDAP$$$
2827

29-
# Search with synonyms [search-with-synonyms]
28+
Synonyms are words or phrases that share the same or similar meaning. Searching using synonyms allows you to:
29+
30+
* Improve search relevance by finding relevant documents that use different terms to express the same concept.
31+
* Make domain-specific vocabulary more user-friendly.
32+
* Define misspellings and typos to transparently handle common mistakes.
33+
34+
## How synonyms work in Elasticsearch
35+
36+
To use synonyms in {{es}}, follow this workflow:
37+
38+
1. **Create synonym sets and rules**: Define which terms are equivalent and where to store your synonym sets.
39+
2. **Configure analyzers**: Configure your token filters and analyzers to use them.
40+
3. **Test and apply**: Verify your configuration works correctly.
3041

31-
Synonyms are words or phrases that have the same or similar meaning. They are an important aspect of search, as they can improve the search experience and increase the scope of search results.
42+
## Synonym rule formats
43+
44+
Synonym rules define which terms should be treated as equivalent during search and indexing.
45+
46+
There are two main formats for synonym rules: explicit mappings and equivalent mappings.
47+
48+
#### Explicit mappings
49+
50+
Explicit mappings use `=>` to specify exact replacements:
51+
52+
```
53+
i-pod, i pod => ipod
54+
sea biscuit, sea biscit => seabiscuit
55+
```
56+
57+
With explicit mappings, the relationship is one-way. In the previous examples:
58+
- `i-pod` and `i pod` will be replaced with `ipod`, but `ipod` will not be replaced with `i-pod` or `i pod`
59+
- `sea biscuit` and `sea biscit` will be replaced with `seabiscuit`, but `seabiscuit` will not be replaced with `sea biscuit` or `sea biscit`
60+
61+
This is different from equivalent synonyms, which can create bidirectional relationships when `expand=true`.
62+
63+
#### Equivalent mappings
64+
65+
Equivalent synonyms use commas to group interchangeable terms:
66+
67+
```
68+
ipod, i-pod, i pod
69+
foozball, foosball
70+
universe, cosmos
71+
lol, laughing out loud
72+
```
3273

33-
Synonyms allow you to:
74+
The behavior of equivalent synonyms depends on the `expand` parameter in your token filter configuration:
75+
- If `expand=true`: `ipod, i-pod, i pod` creates bidirectional mappings:
76+
- `ipod``i-pod`
77+
- `ipod``i pod`
78+
- `i-pod``i pod`
79+
- If `expand=false`: `ipod, i-pod, i pod` maps all terms to the first term as canonical:
80+
- `ipod``ipod`
81+
- `i-pod``ipod`
82+
- `i pod``ipod`
3483

35-
* **Improve search relevance** by finding relevant documents that use different terms to express the same concept.
36-
* Make **domain-specific vocabulary** more user-friendly, allowing users to use search terms they are more familiar with.
37-
* **Define common misspellings and typos** to transparently handle common mistakes.
84+
## Step 1: Create synonym sets and rules [synonyms-store-synonyms]
3885

39-
Synonyms are grouped together using **synonyms sets**. You can have as many synonyms sets as you need.
86+
You have multiple options for creating synonym sets and rules.
4087

41-
In order to use synonyms sets in {{es}}, you need to:
88+
### Method 1: {{kib}} UI
4289

43-
* [Store your synonyms set](#synonyms-store-synonyms)
44-
* [Configure synonyms token filters and analyzers](#synonyms-synonym-token-filters)
90+
```yaml {applies_to}
91+
serverless:
92+
elasticsearch:
93+
```
4594
95+
You can create and manage synonym sets and synonym rules using the {{kib}} user interface.
4696
47-
## Store your synonyms set [synonyms-store-synonyms]
97+
To create a synonym set using the UI:
4898
49-
Your synonyms sets need to be stored in {{es}} so your analyzers can refer to them. There are three ways to store your synonyms sets:
99+
1. Navigate to **Elasticsearch** > **Synonyms** or use the [global search field](/explore-analyze/query-filter/filtering.md#_finding_your_apps_and_objects).
100+
2. Click **Get started**.
101+
3. Enter a name for your synonym set.
102+
4. Add your synonym rules in the editor by adding terms to match against:
103+
- Add **Equivalent rules** by adding multiple equivalent terms. For example: `ipod, i-pod, i pod`
104+
- Add **Explicit rules** by adding multiple terms that map to a single term. For example: `i-pod, i pod => ipod`
105+
5. Click **Save** to save your rules.
50106

107+
The UI supports the same synonym rule formats as the file-based approach. Changes made through the UI will automatically reload the associated analyzers.
51108

52-
### Synonyms API [synonyms-store-synonyms-api]
109+
### Method 2: REST API [synonyms-store-synonyms-api]
53110

54111
You can use the [synonyms APIs](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-synonyms) to manage synonyms sets. This is the most flexible approach, as it allows to dynamically define and modify synonyms sets. For examples of how to
55-
create or update a synonym set with APIs, refer to the [Create or update synonyms set API examples](/solutions/search/full-text/search-with-synonyms.md) page.
112+
create or update a synonym set with APIs, refer to the [Create or update synonyms set API examples](/solutions/search/full-text/create-update-synonyms-api-example.md) page.
56113

57114
Changes in your synonyms sets will automatically reload the associated analyzers.
58115

59-
### Synonyms File [synonyms-store-synonyms-file]
116+
### Method 3: File-based [synonyms-store-synonyms-file]
117+
118+
```{applies_to}
119+
serverless: unavailable
120+
```
60121

61122
You can store your synonyms set in a file.
62123

63-
A synonyms set file needs to be uploaded to all your cluster nodes, and be located in the configuration directory for your {{es}} distribution. If youre using {{ech}}, you can upload synonyms files using [custom bundles](../../../deploy-manage/deploy/elastic-cloud/upload-custom-plugins-bundles.md).
124+
Make sure you upload a synonyms set file for all your cluster nodes, to the configuration directory for your {{es}} distribution. If you're using {{ech}}, you can upload synonyms files using [custom bundles](../../../deploy-manage/deploy/elastic-cloud/upload-custom-plugins-bundles.md).
64125

65126
An example synonyms file:
66127

@@ -80,8 +141,8 @@ sea biscuit, sea biscit => seabiscuit
80141
# This allows the same synonym file to be used in different synonym handling strategies.
81142
# Examples:
82143
ipod, i-pod, i pod
83-
foozball , foosball
84-
universe , cosmos
144+
foozball, foosball
145+
universe, cosmos
85146
lol, laughing out loud
86147
87148
# If expand==true in the synonym token filter configuration,
@@ -104,27 +165,28 @@ When a synonyms set is updated, search analyzers that use it need to be refreshe
104165

105166
This manual syncing and reloading makes this approach less flexible than using the [synonyms API](../../../solutions/search/full-text/search-with-synonyms.md#synonyms-store-synonyms-api).
106167

107-
108-
### Inline [synonyms-store-synonyms-inline]
168+
### Method 4: Inline [synonyms-store-synonyms-inline]
109169

110170
You can test your synonyms by adding them directly inline in your token filter definition.
111171

112172
::::{warning}
113173
Inline synonyms are not recommended for production usage. A large number of inline synonyms increases cluster size unnecessarily and can lead to performance issues.
114-
115174
::::
116175

117-
118-
119-
### Configure synonyms token filters and analyzers [synonyms-synonym-token-filters]
176+
## Step 2: Configure synonyms token filters and analyzers [synonyms-synonym-token-filters]
120177

121178
Once your synonyms sets are created, you can start configuring your token filters and analyzers to use them.
122179

123180
::::{warning}
124181
Synonyms sets must exist before they can be added to indices. If an index is created referencing a nonexistent synonyms set, the index will remain in a partially created and inoperable state. The only way to recover from this scenario is to ensure the synonyms set exists then either delete and re-create the index, or close and re-open the index.
125-
126182
::::
127183

184+
{{es}} uses synonyms as part of the [analysis process](../../../manage-data/data-store/text-analysis.md). You can use two types of [token filter](elasticsearch://reference/text-analysis/token-filter-reference.md) to include synonyms:
185+
186+
* [Synonym graph](elasticsearch://reference/text-analysis/analysis-synonym-graph-tokenfilter.md): Recommended as it can correctly handle multi-word synonyms.
187+
* [Synonym](elasticsearch://reference/text-analysis/analysis-synonym-tokenfilter.md): Not recommended if you need to use multi-word synonyms.
188+
189+
Check each synonym token filter documentation for configuration details and instructions on adding it to an analyzer.
128190

129191
::::{warning}
130192
Invalid synonym rules can cause errors when applying analyzer changes. For reloadable analyzers, this prevents reloading and applying changes. You must correct errors in the synonym rules and reload the analyzer.
@@ -134,19 +196,9 @@ An index with invalid synonym rules cannot be reopened, making it inoperable whe
134196
* A node containing the index starts
135197
* The index is opened from a closed state
136198
* A node restart occurs (which reopens the node assigned shards)
137-
138199
::::
139200

140-
141-
{{es}} uses synonyms as part of the [analysis process](../../../manage-data/data-store/text-analysis.md). You can use two types of [token filter](elasticsearch://reference/text-analysis/token-filter-reference.md) to include synonyms:
142-
143-
* [Synonym graph](elasticsearch://reference/text-analysis/analysis-synonym-graph-tokenfilter.md): It is recommended to use it, as it can correctly handle multi-word synonyms ("hurriedly", "in a hurry").
144-
* [Synonym](elasticsearch://reference/text-analysis/analysis-synonym-tokenfilter.md): Not recommended if you need to use multi-word synonyms.
145-
146-
Check each synonym token filter documentation for configuration details and instructions on adding it to an analyzer.
147-
148-
149-
### Test your analyzer [synonyms-test-analyzer]
201+
## Step 3: Test your analyzer [synonyms-test-analyzer]
150202

151203
You can test an analyzer configuration without modifying your index settings. Use the [analyze API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-analyze) to test your analyzer chain:
152204

@@ -165,17 +217,17 @@ GET /_analyze
165217
}
166218
```
167219

168-
169-
### Apply synonyms at index or search time [synonyms-apply-synonyms]
220+
## Step 4: Apply synonyms at index or search time [synonyms-apply-synonyms]
170221

171222
Analyzers can be applied at [index time or search time](../../../manage-data/data-store/text-analysis/index-search-analysis.md).
172223

173224
You need to decide when to apply your synonyms:
174225

175-
* Index time: Synonyms are applied when the documents are indexed into {{es}}. This is a less flexible alternative, as changes to your synonyms require [reindexing](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-reindex).
176-
* Search time: Synonyms are applied when a search is executed. This is a more flexible approach, which doesn’t require reindexing. If token filters are configured with `"updateable": true`, search analyzers can be [reloaded](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-reload-search-analyzers) when you make changes to your synonyms.
177-
178-
Synonyms sets created using the [synonyms API](../../../solutions/search/full-text/search-with-synonyms.md#synonyms-store-synonyms-api) can only be used at search time.
226+
* **Index time**: Synonyms are applied when the documents are indexed into {{es}}. This is a less flexible alternative, as changes to your synonyms require [reindexing](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-reindex).
227+
* **Search time**: Synonyms are applied when a search is executed. This is a more flexible approach, which doesn't require reindexing. If token filters are configured with `"updateable": true`, search analyzers can be [reloaded](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-reload-search-analyzers) when you make changes to your synonyms.
228+
:::{note}
229+
Synonyms sets created using the synonyms API or the UI can only be used at search time.
230+
:::
179231

180232
You can specify the analyzer that contains your synonyms set as a [search time analyzer](../../../manage-data/data-store/text-analysis/specify-an-analyzer.md#specify-search-analyzer) or as an [index time analyzer](../../../manage-data/data-store/text-analysis/specify-an-analyzer.md#specify-index-time-analyzer).
181233

@@ -211,4 +263,4 @@ The following example adds `my_analyzer` as a search analyzer to the `title` fie
211263
}
212264
}
213265
}
214-
```
266+
```

0 commit comments

Comments
 (0)