addObject, deleteIndex, editSettings
You can make the call synchronous by providing the watch parameter, for asynchronous calls, you can use the observability endpoints and/or debugger dashboard to see the status of your task.
If you want to leverage the pre-indexing data transformation, this is the recommended way of ingesting your records.
This method is similar to pushTask, but requires an indexName instead of a taskID. If zero or many tasks are found, an error will be returned.
Usage
// Initialize the client
var client = new IngestionClient(
new IngestionConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")
);
// Call the API
var response = await client.PushAsync(
"<YOUR_INDEX_NAME>",
new PushTaskPayload
{
Action = Enum.Parse<Action>("AddObject"),
Records = new List<PushTaskRecords>
{
new PushTaskRecords
{
ObjectID = "o",
AdditionalProperties = new Dictionary<string, object>
{
{ "key", "bar" },
{ "foo", "1" },
},
},
new PushTaskRecords
{
ObjectID = "k",
AdditionalProperties = new Dictionary<string, object>
{
{ "key", "baz" },
{ "foo", "2" },
},
},
},
}
);
// print the response
Console.WriteLine(response);
// Initialize the client
final client = IngestionClient(
appId: 'ALGOLIA_APPLICATION_ID',
apiKey: 'ALGOLIA_API_KEY',
region: 'ALGOLIA_APPLICATION_REGION');
// Call the API
final response = await client.push(
indexName: "<YOUR_INDEX_NAME>",
pushTaskPayload: PushTaskPayload(
action: Action.fromJson("addObject"),
records: [
PushTaskRecords(
objectID: "o",
additionalProperties: {
'key': "bar",
'foo': "1",
},
),
PushTaskRecords(
objectID: "k",
additionalProperties: {
'key': "baz",
'foo': "2",
},
),
],
),
);
// print the response
print(response);
// Initialize the client with your application region, eg. ingestion.ALGOLIA_APPLICATION_REGION
client, err := ingestion.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", ingestion.US)
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
// Call the API
response, err := client.Push(client.NewApiPushRequest(
"<YOUR_INDEX_NAME>",
ingestion.NewEmptyPushTaskPayload().SetAction(ingestion.Action("addObject")).SetRecords(
[]ingestion.PushTaskRecords{
*ingestion.NewEmptyPushTaskRecords().SetAdditionalProperty("key", "bar").SetAdditionalProperty("foo", "1").SetObjectID("o"),
*ingestion.NewEmptyPushTaskRecords().SetAdditionalProperty("key", "baz").SetAdditionalProperty("foo", "2").SetObjectID("k"),
}),
))
if err != nil {
// handle the eventual error
panic(err)
}
// print the response
print(response)
// Initialize the client
IngestionClient client = new IngestionClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION");
// Call the API
WatchResponse response = client.push(
"<YOUR_INDEX_NAME>",
new PushTaskPayload()
.setAction(Action.ADD_OBJECT)
.setRecords(
Arrays.asList(
new PushTaskRecords().setAdditionalProperty("key", "bar").setAdditionalProperty("foo", "1").setObjectID("o"),
new PushTaskRecords().setAdditionalProperty("key", "baz").setAdditionalProperty("foo", "2").setObjectID("k")
)
)
);
// print the response
System.out.println(response);
// Initialize the client
// Replace 'us' with your Algolia Application Region
const client = algoliasearch('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY').initIngestion({ region: 'us' });
// Call the API
const response = await client.push({
indexName: 'foo',
pushTaskPayload: {
action: 'addObject',
records: [
{ key: 'bar', foo: '1', objectID: 'o' },
{ key: 'baz', foo: '2', objectID: 'k' },
],
},
});
// print the response
console.log(response);
// Initialize the client
val client =
IngestionClient(
appId = "ALGOLIA_APPLICATION_ID",
apiKey = "ALGOLIA_API_KEY",
region = "ALGOLIA_APPLICATION_REGION",
)
// Call the API
var response =
client.push(
indexName = "<YOUR_INDEX_NAME>",
pushTaskPayload =
PushTaskPayload(
action = Action.entries.first { it.value == "addObject" },
records =
listOf(
PushTaskRecords(
objectID = "o",
additionalProperties =
mapOf("key" to JsonPrimitive("bar"), "foo" to JsonPrimitive("1")),
),
PushTaskRecords(
objectID = "k",
additionalProperties =
mapOf("key" to JsonPrimitive("baz"), "foo" to JsonPrimitive("2")),
),
),
),
)
// print the response
println(response)
// Initialize the client
$client = IngestionClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY', 'ALGOLIA_APPLICATION_REGION');
// Call the API
$response = $client->push(
'<YOUR_INDEX_NAME>',
['action' => 'addObject',
'records' => [
['key' => 'bar',
'foo' => '1',
'objectID' => 'o',
],
['key' => 'baz',
'foo' => '2',
'objectID' => 'k',
],
],
],
);
// print the response
var_dump($response);
# Initialize the client
# In an asynchronous context, you can use IngestionClient instead, which exposes the exact same methods.
client = IngestionClientSync(
"ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"
)
# Call the API
response = client.push(
index_name="<YOUR_INDEX_NAME>",
push_task_payload={
"action": "addObject",
"records": [
{
"key": "bar",
"foo": "1",
"objectID": "o",
},
{
"key": "baz",
"foo": "2",
"objectID": "k",
},
],
},
)
# print the response
print(response)
# Initialize the client
client = Algolia::IngestionClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")
# Call the API
response = client.push(
"<YOUR_INDEX_NAME>",
Algolia::Ingestion::PushTaskPayload.new(
action: "addObject",
records: [
Algolia::Ingestion::PushTaskRecords.new(key: "bar", foo: "1", algolia_object_id: "o"),
Algolia::Ingestion::PushTaskRecords.new(key: "baz", foo: "2", algolia_object_id: "k")
]
)
)
# print the response
puts(response)
// Initialize the client
val client = IngestionClient(
appId = "ALGOLIA_APPLICATION_ID",
apiKey = "ALGOLIA_API_KEY",
region = "ALGOLIA_APPLICATION_REGION"
)
// Call the API
val response = Await.result(
client.push(
indexName = "<YOUR_INDEX_NAME>",
pushTaskPayload = PushTaskPayload(
action = Action.withName("addObject"),
records = Seq(
PushTaskRecords(
objectID = "o",
additionalProperties = Some(List(JField("key", JString("bar")), JField("foo", JString("1"))))
),
PushTaskRecords(
objectID = "k",
additionalProperties = Some(List(JField("key", JString("baz")), JField("foo", JString("2"))))
)
)
)
),
Duration(100, "sec")
)
// print the response
println(response)
// Initialize the client
let client = try IngestionClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY", region: .us)
// Call the API
let response = try await client.push(
indexName: "<YOUR_INDEX_NAME>",
pushTaskPayload: PushTaskPayload(
action: IngestionAction.addObject,
records: [
PushTaskRecords(from: [
"objectID": AnyCodable("o"),
"key": AnyCodable("bar"),
"foo": AnyCodable("1"),
]),
PushTaskRecords(from: [
"objectID": AnyCodable("k"),
"key": AnyCodable("baz"),
"foo": AnyCodable("2"),
]),
]
)
)
// print the response
print(response)
See the full API reference
For more details about input parameters
and response fields.