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
Copy file name to clipboardExpand all lines: solutions/search/full-text/search-with-synonyms.md
+61-30Lines changed: 61 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,14 +8,13 @@ products:
8
8
- id: elasticsearch
9
9
---
10
10
11
-
# Search with synonyms
11
+
# Search with synonyms[search-with-synonyms]
12
12
13
13
$$$ece-add-custom-bundle-example-synonyms$$$
14
14
::::{note}
15
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.
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.
32
29
33
30
Synonyms allow you to:
@@ -38,29 +35,75 @@ Synonyms allow you to:
38
35
39
36
Synonyms are grouped together using **synonyms sets**. You can have as many synonyms sets as you need.
40
37
41
-
In order to use synonyms sets in {{es}}, you need to:
38
+
## How synonyms work in Elasticsearch
39
+
40
+
To use synonyms in {{es}}, you need to follow this workflow:
41
+
42
+
1.**Create synonym sets and rules** - Define which terms are equivalent and where to store your synonym sets
43
+
2.**Configure analyzers** - Apply synonyms during text analysis
44
+
3.**Test and apply** - Verify your configuration works correctly
45
+
46
+
## Step 1: Create synonym sets and rules
47
+
48
+
You can create synonym sets and rules using several methods:
49
+
50
+
### Synonym rule formats
42
51
43
-
*[Store your synonyms set](#synonyms-store-synonyms)
44
-
*[Configure synonyms token filters and analyzers](#synonyms-synonym-token-filters)
52
+
Before creating synonym sets, you need to understand how to write synonym rules. Synonym rules define which terms should be treated as equivalent during search and indexing.
45
53
54
+
There are two main formats for synonym rules:
46
55
47
-
## Store your synonyms set [synonyms-store-synonyms]
56
+
**Explicit mappings** use `=>` to specify exact replacements:
57
+
```
58
+
i-pod, i pod => ipod
59
+
sea biscuit, sea biscit => seabiscuit
60
+
```
48
61
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:
62
+
**Equivalent synonyms** use commas to group interchangeable terms:
63
+
```
64
+
ipod, i-pod, i pod
65
+
foozball, foosball
66
+
universe, cosmos
67
+
lol, laughing out loud
68
+
```
50
69
70
+
The behavior of equivalent synonyms depends on the `expand` parameter in your token filter configuration:
71
+
- If `expand=true`: `ipod, i-pod, i pod` expands to `ipod, i-pod, i pod`
72
+
- If `expand=false`: `ipod, i-pod, i pod` maps to just `ipod`
51
73
52
-
### Synonyms API [synonyms-store-synonyms-api]
74
+
### Method 1: Kibana UI
75
+
76
+
```yaml {applies_to}
77
+
serverless:
78
+
elasticsearch:
79
+
```
80
+
81
+
You can create and manage synonym sets and synonym rules using the Kibana user interface. This provides a user-friendly way to manage synonyms without using APIs or file uploads.
82
+
83
+
To create a synonym set using the UI:
84
+
85
+
1. Navigate to **Elasticsearch** > **Synonyms** or use the [global search field](docs-content://explore-analyze/query-filter/filtering.md#_finding_your_apps_and_objects)
86
+
2. Click **Get started**
87
+
3. Enter a name for your synonym set
88
+
4. Add your synonym rules in the editor using the formats above:
89
+
- Explicit mappings: `i-pod, i pod => ipod`
90
+
- Equivalent synonyms: `ipod, i-pod, i pod`
91
+
5. Click **Create** to save your synonym set
92
+
93
+
The UI supports the same synonym rule formats as the file-based approach. Changes made through the UI will automatically reload the associated analyzers.
94
+
95
+
### Method 2: REST API
53
96
54
97
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
98
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.
56
99
57
100
Changes in your synonyms sets will automatically reload the associated analyzers.
58
101
59
-
### Synonyms File [synonyms-store-synonyms-file]
102
+
### Method 3: File-based
60
103
61
104
You can store your synonyms set in a file.
62
105
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 you’re using {{ech}}, you can upload synonyms files using [custom bundles](../../../deploy-manage/deploy/elastic-cloud/upload-custom-plugins-bundles.md).
106
+
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 you're using {{ech}}, you can upload synonyms files using [custom bundles](../../../deploy-manage/deploy/elastic-cloud/upload-custom-plugins-bundles.md).
64
107
65
108
An example synonyms file:
66
109
@@ -104,28 +147,22 @@ When a synonyms set is updated, search analyzers that use it need to be refreshe
104
147
105
148
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).
106
149
107
-
108
-
### Inline [synonyms-store-synonyms-inline]
150
+
### Method 4: Inline
109
151
110
152
You can test your synonyms by adding them directly inline in your token filter definition.
111
153
112
154
::::{warning}
113
155
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
-
115
156
::::
116
157
117
-
118
-
119
-
### Configure synonyms token filters and analyzers [synonyms-synonym-token-filters]
158
+
## Step 2: Configure synonyms token filters and analyzers [synonyms-synonym-token-filters]
120
159
121
160
Once your synonyms sets are created, you can start configuring your token filters and analyzers to use them.
122
161
123
162
::::{warning}
124
163
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
-
126
164
::::
127
165
128
-
129
166
::::{warning}
130
167
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.
131
168
@@ -134,19 +171,16 @@ An index with invalid synonym rules cannot be reopened, making it inoperable whe
134
171
* A node containing the index starts
135
172
* The index is opened from a closed state
136
173
* A node restart occurs (which reopens the node assigned shards)
137
-
138
174
::::
139
175
140
-
141
176
{{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
177
143
178
* [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
179
* [Synonym](elasticsearch://reference/text-analysis/analysis-synonym-tokenfilter.md): Not recommended if you need to use multi-word synonyms.
145
180
146
181
Check each synonym token filter documentation for configuration details and instructions on adding it to an analyzer.
147
182
148
-
149
-
### Test your analyzer [synonyms-test-analyzer]
183
+
## Step 3: Test your analyzer [synonyms-test-analyzer]
150
184
151
185
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:
152
186
@@ -165,17 +199,14 @@ GET /_analyze
165
199
}
166
200
```
167
201
168
-
169
-
### Apply synonyms at index or search time [synonyms-apply-synonyms]
202
+
## Step 4: Apply synonyms at index or search time [synonyms-apply-synonyms]
170
203
171
204
Analyzers can be applied at [index time or search time](../../../manage-data/data-store/text-analysis/index-search-analysis.md).
172
205
173
206
You need to decide when to apply your synonyms:
174
207
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.
208
+
* **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).
209
+
* **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.
179
210
180
211
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).
0 commit comments