Manage dictionary entries
The REST API offers a single endpoint to manage your dictionary. In this guide, we will demonstrate how to manage entries for different scenarios.
A dictionaryName
can be either stopwords
, plurals
or compounds
.
Append new entries to your dictionary
Useful when you have new data to add to a dictionary and don't want to impact existing entries.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Scala
await client.batchDictionaryEntries({
dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.
batchDictionaryEntriesParams: {
clearExistingDictionaryEntries: false, // here we want to append data, so we don't clear existing entries
requests: [
{
action: 'addEntry',
body: {
objectID: '1',
language: 'en',
word: 'fancy',
words: ['believe', 'algolia'],
decomposition: ['trust', 'algolia'],
state: 'enabled',
},
},
],
},
})
// TODO
client.batchDictionaryEntriesAsync(
DictionaryType.fromValue("YOUR_DICTIONARY_NAME"),
new BatchDictionaryEntriesParams()
.setClearExistingDictionaryEntries(false)
.setRequests(Arrays.asList(
new BatchDictionaryEntriesRequest()
.setAction(DictionaryAction.ADD_ENTRY)
.setBody(new DictionaryEntry()
.setObjectID("1")
.setLanguage("en")
.setWord("fancy")
.setWords(Arrays.asList("believe", "algolia"))
.setDecomposition(Arrays.asList("trust", "algolia"))
.setState(DictionaryEntryState.ENABLED)
)
))
);
import com.algolia.client.api.SearchClient
import com.algolia.client.model.search.*
client.batchDictionaryEntries(
dictionaryName = DictionaryType.valueOf("<YOUR_DICTIONARY_NAME>"),
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
clearExistingDictionaryEntries = false,
requests = listOf(
BatchDictionaryEntriesRequest(
action = DictionaryAction.AddEntry,
body = DictionaryEntry(
objectID = "1",
language = "en",
word = "fancy",
words = listOf("believe", "algolia"),
decomposition = listOf("trust", "algolia"),
state = DictionaryEntryState.Enabled,
)
)
),
)
)
await client.batchDictionaryEntries(
dictionaryName: DictionaryType.fromJson('<YOUR_DICTIONARY_NAME>'), // DictionaryType.plurals, DictionaryType.stopwords or DictionaryType.compounds
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
clearExistingDictionaryEntries: false,
requests: [
BatchDictionaryEntriesRequest(
action: DictionaryAction.addEntry,
body: DictionaryEntry(
objectID: '1',
language: 'en',
word: 'fancy',
words: ['believe', 'algolia'],
decomposition: ['trust', 'algolia'],
state: DictionaryEntryState.enabled,
),
),
],
),
);
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
response, err := searchClient.BatchDictionaryEntries(
searchClient.NewApiBatchDictionaryEntriesRequest(
// One of search.DICTIONARYTYPE_STOPWORDS, search.DICTIONARYTYPE_PLURALS or search.DICTIONARYTYPE_COMPOUNDS.
dictionaryType,
search.NewBatchDictionaryEntriesParams(
[]search.BatchDictionaryEntriesRequest{
*search.NewBatchDictionaryEntriesRequest(
search.DICTIONARYACTION_ADD_ENTRY,
*search.NewDictionaryEntry(
"1",
"en",
search.WithDictionaryEntryWord("fancy"),
search.WithDictionaryEntryWords([]string{"believe", "algolia"}),
search.WithDictionaryEntryDecomposition([]string{"trust", "algolia"}),
search.WithDictionaryEntryState(search.DICTIONARYENTRYSTATE_ENABLED),
),
),
},
// Here we want to append data, so we don't clear existing entries.
search.WithBatchDictionaryEntriesParamsClearExistingDictionaryEntries(false),
),
),
)
if err != nil {
panic(err)
}
taskResponse, err := searchClient.WaitForTask(
indexName,
response.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
Replace dictionary entries
Useful when you want to clear every entries of a dictionary and add new ones at the same time.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Scala
await client.batchDictionaryEntries({
dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.
batchDictionaryEntriesParams: {
clearExistingDictionaryEntries: true, // Since we replace, we will create a new dictionary from those entries
requests: [
{
action: 'addEntry',
body: {
objectID: '1',
language: 'en',
word: 'fancy',
words: ['believe', 'algolia'],
decomposition: ['trust', 'algolia'],
state: 'enabled',
},
},
],
},
})
// TODO
client.batchDictionaryEntriesAsync(
DictionaryType.fromValue("YOUR_DICTIONARY_NAME"), // DictionaryType.PLURALS, DictionaryType.STOPWORDS or DictionaryType.COMPOUNDS
new BatchDictionaryEntriesParams()
.setClearExistingDictionaryEntries(true) // Since we replace, we will create a new dictionary from those entries
.setRequests(Arrays.asList(
new BatchDictionaryEntriesRequest()
.setAction(DictionaryAction.ADD_ENTRY)
.setBody(new DictionaryEntry()
.setObjectID("1")
.setLanguage("en")
.setWord("fancy")
.setWords(Arrays.asList("believe", "algolia"))
.setDecomposition(Arrays.asList("trust", "algolia"))
.setState(DictionaryEntryState.ENABLED)
)
))
);
import com.algolia.client.api.SearchClient
import com.algolia.client.model.search.*
client.batchDictionaryEntries(
dictionaryName = DictionaryType.valueOf("<YOUR_DICTIONARY_NAME>"), // DictionaryType.Plurals, DictionaryType.Stopwords or DictionaryType.Compounds
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
clearExistingDictionaryEntries = true, // Since we replace, we will create a new dictionary from those entries
requests = listOf(
BatchDictionaryEntriesRequest(
action = DictionaryAction.AddEntry,
body = DictionaryEntry(
objectID = "1",
language = "en",
word = "fancy",
words = listOf("believe", "algolia"),
decomposition = listOf("trust", "algolia"),
state = DictionaryEntryState.Enabled,
)
)
),
)
)
await client.batchDictionaryEntries(
dictionaryName: DictionaryType.fromJson('<YOUR_DICTIONARY_NAME>'), // DictionaryType.plurals, DictionaryType.stopwords or DictionaryType.compounds
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
clearExistingDictionaryEntries: true, // Since we replace, we will create a new dictionary from those entries
requests: [
BatchDictionaryEntriesRequest(
action: DictionaryAction.addEntry,
body: DictionaryEntry(
objectID: '1',
language: 'en',
word: 'fancy',
words: ['believe', 'algolia'],
decomposition: ['trust', 'algolia'],
state: DictionaryEntryState.enabled,
),
)
],
),
);
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
response, err := searchClient.BatchDictionaryEntries(
searchClient.NewApiBatchDictionaryEntriesRequest(
// One of search.DICTIONARYTYPE_STOPWORDS, search.DICTIONARYTYPE_PLURALS or search.DICTIONARYTYPE_COMPOUNDS.
dictionaryType,
search.NewBatchDictionaryEntriesParams(
[]search.BatchDictionaryEntriesRequest{
*search.NewBatchDictionaryEntriesRequest(
search.DICTIONARYACTION_ADD_ENTRY,
*search.NewDictionaryEntry(
"1",
"en",
search.WithDictionaryEntryWord("fancy"),
search.WithDictionaryEntryWords([]string{"believe", "algolia"}),
search.WithDictionaryEntryDecomposition([]string{"trust", "algolia"}),
search.WithDictionaryEntryState(search.DICTIONARYENTRYSTATE_ENABLED),
),
),
},
// Since we replace, we will create a new dictionary from those entries
search.WithBatchDictionaryEntriesParamsClearExistingDictionaryEntries(true),
),
),
)
if err != nil {
panic(err)
}
taskResponse, err := searchClient.WaitForTask(
indexName,
response.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
Clear dictionary
Deletes everything that exists in a dictionary.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Scala
await client.batchDictionaryEntries({
dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.
batchDictionaryEntriesParams: {
clearExistingDictionaryEntries: true,
requests: [], // We don't push any new entries to it
},
})
// TODO
client.batchDictionaryEntriesAsync(
DictionaryType.fromValue("YOUR_DICTIONARY_NAME"), // DictionaryType.PLURALS, DictionaryType.STOPWORDS or DictionaryType.COMPOUNDS
new BatchDictionaryEntriesParams()
.setClearExistingDictionaryEntries(true)
.setRequests(Collections.emptyList()) // We don't push any new entries to it
);
import com.algolia.client.api.SearchClient
import com.algolia.client.model.search.*
client.batchDictionaryEntries(
dictionaryName = DictionaryType.valueOf("<YOUR_DICTIONARY_NAME>"), // DictionaryType.Plurals, DictionaryType.Stopwords or DictionaryType.Compounds
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
clearExistingDictionaryEntries = true,
requests = listOf(), // We don't push any new entries to it
)
)
await client.batchDictionaryEntries(
dictionaryName: DictionaryType.fromJson('<YOUR_DICTIONARY_NAME>'), // DictionaryType.plurals, DictionaryType.stopwords or DictionaryType.compounds
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
clearExistingDictionaryEntries: true,
requests: [], // We don't push any new entries to it
),
);
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
response, err := searchClient.BatchDictionaryEntries(
searchClient.NewApiBatchDictionaryEntriesRequest(
// One of search.DICTIONARYTYPE_STOPWORDS, search.DICTIONARYTYPE_PLURALS or search.DICTIONARYTYPE_COMPOUNDS.
dictionaryType,
search.NewBatchDictionaryEntriesParams(
[]search.BatchDictionaryEntriesRequest{}, // We don't push any new entries to it
search.WithBatchDictionaryEntriesParamsClearExistingDictionaryEntries(true),
),
),
)
if err != nil {
panic(err)
}
taskResponse, err := searchClient.WaitForTask(
indexName,
response.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}
Delete entries in the dictionary
Useful when deleting one or many entries from a dictionary.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Scala
await client.batchDictionaryEntries({
dictionaryName: 'YOUR_DICTIONARY_NAME', // one of `stopwords`, `plurals` or `compounds`.
batchDictionaryEntriesParams: {
clearExistingDictionaryEntries: false, // we don't want to impact other entries.
requests: [
{
action: 'deleteEntry', // `deleteEntry` will remove any entries in the dictionary that have the same `objectID` as the `body.objectID` field.
body: {
objectID: '1',
},
},
],
},
})
// TODO
client.batchDictionaryEntriesAsync(
DictionaryType.fromValue("YOUR_DICTIONARY_NAME"), // DictionaryType.PLURALS, DictionaryType.STOPWORDS or DictionaryType.COMPOUNDS
new BatchDictionaryEntriesParams()
.setClearExistingDictionaryEntries(false) // we don't want to impact other entries.
.setRequests(Arrays.asList(
new BatchDictionaryEntriesRequest()
.setAction(DictionaryAction.DELETE_ENTRY)
.setBody(new DictionaryEntry().setObjectID("1")))
)
);
import com.algolia.client.api.SearchClient
import com.algolia.client.model.search.*
client.batchDictionaryEntries(
dictionaryName = DictionaryType.valueOf("<YOUR_DICTIONARY_NAME>"), // DictionaryType.Plurals, DictionaryType.Stopwords or DictionaryType.Compounds
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
clearExistingDictionaryEntries = false, // we don't want to impact other entries.
requests = listOf(
BatchDictionaryEntriesRequest(
action = DictionaryAction.DeleteEntry,
body = DictionaryEntry(objectID = "1", language = "en")
)
),
)
)
await client.batchDictionaryEntries(
dictionaryName: DictionaryType.fromJson('<YOUR_DICTIONARY_NAME>'), // DictionaryType.plurals, DictionaryType.stopwords or DictionaryType.compounds
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
clearExistingDictionaryEntries: false, // we don't want to impact other entries.
requests: [
BatchDictionaryEntriesRequest(
action: DictionaryAction.deleteEntry,
body: DictionaryEntry(objectID: '1', language: 'en'),
),
],
),
);
import (
"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
)
indexName := "<INDEX_NAME>"
appID := "<APPLICATION_ID>"
apiKey := "<API_KEY>"
searchClient, _ := search.NewClient(appID, apiKey)
response, err := searchClient.BatchDictionaryEntries(
searchClient.NewApiBatchDictionaryEntriesRequest(
// One of search.DICTIONARYTYPE_STOPWORDS, search.DICTIONARYTYPE_PLURALS or search.DICTIONARYTYPE_COMPOUNDS.
dictionaryType,
search.NewBatchDictionaryEntriesParams(
[]search.BatchDictionaryEntriesRequest{
*search.NewBatchDictionaryEntriesRequest(
// `deleteEntry` will remove any entries in the dictionary that have the same `objectID` as the `body.objectID` field.
search.DICTIONARYACTION_DELETE_ENTRY,
*search.NewDictionaryEntry(
"1",
"en",
),
),
},
// We don't want to impact other entries.
search.WithBatchDictionaryEntriesParamsClearExistingDictionaryEntries(false),
),
),
)
if err != nil {
panic(err)
}
taskResponse, err := searchClient.WaitForTask(
indexName,
response.TaskID,
nil,
nil,
nil,
)
if err != nil {
panic(err)
}