Sep 25, 2025
Batch action to multiple compositions
Adds, updates, or deletes compositions with a single API request.
Usage
Required ACL:
editSettings
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using Algolia.Search.Clients;
using Algolia.Search.Http;
using Algolia.Search.Models.Composition;
var client = new CompositionClient(
new CompositionConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
);
var response = await client.MultipleBatchAsync(
new BatchParams
{
Requests = new List<MultipleBatchRequest>
{
new MultipleBatchRequest
{
Action = Enum.Parse<Action>("Upsert"),
Body = new BatchCompositionAction(
new Composition
{
ObjectID = "my-metadata-compo",
Name = "my composition",
Behavior = new CompositionBehavior
{
Injection = new Injection
{
Main = new Main
{
Source = new CompositionSource
{
Search = new CompositionSourceSearch
{
Index = "foo",
Params = new MainInjectionQueryParameters { Filters = "brand:adidas" },
},
},
},
InjectedItems = new List<InjectedItem>
{
new InjectedItem
{
Key = "injectedItem1",
Source = new InjectedItemSource(
new SearchSource
{
Search = new Algolia.Search.Models.Composition.Search
{
Index = "foo",
Params = new BaseInjectionQueryParameters
{
Filters = "brand:adidas",
},
},
}
),
Position = 2,
Length = 1,
Metadata = new InjectedItemMetadata
{
Hits = new InjectedItemHitsMetadata
{
AddItemKey = true,
Extra = new Dictionary<string, object>
{
{ "my-string", "string" },
{ "my-bool", true },
{ "my-number", 42 },
{
"my-object",
new Dictionary<string, object> { { "sub-key", "sub-value" } }
},
},
},
},
},
new InjectedItem
{
Key = "externalItem",
Source = new InjectedItemSource(
new SearchSource
{
Search = new Algolia.Search.Models.Composition.Search
{
Index = "foo",
Params = new BaseInjectionQueryParameters { Filters = "brand:puma" },
},
}
),
Position = 5,
Length = 5,
Metadata = new InjectedItemMetadata
{
Hits = new InjectedItemHitsMetadata
{
AddItemKey = true,
Extra = new Dictionary<string, object>
{
{ "my-string", "string" },
{ "my-bool", true },
{ "my-number", 42 },
{
"my-object",
new Dictionary<string, object> { { "sub-key", "sub-value" } }
},
},
},
},
},
},
},
},
}
),
},
},
}
);