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
- Ruby
- Scala
- Swift
using Algolia.Search.Clients;
using Algolia.Search.Http;
var client = new SearchClient(new SearchConfig("YOUR_APP_ID", "YOUR_API_KEY"));
var response = await client.BatchDictionaryEntriesAsync(
Enum.Parse<DictionaryType>("Stopwords"),
new BatchDictionaryEntriesParams
{
Requests = new List<BatchDictionaryEntriesRequest>
{
new BatchDictionaryEntriesRequest
{
Action = Enum.Parse<DictionaryAction>("AddEntry"),
Body = new DictionaryEntry
{
ObjectID = "1",
Language = Enum.Parse<SupportedLanguage>("En"),
AdditionalProperties = new Dictionary<string, object> { { "additional", "try me" } }
},
}
},
}
);
await client.WaitForAppTaskAsync(response.TaskID);
import 'package:algolia_client_search/algolia_client_search.dart';
final client = SearchClient(appId: 'YOUR_APP_ID', apiKey: 'YOUR_API_KEY');
final response = await client.batchDictionaryEntries(
dictionaryName: DictionaryType.fromJson("stopwords"),
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
requests: [
BatchDictionaryEntriesRequest(
action: DictionaryAction.fromJson("addEntry"),
body: DictionaryEntry(
objectID: "1",
language: SupportedLanguage.fromJson("en"),
additionalProperties: {'additional': 'try me'},
),
),
],
),
);
await client.waitAppTask(response.taskID);
import "github.com/algolia/algoliasearch-client-go/v4/algolia/search"
client, err := search.NewClient("YOUR_APP_ID", "YOUR_API_KEY")
response, err := client.BatchDictionaryEntries(client.NewApiBatchDictionaryEntriesRequest(
search.DictionaryType("stopwords"),
search.NewEmptyBatchDictionaryEntriesParams().SetRequests(
[]search.BatchDictionaryEntriesRequest{*search.NewEmptyBatchDictionaryEntriesRequest().SetAction(search.DictionaryAction("addEntry")).SetBody(
search.NewEmptyDictionaryEntry().SetObjectID("1").SetLanguage(search.SupportedLanguage("en")).SetAdditionalProperty("additional", "try me"))}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForAppTask(response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;
SearchClient client = new SearchClient("YOUR_APP_ID", "YOUR_API_KEY");
client.batchDictionaryEntries(
DictionaryType.STOPWORDS,
new BatchDictionaryEntriesParams()
.setRequests(
List.of(
new BatchDictionaryEntriesRequest()
.setAction(DictionaryAction.ADD_ENTRY)
.setBody(
new DictionaryEntry().setObjectID("1").setLanguage(SupportedLanguage.EN).setAdditionalProperty("additional", "try me")
)
)
)
);
client.waitForAppTask(response.getTaskID());
import { searchClient } from '@algolia/client-search';
const client = searchClient('YOUR_APP_ID', 'YOUR_API_KEY');
const response = await client.batchDictionaryEntries({
dictionaryName: 'stopwords',
batchDictionaryEntriesParams: {
requests: [
{
action: 'addEntry',
body: { objectID: '1', language: 'en', additional: 'try me' },
},
],
},
});
// use typed response
console.log(response);
await client.waitForAppTask({ taskID: response.taskID });
import com.algolia.client.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
var response = client.batchDictionaryEntries(
dictionaryName = DictionaryType.entries.first { it.value == "stopwords" },
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
requests = listOf(
BatchDictionaryEntriesRequest(
action = DictionaryAction.entries.first { it.value == "addEntry" },
body = DictionaryEntry(
objectID = "1",
language = SupportedLanguage.entries.first { it.value == "en" },
additionalProperties = mapOf(
"additional" to JsonPrimitive("try me"),
),
),
),
),
),
)
// Use the response
println(response)
client.waitAppTask(response.taskID)
use Algolia\AlgoliaSearch\Api\SearchClient;
$client = SearchClient::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
$response = $client->batchDictionaryEntries(
'stopwords',
['requests' => [
['action' => 'addEntry',
'body' => ['objectID' => '1',
'language' => 'en',
'additional' => 'try me',
],
],
],
],
);
// play with the response
var_dump($response);
$client->waitForAppTask($response['taskID']);
from algoliasearch.search.client import SearchClient
_client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY")
response = await _client.batch_dictionary_entries(
dictionary_name="stopwords",
batch_dictionary_entries_params={
"requests": [
{
"action": "addEntry",
"body": {
"objectID": "1",
"language": "en",
"additional": "try me",
},
},
],
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_app_task(task_id=response.task_id)
require 'algolia'
client = Algolia::SearchClient.create('YOUR_APP_ID', 'YOUR_API_KEY')
response = client.batch_dictionary_entries(
'stopwords',
BatchDictionaryEntriesParams.new(
requests: [BatchDictionaryEntriesRequest.new(
action: 'addEntry',
body: DictionaryEntry.new(object_id: "1", language: 'en', additional: "try me")
)]
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_app_task(response.task_id)
import algoliasearch.api.SearchClient
val client = SearchClient(appId = "YOUR_APP_ID", apiKey = "YOUR_API_KEY")
val response = client.batchDictionaryEntries(
dictionaryName = DictionaryType.withName("stopwords"),
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
requests = Seq(
BatchDictionaryEntriesRequest(
action = DictionaryAction.withName("addEntry"),
body = DictionaryEntry(
objectID = "1",
language = SupportedLanguage.withName("en"),
additionalProperties = Some(List(JField("additional", JString("try me"))))
)
)
)
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitAppTask(response.getTaskID())
import Search
let client = try SearchClient(appID: "YOUR_APP_ID", apiKey: "YOUR_API_KEY")
let response = try await client.batchDictionaryEntries(
dictionaryName: DictionaryType.stopwords,
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(requests: [BatchDictionaryEntriesRequest(
action: DictionaryAction.addEntry,
body: DictionaryEntry(from: [
"objectID": AnyCodable("1"),
"language": AnyCodable(SearchSupportedLanguage.en),
"additional": AnyCodable("try me"),
])
)])
)
try await client.waitForAppTask(with: response.taskID)
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
- Ruby
- Scala
- Swift
var response = await client.BatchDictionaryEntriesAsync(
Enum.Parse<DictionaryType>("Plurals"),
new BatchDictionaryEntriesParams
{
ClearExistingDictionaryEntries = true,
Requests = new List<BatchDictionaryEntriesRequest>
{
new BatchDictionaryEntriesRequest
{
Action = Enum.Parse<DictionaryAction>("AddEntry"),
Body = new DictionaryEntry
{
ObjectID = "1",
Language = Enum.Parse<SupportedLanguage>("En"),
Word = "fancy",
Words = new List<string> { "believe", "algolia" },
Decomposition = new List<string> { "trust", "algolia" },
State = Enum.Parse<DictionaryEntryState>("Enabled"),
},
}
},
}
);
await client.WaitForAppTaskAsync(response.TaskID);
final response = await client.batchDictionaryEntries(
dictionaryName: DictionaryType.fromJson("plurals"),
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
clearExistingDictionaryEntries: true,
requests: [
BatchDictionaryEntriesRequest(
action: DictionaryAction.fromJson("addEntry"),
body: DictionaryEntry(
objectID: "1",
language: SupportedLanguage.fromJson("en"),
word: "fancy",
words: [
"believe",
"algolia",
],
decomposition: [
"trust",
"algolia",
],
state: DictionaryEntryState.fromJson("enabled"),
),
),
],
),
);
await client.waitAppTask(response.taskID);
response, err := client.BatchDictionaryEntries(client.NewApiBatchDictionaryEntriesRequest(
search.DictionaryType("plurals"),
search.NewEmptyBatchDictionaryEntriesParams().SetClearExistingDictionaryEntries(true).SetRequests(
[]search.BatchDictionaryEntriesRequest{*search.NewEmptyBatchDictionaryEntriesRequest().SetAction(search.DictionaryAction("addEntry")).SetBody(
search.NewEmptyDictionaryEntry().SetObjectID("1").SetLanguage(search.SupportedLanguage("en")).SetWord("fancy").SetWords(
[]string{"believe", "algolia"}).SetDecomposition(
[]string{"trust", "algolia"}).SetState(search.DictionaryEntryState("enabled")))}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForAppTask(response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
client.batchDictionaryEntries(
DictionaryType.PLURALS,
new BatchDictionaryEntriesParams()
.setClearExistingDictionaryEntries(true)
.setRequests(
List.of(
new BatchDictionaryEntriesRequest()
.setAction(DictionaryAction.ADD_ENTRY)
.setBody(
new DictionaryEntry()
.setObjectID("1")
.setLanguage(SupportedLanguage.EN)
.setWord("fancy")
.setWords(List.of("believe", "algolia"))
.setDecomposition(List.of("trust", "algolia"))
.setState(DictionaryEntryState.ENABLED)
)
)
)
);
client.waitForAppTask(response.getTaskID());
const response = await client.batchDictionaryEntries({
dictionaryName: 'plurals',
batchDictionaryEntriesParams: {
clearExistingDictionaryEntries: true,
requests: [
{
action: 'addEntry',
body: {
objectID: '1',
language: 'en',
word: 'fancy',
words: ['believe', 'algolia'],
decomposition: ['trust', 'algolia'],
state: 'enabled',
},
},
],
},
});
// use typed response
console.log(response);
await client.waitForAppTask({ taskID: response.taskID });
var response = client.batchDictionaryEntries(
dictionaryName = DictionaryType.entries.first { it.value == "plurals" },
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
clearExistingDictionaryEntries = true,
requests = listOf(
BatchDictionaryEntriesRequest(
action = DictionaryAction.entries.first { it.value == "addEntry" },
body = DictionaryEntry(
objectID = "1",
language = SupportedLanguage.entries.first { it.value == "en" },
word = "fancy",
words = listOf("believe", "algolia"),
decomposition = listOf("trust", "algolia"),
state = DictionaryEntryState.entries.first { it.value == "enabled" },
),
),
),
),
)
// Use the response
println(response)
client.waitAppTask(response.taskID)
$response = $client->batchDictionaryEntries(
'plurals',
['clearExistingDictionaryEntries' => true,
'requests' => [
['action' => 'addEntry',
'body' => ['objectID' => '1',
'language' => 'en',
'word' => 'fancy',
'words' => [
'believe',
'algolia',
],
'decomposition' => [
'trust',
'algolia',
],
'state' => 'enabled',
],
],
],
],
);
// play with the response
var_dump($response);
$client->waitForAppTask($response['taskID']);
response = await _client.batch_dictionary_entries(
dictionary_name="plurals",
batch_dictionary_entries_params={
"clearExistingDictionaryEntries": True,
"requests": [
{
"action": "addEntry",
"body": {
"objectID": "1",
"language": "en",
"word": "fancy",
"words": [
"believe",
"algolia",
],
"decomposition": [
"trust",
"algolia",
],
"state": "enabled",
},
},
],
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_app_task(task_id=response.task_id)
response = client.batch_dictionary_entries(
'plurals',
BatchDictionaryEntriesParams.new(
clear_existing_dictionary_entries: true,
requests: [BatchDictionaryEntriesRequest.new(
action: 'addEntry',
body: DictionaryEntry.new(
object_id: "1",
language: 'en',
word: "fancy",
words: ["believe", "algolia"],
decomposition: ["trust", "algolia"],
state: 'enabled'
)
)]
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_app_task(response.task_id)
val response = client.batchDictionaryEntries(
dictionaryName = DictionaryType.withName("plurals"),
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
clearExistingDictionaryEntries = Some(true),
requests = Seq(
BatchDictionaryEntriesRequest(
action = DictionaryAction.withName("addEntry"),
body = DictionaryEntry(
objectID = "1",
language = SupportedLanguage.withName("en"),
word = Some("fancy"),
words = Some(Seq("believe", "algolia")),
decomposition = Some(Seq("trust", "algolia")),
state = Some(DictionaryEntryState.withName("enabled"))
)
)
)
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitAppTask(response.getTaskID())
let response = try await client.batchDictionaryEntries(
dictionaryName: DictionaryType.plurals,
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
clearExistingDictionaryEntries: true,
requests: [BatchDictionaryEntriesRequest(
action: DictionaryAction.addEntry,
body: DictionaryEntry(
objectID: "1",
language: SearchSupportedLanguage.en,
word: "fancy",
words: ["believe", "algolia"],
decomposition: ["trust", "algolia"],
state: DictionaryEntryState.enabled
)
)]
)
)
try await client.waitForAppTask(with: response.taskID)
Delete entries in the dictionary
Useful when deleting one or many entries from a dictionary.
- C#
- Dart
- Go
- Java
- JavaScript
- Kotlin
- PHP
- Python
- Ruby
- Scala
- Swift
var response = await client.BatchDictionaryEntriesAsync(
Enum.Parse<DictionaryType>("Plurals"),
new BatchDictionaryEntriesParams
{
ClearExistingDictionaryEntries = true,
Requests = new List<BatchDictionaryEntriesRequest>
{
new BatchDictionaryEntriesRequest
{
Action = Enum.Parse<DictionaryAction>("DeleteEntry"),
Body = new DictionaryEntry
{
ObjectID = "1",
Language = Enum.Parse<SupportedLanguage>("En"),
Word = "fancy",
Words = new List<string> { "believe", "algolia" },
Decomposition = new List<string> { "trust", "algolia" },
State = Enum.Parse<DictionaryEntryState>("Enabled"),
},
}
},
}
);
await client.WaitForAppTaskAsync(response.TaskID);
final response = await client.batchDictionaryEntries(
dictionaryName: DictionaryType.fromJson("plurals"),
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
clearExistingDictionaryEntries: true,
requests: [
BatchDictionaryEntriesRequest(
action: DictionaryAction.fromJson("deleteEntry"),
body: DictionaryEntry(
objectID: "1",
language: SupportedLanguage.fromJson("en"),
word: "fancy",
words: [
"believe",
"algolia",
],
decomposition: [
"trust",
"algolia",
],
state: DictionaryEntryState.fromJson("enabled"),
),
),
],
),
);
await client.waitAppTask(response.taskID);
response, err := client.BatchDictionaryEntries(client.NewApiBatchDictionaryEntriesRequest(
search.DictionaryType("plurals"),
search.NewEmptyBatchDictionaryEntriesParams().SetClearExistingDictionaryEntries(true).SetRequests(
[]search.BatchDictionaryEntriesRequest{*search.NewEmptyBatchDictionaryEntriesRequest().SetAction(search.DictionaryAction("deleteEntry")).SetBody(
search.NewEmptyDictionaryEntry().SetObjectID("1").SetLanguage(search.SupportedLanguage("en")).SetWord("fancy").SetWords(
[]string{"believe", "algolia"}).SetDecomposition(
[]string{"trust", "algolia"}).SetState(search.DictionaryEntryState("enabled")))}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// use the model directly
print(response)
taskResponse, err := searchClient.WaitForAppTask(response.TaskID, nil, nil, nil)
if err != nil {
panic(err)
}
client.batchDictionaryEntries(
DictionaryType.PLURALS,
new BatchDictionaryEntriesParams()
.setClearExistingDictionaryEntries(true)
.setRequests(
List.of(
new BatchDictionaryEntriesRequest()
.setAction(DictionaryAction.DELETE_ENTRY)
.setBody(
new DictionaryEntry()
.setObjectID("1")
.setLanguage(SupportedLanguage.EN)
.setWord("fancy")
.setWords(List.of("believe", "algolia"))
.setDecomposition(List.of("trust", "algolia"))
.setState(DictionaryEntryState.ENABLED)
)
)
)
);
client.waitForAppTask(response.getTaskID());
const response = await client.batchDictionaryEntries({
dictionaryName: 'plurals',
batchDictionaryEntriesParams: {
clearExistingDictionaryEntries: true,
requests: [
{
action: 'deleteEntry',
body: {
objectID: '1',
language: 'en',
word: 'fancy',
words: ['believe', 'algolia'],
decomposition: ['trust', 'algolia'],
state: 'enabled',
},
},
],
},
});
// use typed response
console.log(response);
await client.waitForAppTask({ taskID: response.taskID });
var response = client.batchDictionaryEntries(
dictionaryName = DictionaryType.entries.first { it.value == "plurals" },
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
clearExistingDictionaryEntries = true,
requests = listOf(
BatchDictionaryEntriesRequest(
action = DictionaryAction.entries.first { it.value == "deleteEntry" },
body = DictionaryEntry(
objectID = "1",
language = SupportedLanguage.entries.first { it.value == "en" },
word = "fancy",
words = listOf("believe", "algolia"),
decomposition = listOf("trust", "algolia"),
state = DictionaryEntryState.entries.first { it.value == "enabled" },
),
),
),
),
)
// Use the response
println(response)
client.waitAppTask(response.taskID)
$response = $client->batchDictionaryEntries(
'plurals',
['clearExistingDictionaryEntries' => true,
'requests' => [
['action' => 'deleteEntry',
'body' => ['objectID' => '1',
'language' => 'en',
'word' => 'fancy',
'words' => [
'believe',
'algolia',
],
'decomposition' => [
'trust',
'algolia',
],
'state' => 'enabled',
],
],
],
],
);
// play with the response
var_dump($response);
$client->waitForAppTask($response['taskID']);
response = await _client.batch_dictionary_entries(
dictionary_name="plurals",
batch_dictionary_entries_params={
"clearExistingDictionaryEntries": True,
"requests": [
{
"action": "deleteEntry",
"body": {
"objectID": "1",
"language": "en",
"word": "fancy",
"words": [
"believe",
"algolia",
],
"decomposition": [
"trust",
"algolia",
],
"state": "enabled",
},
},
],
},
)
# use the class directly
print(response)
# print the JSON response
print(response.to_json())
await client.wait_for_app_task(task_id=response.task_id)
response = client.batch_dictionary_entries(
'plurals',
BatchDictionaryEntriesParams.new(
clear_existing_dictionary_entries: true,
requests: [BatchDictionaryEntriesRequest.new(
action: 'deleteEntry',
body: DictionaryEntry.new(
object_id: "1",
language: 'en',
word: "fancy",
words: ["believe", "algolia"],
decomposition: ["trust", "algolia"],
state: 'enabled'
)
)]
)
)
# use the class directly
puts response
# print the JSON response
puts response.to_json
client.wait_for_app_task(response.task_id)
val response = client.batchDictionaryEntries(
dictionaryName = DictionaryType.withName("plurals"),
batchDictionaryEntriesParams = BatchDictionaryEntriesParams(
clearExistingDictionaryEntries = Some(true),
requests = Seq(
BatchDictionaryEntriesRequest(
action = DictionaryAction.withName("deleteEntry"),
body = DictionaryEntry(
objectID = "1",
language = SupportedLanguage.withName("en"),
word = Some("fancy"),
words = Some(Seq("believe", "algolia")),
decomposition = Some(Seq("trust", "algolia")),
state = Some(DictionaryEntryState.withName("enabled"))
)
)
)
)
)
// Use the response
val value = Await.result(response, Duration(100, "sec"))
client.waitAppTask(response.getTaskID())
let response = try await client.batchDictionaryEntries(
dictionaryName: DictionaryType.plurals,
batchDictionaryEntriesParams: BatchDictionaryEntriesParams(
clearExistingDictionaryEntries: true,
requests: [BatchDictionaryEntriesRequest(
action: DictionaryAction.deleteEntry,
body: DictionaryEntry(
objectID: "1",
language: SearchSupportedLanguage.en,
word: "fancy",
words: ["believe", "algolia"],
decomposition: ["trust", "algolia"],
state: DictionaryEntryState.enabled
)
)]
)
)
try await client.waitForAppTask(with: response.taskID)