curl --request PUT \
--url https://algolia_application_id.algolia.net/1/compositions/my_composition_object_id \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-algolia-api-key: ALGOLIA_API_KEY' \
--header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID' \
--data '
{
"objectID": "my_composition_object_id",
"name": "my lovely crafted composition",
"description": "my lovely crafted composition that is used for X purpose",
"behavior": {
"injection": {
"main": {
"source": {
"search": {
"index": "Products",
"params": {
"advancedSyntax": false,
"advancedSyntaxFeatures": [
"exactPhrase",
"excludeWords"
],
"allowTyposOnNumericTokens": true,
"alternativesAsExact": [
"ignorePlurals",
"singleWordSynonym"
],
"attributeCriteriaComputedByMinProximity": false,
"attributesToHighlight": [
"author",
"title",
"conten",
"content"
],
"attributesToRetrieve": [
"author",
"title",
"content"
],
"attributesToSnippet": [
"content:80",
"description"
],
"clickAnalytics": false,
"disableExactOnAttributes": [
"description"
],
"disableTypoToleranceOnAttributes": [
"sku"
],
"distinct": 1,
"enableABTest": true,
"enablePersonalization": false,
"enableReRanking": true,
"enableRules": true,
"exactOnSingleWordQuery": "attribute",
"facetFilters": [
[
"category:Book",
"category:-Movie"
],
"author:John Doe"
],
"filters": "(category:Book OR category:Ebook) AND _tags:published",
"getRankingInfo": false,
"highlightPostTag": "</em>",
"highlightPreTag": "<em>",
"ignorePlurals": [
"ca",
"es"
],
"minProximity": 1,
"minWordSizefor1Typo": 4,
"minWordSizefor2Typos": 8,
"naturalLanguages": [],
"numericFilters": [
[
"inStock = 1",
"deliveryDate < 1441755506"
],
"price < 1000"
],
"optionalFilters": [
"category:Book",
"author:John Doe"
],
"optionalWords": "lorem",
"percentileComputation": true,
"personalizationImpact": 100,
"queryLanguages": [
"es"
],
"queryType": "prefixLast",
"removeStopWords": [
"ca",
"es"
],
"removeWordsIfNoResults": "firstWords",
"replaceSynonymsInHighlight": false,
"responseFields": [
"*"
],
"restrictHighlightAndSnippetArrays": false,
"restrictSearchableAttributes": [
"title",
"author"
],
"ruleContexts": [
"mobile"
],
"snippetEllipsisText": "ā¦",
"synonyms": true,
"typoTolerance": true,
"facetingAfterDistinct": false,
"facets": [
"category",
"disjunctive(brand)",
"price"
],
"hitsPerPage": 20,
"maxValuesPerFacet": 100,
"renderingContent": {
"facetOrdering": {
"facets": {
"order": [
"lorem"
]
},
"values": {
"property1": {
"order": [
"lorem"
],
"sortRemainingBy": "count",
"hide": [
"lorem"
]
},
"property2": {
"order": [
"lorem"
],
"sortRemainingBy": "count",
"hide": [
"lorem"
]
}
}
},
"redirect": {
"url": "lorem"
},
"widgets": {
"banners": [
{
"image": {
"urls": [
{
"url": "lorem"
}
],
"title": "lorem"
},
"link": {
"url": "lorem"
}
}
]
}
},
"sortFacetValuesBy": "count",
"sumOrFiltersScores": false
}
}
}
},
"injectedItems": [
{
"key": "lorem",
"source": {
"search": {
"index": "Products",
"params": {
"advancedSyntax": false,
"advancedSyntaxFeatures": [
"exactPhrase",
"excludeWords"
],
"allowTyposOnNumericTokens": true,
"alternativesAsExact": [
"ignorePlurals",
"singleWordSynonym"
],
"attributeCriteriaComputedByMinProximity": false,
"attributesToHighlight": [
"author",
"title",
"conten",
"content"
],
"attributesToRetrieve": [
"author",
"title",
"content"
],
"attributesToSnippet": [
"content:80",
"description"
],
"clickAnalytics": false,
"disableExactOnAttributes": [
"description"
],
"disableTypoToleranceOnAttributes": [
"sku"
],
"distinct": 1,
"enableABTest": true,
"enablePersonalization": false,
"enableReRanking": true,
"enableRules": true,
"exactOnSingleWordQuery": "attribute",
"facetFilters": [
[
"category:Book",
"category:-Movie"
],
"author:John Doe"
],
"filters": "(category:Book OR category:Ebook) AND _tags:published",
"getRankingInfo": false,
"highlightPostTag": "</em>",
"highlightPreTag": "<em>",
"ignorePlurals": [
"ca",
"es"
],
"minProximity": 1,
"minWordSizefor1Typo": 4,
"minWordSizefor2Typos": 8,
"naturalLanguages": [],
"numericFilters": [
[
"inStock = 1",
"deliveryDate < 1441755506"
],
"price < 1000"
],
"optionalFilters": [
"category:Book",
"author:John Doe"
],
"optionalWords": "lorem",
"percentileComputation": true,
"personalizationImpact": 100,
"queryLanguages": [
"es"
],
"queryType": "prefixLast",
"removeStopWords": [
"ca",
"es"
],
"removeWordsIfNoResults": "firstWords",
"replaceSynonymsInHighlight": false,
"responseFields": [
"*"
],
"restrictHighlightAndSnippetArrays": false,
"restrictSearchableAttributes": [
"title",
"author"
],
"ruleContexts": [
"mobile"
],
"snippetEllipsisText": "ā¦",
"synonyms": true,
"typoTolerance": true
}
}
},
"position": 0,
"length": 0,
"metadata": {
"hits": {
"addItemKey": true,
"extra": {}
}
}
}
],
"deduplication": {
"positioning": "highest"
}
}
},
"sortingStrategy": {
"Price (asc)": "products-low-to-high",
"Price (desc)": "products-high-to-low"
}
}
'// Initialize the client
var client = new CompositionClient(
new CompositionConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
);
// Call the API
var response = await client.PutCompositionAsync(
"my-compo",
new Composition
{
ObjectID = "my-compo",
Name = "my composition",
Behavior = new CompositionBehavior(
new CompositionMultifeedBehavior
{
Multifeed = new Multifeed
{
Feeds = new Dictionary<string, FeedInjection>
{
{
"products",
new FeedInjection
{
Injection = new Injection
{
Main = new InjectionMain
{
Source = new InjectionMainSource(
new InjectionMainSearchSource
{
Search = new MainSearch
{
Index = "products",
Params = new MainInjectionQueryParameters { HitsPerPage = 12 },
},
}
),
},
InjectedItems = new List<InjectionInjectedItem>
{
new InjectionInjectedItem
{
Key = "featured-products",
Source = new InjectedItemSource(
new InjectedItemSearchSource
{
Search = new InjectedItemSearch
{
Index = "products",
Params = new BaseInjectionQueryParameters
{
Filters = "featured:true",
},
},
}
),
Position = 0,
Length = 2,
},
},
},
}
},
{
"articles",
new FeedInjection
{
Injection = new Injection
{
Main = new InjectionMain
{
Source = new InjectionMainSource(
new InjectionMainSearchSource
{
Search = new MainSearch
{
Index = "articles",
Params = new MainInjectionQueryParameters
{
HitsPerPage = 5,
AttributesToRetrieve = new List<string>
{
"title",
"excerpt",
"publishedAt",
},
},
},
}
),
},
InjectedItems = new List<InjectionInjectedItem>
{
new InjectionInjectedItem
{
Key = "editorial-picks",
Source = new InjectedItemSource(
new InjectedItemSearchSource
{
Search = new InjectedItemSearch
{
Index = "articles",
Params = new BaseInjectionQueryParameters
{
Filters = "editorial_pick:true",
},
},
}
),
Position = 0,
Length = 1,
},
},
},
}
},
{
"videos",
new FeedInjection
{
Injection = new Injection
{
Main = new InjectionMain
{
Source = new InjectionMainSource(
new InjectionMainSearchSource
{
Search = new MainSearch
{
Index = "videos",
Params = new MainInjectionQueryParameters
{
HitsPerPage = 3,
AttributesToRetrieve = new List<string>
{
"title",
"thumbnail",
"duration",
},
},
},
}
),
},
},
}
},
},
FeedsOrder = new List<string> { "products", "articles", "videos" },
},
}
),
}
);
// print the response
Console.WriteLine(response);// Initialize the client
final client = CompositionClient(
appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');
// Call the API
final response = await client.putComposition(
compositionID: "my-compo",
composition: Composition(
objectID: "my-compo",
name: "my composition",
behavior: CompositionMultifeedBehavior(
multifeed: Multifeed(
feeds: {
'products': FeedInjection(
injection: Injection(
main: InjectionMain(
source: InjectionMainSearchSource(
search: MainSearch(
index: "products",
params: MainInjectionQueryParameters(
hitsPerPage: 12,
),
),
),
),
injectedItems: [
InjectionInjectedItem(
key: "featured-products",
source: InjectedItemSearchSource(
search: InjectedItemSearch(
index: "products",
params: BaseInjectionQueryParameters(
filters: "featured:true",
),
),
),
position: 0,
length: 2,
),
],
),
),
'articles': FeedInjection(
injection: Injection(
main: InjectionMain(
source: InjectionMainSearchSource(
search: MainSearch(
index: "articles",
params: MainInjectionQueryParameters(
hitsPerPage: 5,
attributesToRetrieve: [
"title",
"excerpt",
"publishedAt",
],
),
),
),
),
injectedItems: [
InjectionInjectedItem(
key: "editorial-picks",
source: InjectedItemSearchSource(
search: InjectedItemSearch(
index: "articles",
params: BaseInjectionQueryParameters(
filters: "editorial_pick:true",
),
),
),
position: 0,
length: 1,
),
],
),
),
'videos': FeedInjection(
injection: Injection(
main: InjectionMain(
source: InjectionMainSearchSource(
search: MainSearch(
index: "videos",
params: MainInjectionQueryParameters(
hitsPerPage: 3,
attributesToRetrieve: [
"title",
"thumbnail",
"duration",
],
),
),
),
),
),
),
},
feedsOrder: [
"products",
"articles",
"videos",
],
),
),
),
);
// print the response
print(response);// Initialize the client
client, err := composition.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
// Call the API
response, err := client.PutComposition(client.NewApiPutCompositionRequest(
"my-compo",
composition.NewEmptyComposition().
SetObjectID("my-compo").
SetName("my composition").
SetBehavior(composition.CompositionMultifeedBehaviorAsCompositionBehavior(
composition.NewEmptyCompositionMultifeedBehavior().SetMultifeed(
composition.NewEmptyMultifeed().
SetFeeds(map[string]composition.FeedInjection{"products": *composition.NewEmptyFeedInjection().SetInjection(
composition.NewEmptyInjection().SetMain(
composition.NewEmptyInjectionMain().SetSource(composition.InjectionMainSearchSourceAsInjectionMainSource(
composition.NewEmptyInjectionMainSearchSource().SetSearch(
composition.NewEmptyMainSearch().SetIndex("products").SetParams(
composition.NewEmptyMainInjectionQueryParameters().SetHitsPerPage(12)))))).SetInjectedItems(
[]composition.InjectionInjectedItem{*composition.NewEmptyInjectionInjectedItem().SetKey("featured-products").SetSource(composition.InjectedItemSearchSourceAsInjectedItemSource(
composition.NewEmptyInjectedItemSearchSource().SetSearch(
composition.NewEmptyInjectedItemSearch().SetIndex("products").SetParams(
composition.NewEmptyBaseInjectionQueryParameters().SetFilters("featured:true"))))).SetPosition(0).SetLength(2)})), "articles": *composition.NewEmptyFeedInjection().SetInjection(
composition.NewEmptyInjection().SetMain(
composition.NewEmptyInjectionMain().SetSource(composition.InjectionMainSearchSourceAsInjectionMainSource(
composition.NewEmptyInjectionMainSearchSource().SetSearch(
composition.NewEmptyMainSearch().SetIndex("articles").SetParams(
composition.NewEmptyMainInjectionQueryParameters().SetHitsPerPage(5).SetAttributesToRetrieve(
[]string{"title", "excerpt", "publishedAt"})))))).SetInjectedItems(
[]composition.InjectionInjectedItem{*composition.NewEmptyInjectionInjectedItem().SetKey("editorial-picks").SetSource(composition.InjectedItemSearchSourceAsInjectedItemSource(
composition.NewEmptyInjectedItemSearchSource().SetSearch(
composition.NewEmptyInjectedItemSearch().SetIndex("articles").SetParams(
composition.NewEmptyBaseInjectionQueryParameters().SetFilters("editorial_pick:true"))))).SetPosition(0).SetLength(1)})), "videos": *composition.NewEmptyFeedInjection().SetInjection(
composition.NewEmptyInjection().SetMain(
composition.NewEmptyInjectionMain().SetSource(composition.InjectionMainSearchSourceAsInjectionMainSource(
composition.NewEmptyInjectionMainSearchSource().SetSearch(
composition.NewEmptyMainSearch().SetIndex("videos").SetParams(
composition.NewEmptyMainInjectionQueryParameters().SetHitsPerPage(3).SetAttributesToRetrieve(
[]string{"title", "thumbnail", "duration"})))))))}).
SetFeedsOrder(
[]string{"products", "articles", "videos"}),
),
)),
))
if err != nil {
// handle the eventual error
panic(err)
}
// print the response
print(response)// Initialize the client
CompositionClient client = new CompositionClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
// Call the API
TaskIDResponse response = client.putComposition(
"my-compo",
new Composition()
.setObjectID("my-compo")
.setName("my composition")
.setBehavior(
new CompositionMultifeedBehavior().setMultifeed(
new Multifeed()
.setFeeds(
new HashMap() {
{
put(
"products",
new FeedInjection().setInjection(
new Injection()
.setMain(
new InjectionMain().setSource(
new InjectionMainSearchSource().setSearch(
new MainSearch().setIndex("products").setParams(new MainInjectionQueryParameters().setHitsPerPage(12))
)
)
)
.setInjectedItems(
Arrays.asList(
new InjectionInjectedItem()
.setKey("featured-products")
.setSource(
new InjectedItemSearchSource().setSearch(
new InjectedItemSearch()
.setIndex("products")
.setParams(new BaseInjectionQueryParameters().setFilters("featured:true"))
)
)
.setPosition(0)
.setLength(2)
)
)
)
);
put(
"articles",
new FeedInjection().setInjection(
new Injection()
.setMain(
new InjectionMain().setSource(
new InjectionMainSearchSource().setSearch(
new MainSearch()
.setIndex("articles")
.setParams(
new MainInjectionQueryParameters()
.setHitsPerPage(5)
.setAttributesToRetrieve(Arrays.asList("title", "excerpt", "publishedAt"))
)
)
)
)
.setInjectedItems(
Arrays.asList(
new InjectionInjectedItem()
.setKey("editorial-picks")
.setSource(
new InjectedItemSearchSource().setSearch(
new InjectedItemSearch()
.setIndex("articles")
.setParams(new BaseInjectionQueryParameters().setFilters("editorial_pick:true"))
)
)
.setPosition(0)
.setLength(1)
)
)
)
);
put(
"videos",
new FeedInjection().setInjection(
new Injection().setMain(
new InjectionMain().setSource(
new InjectionMainSearchSource().setSearch(
new MainSearch()
.setIndex("videos")
.setParams(
new MainInjectionQueryParameters()
.setHitsPerPage(3)
.setAttributesToRetrieve(Arrays.asList("title", "thumbnail", "duration"))
)
)
)
)
)
);
}
}
)
.setFeedsOrder(Arrays.asList("products", "articles", "videos"))
)
)
);
// print the response
System.out.println(response);// Initialize the client
const client = compositionClient('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
const response = await client.putComposition({
compositionID: 'my-compo',
composition: {
objectID: 'my-compo',
name: 'my composition',
behavior: {
multifeed: {
feeds: {
products: {
injection: {
main: { source: { search: { index: 'products', params: { hitsPerPage: 12 } } } },
injectedItems: [
{
key: 'featured-products',
source: { search: { index: 'products', params: { filters: 'featured:true' } } },
position: 0,
length: 2,
},
],
},
},
articles: {
injection: {
main: {
source: {
search: {
index: 'articles',
params: { hitsPerPage: 5, attributesToRetrieve: ['title', 'excerpt', 'publishedAt'] },
},
},
},
injectedItems: [
{
key: 'editorial-picks',
source: { search: { index: 'articles', params: { filters: 'editorial_pick:true' } } },
position: 0,
length: 1,
},
],
},
},
videos: {
injection: {
main: {
source: {
search: {
index: 'videos',
params: { hitsPerPage: 3, attributesToRetrieve: ['title', 'thumbnail', 'duration'] },
},
},
},
},
},
},
feedsOrder: ['products', 'articles', 'videos'],
},
},
},
});
// print the response
console.log(response);// Initialize the client
val client = CompositionClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
var response =
client.putComposition(
compositionID = "my-compo",
composition =
Composition(
objectID = "my-compo",
name = "my composition",
behavior =
CompositionMultifeedBehavior(
multifeed =
Multifeed(
feeds =
mapOf(
"products" to
FeedInjection(
injection =
Injection(
main =
InjectionMain(
source =
InjectionMainSearchSource(
search =
MainSearch(
index = "products",
params = MainInjectionQueryParameters(hitsPerPage = 12),
)
)
),
injectedItems =
listOf(
InjectionInjectedItem(
key = "featured-products",
source =
InjectedItemSearchSource(
search =
InjectedItemSearch(
index = "products",
params =
BaseInjectionQueryParameters(
filters = "featured:true"
),
)
),
position = 0,
length = 2,
)
),
)
),
"articles" to
FeedInjection(
injection =
Injection(
main =
InjectionMain(
source =
InjectionMainSearchSource(
search =
MainSearch(
index = "articles",
params =
MainInjectionQueryParameters(
hitsPerPage = 5,
attributesToRetrieve =
listOf("title", "excerpt", "publishedAt"),
),
)
)
),
injectedItems =
listOf(
InjectionInjectedItem(
key = "editorial-picks",
source =
InjectedItemSearchSource(
search =
InjectedItemSearch(
index = "articles",
params =
BaseInjectionQueryParameters(
filters = "editorial_pick:true"
),
)
),
position = 0,
length = 1,
)
),
)
),
"videos" to
FeedInjection(
injection =
Injection(
main =
InjectionMain(
source =
InjectionMainSearchSource(
search =
MainSearch(
index = "videos",
params =
MainInjectionQueryParameters(
hitsPerPage = 3,
attributesToRetrieve =
listOf("title", "thumbnail", "duration"),
),
)
)
)
)
),
),
feedsOrder = listOf("products", "articles", "videos"),
)
),
),
)
// print the response
println(response)// Initialize the client
$client = CompositionClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
$response = $client->putComposition(
'my-compo',
['objectID' => 'my-compo',
'name' => 'my composition',
'behavior' => ['multifeed' => ['feeds' => ['products' => ['injection' => ['main' => ['source' => ['search' => ['index' => 'products',
'params' => ['hitsPerPage' => 12,
],
],
],
],
'injectedItems' => [
['key' => 'featured-products',
'source' => ['search' => ['index' => 'products',
'params' => ['filters' => 'featured:true',
],
],
],
'position' => 0,
'length' => 2,
],
],
],
],
'articles' => ['injection' => ['main' => ['source' => ['search' => ['index' => 'articles',
'params' => ['hitsPerPage' => 5,
'attributesToRetrieve' => [
'title',
'excerpt',
'publishedAt',
],
],
],
],
],
'injectedItems' => [
['key' => 'editorial-picks',
'source' => ['search' => ['index' => 'articles',
'params' => ['filters' => 'editorial_pick:true',
],
],
],
'position' => 0,
'length' => 1,
],
],
],
],
'videos' => ['injection' => ['main' => ['source' => ['search' => ['index' => 'videos',
'params' => ['hitsPerPage' => 3,
'attributesToRetrieve' => [
'title',
'thumbnail',
'duration',
],
],
],
],
],
],
],
],
'feedsOrder' => [
'products',
'articles',
'videos',
],
],
],
],
);
// print the response
var_dump($response);# Initialize the client
# In an asynchronous context, you can use CompositionClient instead, which exposes the exact same methods.
client = CompositionClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.put_composition(
composition_id="my-compo",
composition={
"objectID": "my-compo",
"name": "my composition",
"behavior": {
"multifeed": {
"feeds": {
"products": {
"injection": {
"main": {
"source": {
"search": {
"index": "products",
"params": {
"hitsPerPage": 12,
},
},
},
},
"injectedItems": [
{
"key": "featured-products",
"source": {
"search": {
"index": "products",
"params": {
"filters": "featured:true",
},
},
},
"position": 0,
"length": 2,
},
],
},
},
"articles": {
"injection": {
"main": {
"source": {
"search": {
"index": "articles",
"params": {
"hitsPerPage": 5,
"attributesToRetrieve": [
"title",
"excerpt",
"publishedAt",
],
},
},
},
},
"injectedItems": [
{
"key": "editorial-picks",
"source": {
"search": {
"index": "articles",
"params": {
"filters": "editorial_pick:true",
},
},
},
"position": 0,
"length": 1,
},
],
},
},
"videos": {
"injection": {
"main": {
"source": {
"search": {
"index": "videos",
"params": {
"hitsPerPage": 3,
"attributesToRetrieve": [
"title",
"thumbnail",
"duration",
],
},
},
},
},
},
},
},
"feedsOrder": [
"products",
"articles",
"videos",
],
},
},
},
)
# print the response
print(response)# Initialize the client
client = Algolia::CompositionClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.put_composition(
"my-compo",
Algolia::Composition::Composition.new(
algolia_object_id: "my-compo",
name: "my composition",
behavior: Algolia::Composition::CompositionMultifeedBehavior.new(
multifeed: Algolia::Composition::Multifeed.new(
feeds: {
products: Algolia::Composition::FeedInjection.new(
injection: Algolia::Composition::Injection.new(
main: Algolia::Composition::InjectionMain.new(
source: Algolia::Composition::InjectionMainSearchSource.new(
search: Algolia::Composition::MainSearch.new(
index: "products",
params: Algolia::Composition::MainInjectionQueryParameters.new(hits_per_page: 12)
)
)
),
injected_items: [
Algolia::Composition::InjectionInjectedItem.new(
key: "featured-products",
source: Algolia::Composition::InjectedItemSearchSource.new(
search: Algolia::Composition::InjectedItemSearch.new(
index: "products",
params: Algolia::Composition::BaseInjectionQueryParameters.new(filters: "featured:true")
)
),
position: 0,
length: 2
)
]
)
),
articles: Algolia::Composition::FeedInjection.new(
injection: Algolia::Composition::Injection.new(
main: Algolia::Composition::InjectionMain.new(
source: Algolia::Composition::InjectionMainSearchSource.new(
search: Algolia::Composition::MainSearch.new(
index: "articles",
params: Algolia::Composition::MainInjectionQueryParameters.new(
hits_per_page: 5,
attributes_to_retrieve: ["title", "excerpt", "publishedAt"]
)
)
)
),
injected_items: [
Algolia::Composition::InjectionInjectedItem.new(
key: "editorial-picks",
source: Algolia::Composition::InjectedItemSearchSource.new(
search: Algolia::Composition::InjectedItemSearch.new(
index: "articles",
params: Algolia::Composition::BaseInjectionQueryParameters.new(filters: "editorial_pick:true")
)
),
position: 0,
length: 1
)
]
)
),
videos: Algolia::Composition::FeedInjection.new(
injection: Algolia::Composition::Injection.new(
main: Algolia::Composition::InjectionMain.new(
source: Algolia::Composition::InjectionMainSearchSource.new(
search: Algolia::Composition::MainSearch.new(
index: "videos",
params: Algolia::Composition::MainInjectionQueryParameters.new(
hits_per_page: 3,
attributes_to_retrieve: ["title", "thumbnail", "duration"]
)
)
)
)
)
)
},
feeds_order: ["products", "articles", "videos"]
)
)
)
)
# print the response
puts(response)// Initialize the client
val client = CompositionClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
val response = Await.result(
client.putComposition(
compositionID = "my-compo",
composition = Composition(
objectID = "my-compo",
name = "my composition",
behavior = CompositionMultifeedBehavior(
multifeed = Multifeed(
feeds = Map(
"products" -> FeedInjection(
injection = Injection(
main = InjectionMain(
source = Some(
InjectionMainSearchSource(
search = MainSearch(
index = "products",
params = Some(
MainInjectionQueryParameters(
hitsPerPage = Some(12)
)
)
)
)
)
),
injectedItems = Some(
Seq(
InjectionInjectedItem(
key = "featured-products",
source = InjectedItemSearchSource(
search = InjectedItemSearch(
index = "products",
params = Some(
BaseInjectionQueryParameters(
filters = Some("featured:true")
)
)
)
),
position = 0,
length = 2
)
)
)
)
),
"articles" -> FeedInjection(
injection = Injection(
main = InjectionMain(
source = Some(
InjectionMainSearchSource(
search = MainSearch(
index = "articles",
params = Some(
MainInjectionQueryParameters(
hitsPerPage = Some(5),
attributesToRetrieve = Some(Seq("title", "excerpt", "publishedAt"))
)
)
)
)
)
),
injectedItems = Some(
Seq(
InjectionInjectedItem(
key = "editorial-picks",
source = InjectedItemSearchSource(
search = InjectedItemSearch(
index = "articles",
params = Some(
BaseInjectionQueryParameters(
filters = Some("editorial_pick:true")
)
)
)
),
position = 0,
length = 1
)
)
)
)
),
"videos" -> FeedInjection(
injection = Injection(
main = InjectionMain(
source = Some(
InjectionMainSearchSource(
search = MainSearch(
index = "videos",
params = Some(
MainInjectionQueryParameters(
hitsPerPage = Some(3),
attributesToRetrieve = Some(Seq("title", "thumbnail", "duration"))
)
)
)
)
)
)
)
)
),
feedsOrder = Some(Seq("products", "articles", "videos"))
)
)
)
),
Duration(100, "sec")
)
// print the response
println(response)// Initialize the client
let client = try CompositionClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")
// Call the API
let response = try await client.putComposition(
compositionID: "my-compo",
composition: Composition(
objectID: "my-compo",
name: "my composition",
behavior: CompositionBehavior
.compositionMultifeedBehavior(CompositionMultifeedBehavior(multifeed: Multifeed(
feeds: [
"products": FeedInjection(injection: Injection(
main: InjectionMain(source: InjectionMainSource
.injectionMainSearchSource(InjectionMainSearchSource(search: MainSearch(
index: "products",
params: MainInjectionQueryParameters(hitsPerPage: 12)
)))),
injectedItems: [InjectionInjectedItem(
key: "featured-products",
source: InjectedItemSource
.injectedItemSearchSource(InjectedItemSearchSource(search: InjectedItemSearch(
index: "products",
params: BaseInjectionQueryParameters(filters: "featured:true")
))),
position: 0,
length: 2
)]
)),
"articles": FeedInjection(injection: Injection(
main: InjectionMain(source: InjectionMainSource
.injectionMainSearchSource(InjectionMainSearchSource(search: MainSearch(
index: "articles",
params: MainInjectionQueryParameters(
attributesToRetrieve: ["title", "excerpt", "publishedAt"],
hitsPerPage: 5
)
)))),
injectedItems: [InjectionInjectedItem(
key: "editorial-picks",
source: InjectedItemSource
.injectedItemSearchSource(InjectedItemSearchSource(search: InjectedItemSearch(
index: "articles",
params: BaseInjectionQueryParameters(filters: "editorial_pick:true")
))),
position: 0,
length: 1
)]
)),
"videos": FeedInjection(injection: Injection(main: InjectionMain(source: InjectionMainSource
.injectionMainSearchSource(InjectionMainSearchSource(search: MainSearch(
index: "videos",
params: MainInjectionQueryParameters(
attributesToRetrieve: ["title", "thumbnail", "duration"],
hitsPerPage: 3
)
)))))),
],
feedsOrder: ["products", "articles", "videos"]
)))
)
)
// print the response
print(response){
"taskID": 1514562690001
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}Update and insert (upsert) a composition
Update and insert a composition in the current Algolia application.
curl --request PUT \
--url https://algolia_application_id.algolia.net/1/compositions/my_composition_object_id \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-algolia-api-key: ALGOLIA_API_KEY' \
--header 'x-algolia-application-id: ALGOLIA_APPLICATION_ID' \
--data '
{
"objectID": "my_composition_object_id",
"name": "my lovely crafted composition",
"description": "my lovely crafted composition that is used for X purpose",
"behavior": {
"injection": {
"main": {
"source": {
"search": {
"index": "Products",
"params": {
"advancedSyntax": false,
"advancedSyntaxFeatures": [
"exactPhrase",
"excludeWords"
],
"allowTyposOnNumericTokens": true,
"alternativesAsExact": [
"ignorePlurals",
"singleWordSynonym"
],
"attributeCriteriaComputedByMinProximity": false,
"attributesToHighlight": [
"author",
"title",
"conten",
"content"
],
"attributesToRetrieve": [
"author",
"title",
"content"
],
"attributesToSnippet": [
"content:80",
"description"
],
"clickAnalytics": false,
"disableExactOnAttributes": [
"description"
],
"disableTypoToleranceOnAttributes": [
"sku"
],
"distinct": 1,
"enableABTest": true,
"enablePersonalization": false,
"enableReRanking": true,
"enableRules": true,
"exactOnSingleWordQuery": "attribute",
"facetFilters": [
[
"category:Book",
"category:-Movie"
],
"author:John Doe"
],
"filters": "(category:Book OR category:Ebook) AND _tags:published",
"getRankingInfo": false,
"highlightPostTag": "</em>",
"highlightPreTag": "<em>",
"ignorePlurals": [
"ca",
"es"
],
"minProximity": 1,
"minWordSizefor1Typo": 4,
"minWordSizefor2Typos": 8,
"naturalLanguages": [],
"numericFilters": [
[
"inStock = 1",
"deliveryDate < 1441755506"
],
"price < 1000"
],
"optionalFilters": [
"category:Book",
"author:John Doe"
],
"optionalWords": "lorem",
"percentileComputation": true,
"personalizationImpact": 100,
"queryLanguages": [
"es"
],
"queryType": "prefixLast",
"removeStopWords": [
"ca",
"es"
],
"removeWordsIfNoResults": "firstWords",
"replaceSynonymsInHighlight": false,
"responseFields": [
"*"
],
"restrictHighlightAndSnippetArrays": false,
"restrictSearchableAttributes": [
"title",
"author"
],
"ruleContexts": [
"mobile"
],
"snippetEllipsisText": "ā¦",
"synonyms": true,
"typoTolerance": true,
"facetingAfterDistinct": false,
"facets": [
"category",
"disjunctive(brand)",
"price"
],
"hitsPerPage": 20,
"maxValuesPerFacet": 100,
"renderingContent": {
"facetOrdering": {
"facets": {
"order": [
"lorem"
]
},
"values": {
"property1": {
"order": [
"lorem"
],
"sortRemainingBy": "count",
"hide": [
"lorem"
]
},
"property2": {
"order": [
"lorem"
],
"sortRemainingBy": "count",
"hide": [
"lorem"
]
}
}
},
"redirect": {
"url": "lorem"
},
"widgets": {
"banners": [
{
"image": {
"urls": [
{
"url": "lorem"
}
],
"title": "lorem"
},
"link": {
"url": "lorem"
}
}
]
}
},
"sortFacetValuesBy": "count",
"sumOrFiltersScores": false
}
}
}
},
"injectedItems": [
{
"key": "lorem",
"source": {
"search": {
"index": "Products",
"params": {
"advancedSyntax": false,
"advancedSyntaxFeatures": [
"exactPhrase",
"excludeWords"
],
"allowTyposOnNumericTokens": true,
"alternativesAsExact": [
"ignorePlurals",
"singleWordSynonym"
],
"attributeCriteriaComputedByMinProximity": false,
"attributesToHighlight": [
"author",
"title",
"conten",
"content"
],
"attributesToRetrieve": [
"author",
"title",
"content"
],
"attributesToSnippet": [
"content:80",
"description"
],
"clickAnalytics": false,
"disableExactOnAttributes": [
"description"
],
"disableTypoToleranceOnAttributes": [
"sku"
],
"distinct": 1,
"enableABTest": true,
"enablePersonalization": false,
"enableReRanking": true,
"enableRules": true,
"exactOnSingleWordQuery": "attribute",
"facetFilters": [
[
"category:Book",
"category:-Movie"
],
"author:John Doe"
],
"filters": "(category:Book OR category:Ebook) AND _tags:published",
"getRankingInfo": false,
"highlightPostTag": "</em>",
"highlightPreTag": "<em>",
"ignorePlurals": [
"ca",
"es"
],
"minProximity": 1,
"minWordSizefor1Typo": 4,
"minWordSizefor2Typos": 8,
"naturalLanguages": [],
"numericFilters": [
[
"inStock = 1",
"deliveryDate < 1441755506"
],
"price < 1000"
],
"optionalFilters": [
"category:Book",
"author:John Doe"
],
"optionalWords": "lorem",
"percentileComputation": true,
"personalizationImpact": 100,
"queryLanguages": [
"es"
],
"queryType": "prefixLast",
"removeStopWords": [
"ca",
"es"
],
"removeWordsIfNoResults": "firstWords",
"replaceSynonymsInHighlight": false,
"responseFields": [
"*"
],
"restrictHighlightAndSnippetArrays": false,
"restrictSearchableAttributes": [
"title",
"author"
],
"ruleContexts": [
"mobile"
],
"snippetEllipsisText": "ā¦",
"synonyms": true,
"typoTolerance": true
}
}
},
"position": 0,
"length": 0,
"metadata": {
"hits": {
"addItemKey": true,
"extra": {}
}
}
}
],
"deduplication": {
"positioning": "highest"
}
}
},
"sortingStrategy": {
"Price (asc)": "products-low-to-high",
"Price (desc)": "products-high-to-low"
}
}
'// Initialize the client
var client = new CompositionClient(
new CompositionConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
);
// Call the API
var response = await client.PutCompositionAsync(
"my-compo",
new Composition
{
ObjectID = "my-compo",
Name = "my composition",
Behavior = new CompositionBehavior(
new CompositionMultifeedBehavior
{
Multifeed = new Multifeed
{
Feeds = new Dictionary<string, FeedInjection>
{
{
"products",
new FeedInjection
{
Injection = new Injection
{
Main = new InjectionMain
{
Source = new InjectionMainSource(
new InjectionMainSearchSource
{
Search = new MainSearch
{
Index = "products",
Params = new MainInjectionQueryParameters { HitsPerPage = 12 },
},
}
),
},
InjectedItems = new List<InjectionInjectedItem>
{
new InjectionInjectedItem
{
Key = "featured-products",
Source = new InjectedItemSource(
new InjectedItemSearchSource
{
Search = new InjectedItemSearch
{
Index = "products",
Params = new BaseInjectionQueryParameters
{
Filters = "featured:true",
},
},
}
),
Position = 0,
Length = 2,
},
},
},
}
},
{
"articles",
new FeedInjection
{
Injection = new Injection
{
Main = new InjectionMain
{
Source = new InjectionMainSource(
new InjectionMainSearchSource
{
Search = new MainSearch
{
Index = "articles",
Params = new MainInjectionQueryParameters
{
HitsPerPage = 5,
AttributesToRetrieve = new List<string>
{
"title",
"excerpt",
"publishedAt",
},
},
},
}
),
},
InjectedItems = new List<InjectionInjectedItem>
{
new InjectionInjectedItem
{
Key = "editorial-picks",
Source = new InjectedItemSource(
new InjectedItemSearchSource
{
Search = new InjectedItemSearch
{
Index = "articles",
Params = new BaseInjectionQueryParameters
{
Filters = "editorial_pick:true",
},
},
}
),
Position = 0,
Length = 1,
},
},
},
}
},
{
"videos",
new FeedInjection
{
Injection = new Injection
{
Main = new InjectionMain
{
Source = new InjectionMainSource(
new InjectionMainSearchSource
{
Search = new MainSearch
{
Index = "videos",
Params = new MainInjectionQueryParameters
{
HitsPerPage = 3,
AttributesToRetrieve = new List<string>
{
"title",
"thumbnail",
"duration",
},
},
},
}
),
},
},
}
},
},
FeedsOrder = new List<string> { "products", "articles", "videos" },
},
}
),
}
);
// print the response
Console.WriteLine(response);// Initialize the client
final client = CompositionClient(
appId: 'ALGOLIA_APPLICATION_ID', apiKey: 'ALGOLIA_API_KEY');
// Call the API
final response = await client.putComposition(
compositionID: "my-compo",
composition: Composition(
objectID: "my-compo",
name: "my composition",
behavior: CompositionMultifeedBehavior(
multifeed: Multifeed(
feeds: {
'products': FeedInjection(
injection: Injection(
main: InjectionMain(
source: InjectionMainSearchSource(
search: MainSearch(
index: "products",
params: MainInjectionQueryParameters(
hitsPerPage: 12,
),
),
),
),
injectedItems: [
InjectionInjectedItem(
key: "featured-products",
source: InjectedItemSearchSource(
search: InjectedItemSearch(
index: "products",
params: BaseInjectionQueryParameters(
filters: "featured:true",
),
),
),
position: 0,
length: 2,
),
],
),
),
'articles': FeedInjection(
injection: Injection(
main: InjectionMain(
source: InjectionMainSearchSource(
search: MainSearch(
index: "articles",
params: MainInjectionQueryParameters(
hitsPerPage: 5,
attributesToRetrieve: [
"title",
"excerpt",
"publishedAt",
],
),
),
),
),
injectedItems: [
InjectionInjectedItem(
key: "editorial-picks",
source: InjectedItemSearchSource(
search: InjectedItemSearch(
index: "articles",
params: BaseInjectionQueryParameters(
filters: "editorial_pick:true",
),
),
),
position: 0,
length: 1,
),
],
),
),
'videos': FeedInjection(
injection: Injection(
main: InjectionMain(
source: InjectionMainSearchSource(
search: MainSearch(
index: "videos",
params: MainInjectionQueryParameters(
hitsPerPage: 3,
attributesToRetrieve: [
"title",
"thumbnail",
"duration",
],
),
),
),
),
),
),
},
feedsOrder: [
"products",
"articles",
"videos",
],
),
),
),
);
// print the response
print(response);// Initialize the client
client, err := composition.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
// Call the API
response, err := client.PutComposition(client.NewApiPutCompositionRequest(
"my-compo",
composition.NewEmptyComposition().
SetObjectID("my-compo").
SetName("my composition").
SetBehavior(composition.CompositionMultifeedBehaviorAsCompositionBehavior(
composition.NewEmptyCompositionMultifeedBehavior().SetMultifeed(
composition.NewEmptyMultifeed().
SetFeeds(map[string]composition.FeedInjection{"products": *composition.NewEmptyFeedInjection().SetInjection(
composition.NewEmptyInjection().SetMain(
composition.NewEmptyInjectionMain().SetSource(composition.InjectionMainSearchSourceAsInjectionMainSource(
composition.NewEmptyInjectionMainSearchSource().SetSearch(
composition.NewEmptyMainSearch().SetIndex("products").SetParams(
composition.NewEmptyMainInjectionQueryParameters().SetHitsPerPage(12)))))).SetInjectedItems(
[]composition.InjectionInjectedItem{*composition.NewEmptyInjectionInjectedItem().SetKey("featured-products").SetSource(composition.InjectedItemSearchSourceAsInjectedItemSource(
composition.NewEmptyInjectedItemSearchSource().SetSearch(
composition.NewEmptyInjectedItemSearch().SetIndex("products").SetParams(
composition.NewEmptyBaseInjectionQueryParameters().SetFilters("featured:true"))))).SetPosition(0).SetLength(2)})), "articles": *composition.NewEmptyFeedInjection().SetInjection(
composition.NewEmptyInjection().SetMain(
composition.NewEmptyInjectionMain().SetSource(composition.InjectionMainSearchSourceAsInjectionMainSource(
composition.NewEmptyInjectionMainSearchSource().SetSearch(
composition.NewEmptyMainSearch().SetIndex("articles").SetParams(
composition.NewEmptyMainInjectionQueryParameters().SetHitsPerPage(5).SetAttributesToRetrieve(
[]string{"title", "excerpt", "publishedAt"})))))).SetInjectedItems(
[]composition.InjectionInjectedItem{*composition.NewEmptyInjectionInjectedItem().SetKey("editorial-picks").SetSource(composition.InjectedItemSearchSourceAsInjectedItemSource(
composition.NewEmptyInjectedItemSearchSource().SetSearch(
composition.NewEmptyInjectedItemSearch().SetIndex("articles").SetParams(
composition.NewEmptyBaseInjectionQueryParameters().SetFilters("editorial_pick:true"))))).SetPosition(0).SetLength(1)})), "videos": *composition.NewEmptyFeedInjection().SetInjection(
composition.NewEmptyInjection().SetMain(
composition.NewEmptyInjectionMain().SetSource(composition.InjectionMainSearchSourceAsInjectionMainSource(
composition.NewEmptyInjectionMainSearchSource().SetSearch(
composition.NewEmptyMainSearch().SetIndex("videos").SetParams(
composition.NewEmptyMainInjectionQueryParameters().SetHitsPerPage(3).SetAttributesToRetrieve(
[]string{"title", "thumbnail", "duration"})))))))}).
SetFeedsOrder(
[]string{"products", "articles", "videos"}),
),
)),
))
if err != nil {
// handle the eventual error
panic(err)
}
// print the response
print(response)// Initialize the client
CompositionClient client = new CompositionClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY");
// Call the API
TaskIDResponse response = client.putComposition(
"my-compo",
new Composition()
.setObjectID("my-compo")
.setName("my composition")
.setBehavior(
new CompositionMultifeedBehavior().setMultifeed(
new Multifeed()
.setFeeds(
new HashMap() {
{
put(
"products",
new FeedInjection().setInjection(
new Injection()
.setMain(
new InjectionMain().setSource(
new InjectionMainSearchSource().setSearch(
new MainSearch().setIndex("products").setParams(new MainInjectionQueryParameters().setHitsPerPage(12))
)
)
)
.setInjectedItems(
Arrays.asList(
new InjectionInjectedItem()
.setKey("featured-products")
.setSource(
new InjectedItemSearchSource().setSearch(
new InjectedItemSearch()
.setIndex("products")
.setParams(new BaseInjectionQueryParameters().setFilters("featured:true"))
)
)
.setPosition(0)
.setLength(2)
)
)
)
);
put(
"articles",
new FeedInjection().setInjection(
new Injection()
.setMain(
new InjectionMain().setSource(
new InjectionMainSearchSource().setSearch(
new MainSearch()
.setIndex("articles")
.setParams(
new MainInjectionQueryParameters()
.setHitsPerPage(5)
.setAttributesToRetrieve(Arrays.asList("title", "excerpt", "publishedAt"))
)
)
)
)
.setInjectedItems(
Arrays.asList(
new InjectionInjectedItem()
.setKey("editorial-picks")
.setSource(
new InjectedItemSearchSource().setSearch(
new InjectedItemSearch()
.setIndex("articles")
.setParams(new BaseInjectionQueryParameters().setFilters("editorial_pick:true"))
)
)
.setPosition(0)
.setLength(1)
)
)
)
);
put(
"videos",
new FeedInjection().setInjection(
new Injection().setMain(
new InjectionMain().setSource(
new InjectionMainSearchSource().setSearch(
new MainSearch()
.setIndex("videos")
.setParams(
new MainInjectionQueryParameters()
.setHitsPerPage(3)
.setAttributesToRetrieve(Arrays.asList("title", "thumbnail", "duration"))
)
)
)
)
)
);
}
}
)
.setFeedsOrder(Arrays.asList("products", "articles", "videos"))
)
)
);
// print the response
System.out.println(response);// Initialize the client
const client = compositionClient('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
const response = await client.putComposition({
compositionID: 'my-compo',
composition: {
objectID: 'my-compo',
name: 'my composition',
behavior: {
multifeed: {
feeds: {
products: {
injection: {
main: { source: { search: { index: 'products', params: { hitsPerPage: 12 } } } },
injectedItems: [
{
key: 'featured-products',
source: { search: { index: 'products', params: { filters: 'featured:true' } } },
position: 0,
length: 2,
},
],
},
},
articles: {
injection: {
main: {
source: {
search: {
index: 'articles',
params: { hitsPerPage: 5, attributesToRetrieve: ['title', 'excerpt', 'publishedAt'] },
},
},
},
injectedItems: [
{
key: 'editorial-picks',
source: { search: { index: 'articles', params: { filters: 'editorial_pick:true' } } },
position: 0,
length: 1,
},
],
},
},
videos: {
injection: {
main: {
source: {
search: {
index: 'videos',
params: { hitsPerPage: 3, attributesToRetrieve: ['title', 'thumbnail', 'duration'] },
},
},
},
},
},
},
feedsOrder: ['products', 'articles', 'videos'],
},
},
},
});
// print the response
console.log(response);// Initialize the client
val client = CompositionClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
var response =
client.putComposition(
compositionID = "my-compo",
composition =
Composition(
objectID = "my-compo",
name = "my composition",
behavior =
CompositionMultifeedBehavior(
multifeed =
Multifeed(
feeds =
mapOf(
"products" to
FeedInjection(
injection =
Injection(
main =
InjectionMain(
source =
InjectionMainSearchSource(
search =
MainSearch(
index = "products",
params = MainInjectionQueryParameters(hitsPerPage = 12),
)
)
),
injectedItems =
listOf(
InjectionInjectedItem(
key = "featured-products",
source =
InjectedItemSearchSource(
search =
InjectedItemSearch(
index = "products",
params =
BaseInjectionQueryParameters(
filters = "featured:true"
),
)
),
position = 0,
length = 2,
)
),
)
),
"articles" to
FeedInjection(
injection =
Injection(
main =
InjectionMain(
source =
InjectionMainSearchSource(
search =
MainSearch(
index = "articles",
params =
MainInjectionQueryParameters(
hitsPerPage = 5,
attributesToRetrieve =
listOf("title", "excerpt", "publishedAt"),
),
)
)
),
injectedItems =
listOf(
InjectionInjectedItem(
key = "editorial-picks",
source =
InjectedItemSearchSource(
search =
InjectedItemSearch(
index = "articles",
params =
BaseInjectionQueryParameters(
filters = "editorial_pick:true"
),
)
),
position = 0,
length = 1,
)
),
)
),
"videos" to
FeedInjection(
injection =
Injection(
main =
InjectionMain(
source =
InjectionMainSearchSource(
search =
MainSearch(
index = "videos",
params =
MainInjectionQueryParameters(
hitsPerPage = 3,
attributesToRetrieve =
listOf("title", "thumbnail", "duration"),
),
)
)
)
)
),
),
feedsOrder = listOf("products", "articles", "videos"),
)
),
),
)
// print the response
println(response)// Initialize the client
$client = CompositionClient::create('ALGOLIA_APPLICATION_ID', 'ALGOLIA_API_KEY');
// Call the API
$response = $client->putComposition(
'my-compo',
['objectID' => 'my-compo',
'name' => 'my composition',
'behavior' => ['multifeed' => ['feeds' => ['products' => ['injection' => ['main' => ['source' => ['search' => ['index' => 'products',
'params' => ['hitsPerPage' => 12,
],
],
],
],
'injectedItems' => [
['key' => 'featured-products',
'source' => ['search' => ['index' => 'products',
'params' => ['filters' => 'featured:true',
],
],
],
'position' => 0,
'length' => 2,
],
],
],
],
'articles' => ['injection' => ['main' => ['source' => ['search' => ['index' => 'articles',
'params' => ['hitsPerPage' => 5,
'attributesToRetrieve' => [
'title',
'excerpt',
'publishedAt',
],
],
],
],
],
'injectedItems' => [
['key' => 'editorial-picks',
'source' => ['search' => ['index' => 'articles',
'params' => ['filters' => 'editorial_pick:true',
],
],
],
'position' => 0,
'length' => 1,
],
],
],
],
'videos' => ['injection' => ['main' => ['source' => ['search' => ['index' => 'videos',
'params' => ['hitsPerPage' => 3,
'attributesToRetrieve' => [
'title',
'thumbnail',
'duration',
],
],
],
],
],
],
],
],
'feedsOrder' => [
'products',
'articles',
'videos',
],
],
],
],
);
// print the response
var_dump($response);# Initialize the client
# In an asynchronous context, you can use CompositionClient instead, which exposes the exact same methods.
client = CompositionClientSync("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.put_composition(
composition_id="my-compo",
composition={
"objectID": "my-compo",
"name": "my composition",
"behavior": {
"multifeed": {
"feeds": {
"products": {
"injection": {
"main": {
"source": {
"search": {
"index": "products",
"params": {
"hitsPerPage": 12,
},
},
},
},
"injectedItems": [
{
"key": "featured-products",
"source": {
"search": {
"index": "products",
"params": {
"filters": "featured:true",
},
},
},
"position": 0,
"length": 2,
},
],
},
},
"articles": {
"injection": {
"main": {
"source": {
"search": {
"index": "articles",
"params": {
"hitsPerPage": 5,
"attributesToRetrieve": [
"title",
"excerpt",
"publishedAt",
],
},
},
},
},
"injectedItems": [
{
"key": "editorial-picks",
"source": {
"search": {
"index": "articles",
"params": {
"filters": "editorial_pick:true",
},
},
},
"position": 0,
"length": 1,
},
],
},
},
"videos": {
"injection": {
"main": {
"source": {
"search": {
"index": "videos",
"params": {
"hitsPerPage": 3,
"attributesToRetrieve": [
"title",
"thumbnail",
"duration",
],
},
},
},
},
},
},
},
"feedsOrder": [
"products",
"articles",
"videos",
],
},
},
},
)
# print the response
print(response)# Initialize the client
client = Algolia::CompositionClient.create("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
# Call the API
response = client.put_composition(
"my-compo",
Algolia::Composition::Composition.new(
algolia_object_id: "my-compo",
name: "my composition",
behavior: Algolia::Composition::CompositionMultifeedBehavior.new(
multifeed: Algolia::Composition::Multifeed.new(
feeds: {
products: Algolia::Composition::FeedInjection.new(
injection: Algolia::Composition::Injection.new(
main: Algolia::Composition::InjectionMain.new(
source: Algolia::Composition::InjectionMainSearchSource.new(
search: Algolia::Composition::MainSearch.new(
index: "products",
params: Algolia::Composition::MainInjectionQueryParameters.new(hits_per_page: 12)
)
)
),
injected_items: [
Algolia::Composition::InjectionInjectedItem.new(
key: "featured-products",
source: Algolia::Composition::InjectedItemSearchSource.new(
search: Algolia::Composition::InjectedItemSearch.new(
index: "products",
params: Algolia::Composition::BaseInjectionQueryParameters.new(filters: "featured:true")
)
),
position: 0,
length: 2
)
]
)
),
articles: Algolia::Composition::FeedInjection.new(
injection: Algolia::Composition::Injection.new(
main: Algolia::Composition::InjectionMain.new(
source: Algolia::Composition::InjectionMainSearchSource.new(
search: Algolia::Composition::MainSearch.new(
index: "articles",
params: Algolia::Composition::MainInjectionQueryParameters.new(
hits_per_page: 5,
attributes_to_retrieve: ["title", "excerpt", "publishedAt"]
)
)
)
),
injected_items: [
Algolia::Composition::InjectionInjectedItem.new(
key: "editorial-picks",
source: Algolia::Composition::InjectedItemSearchSource.new(
search: Algolia::Composition::InjectedItemSearch.new(
index: "articles",
params: Algolia::Composition::BaseInjectionQueryParameters.new(filters: "editorial_pick:true")
)
),
position: 0,
length: 1
)
]
)
),
videos: Algolia::Composition::FeedInjection.new(
injection: Algolia::Composition::Injection.new(
main: Algolia::Composition::InjectionMain.new(
source: Algolia::Composition::InjectionMainSearchSource.new(
search: Algolia::Composition::MainSearch.new(
index: "videos",
params: Algolia::Composition::MainInjectionQueryParameters.new(
hits_per_page: 3,
attributes_to_retrieve: ["title", "thumbnail", "duration"]
)
)
)
)
)
)
},
feeds_order: ["products", "articles", "videos"]
)
)
)
)
# print the response
puts(response)// Initialize the client
val client = CompositionClient(appId = "ALGOLIA_APPLICATION_ID", apiKey = "ALGOLIA_API_KEY")
// Call the API
val response = Await.result(
client.putComposition(
compositionID = "my-compo",
composition = Composition(
objectID = "my-compo",
name = "my composition",
behavior = CompositionMultifeedBehavior(
multifeed = Multifeed(
feeds = Map(
"products" -> FeedInjection(
injection = Injection(
main = InjectionMain(
source = Some(
InjectionMainSearchSource(
search = MainSearch(
index = "products",
params = Some(
MainInjectionQueryParameters(
hitsPerPage = Some(12)
)
)
)
)
)
),
injectedItems = Some(
Seq(
InjectionInjectedItem(
key = "featured-products",
source = InjectedItemSearchSource(
search = InjectedItemSearch(
index = "products",
params = Some(
BaseInjectionQueryParameters(
filters = Some("featured:true")
)
)
)
),
position = 0,
length = 2
)
)
)
)
),
"articles" -> FeedInjection(
injection = Injection(
main = InjectionMain(
source = Some(
InjectionMainSearchSource(
search = MainSearch(
index = "articles",
params = Some(
MainInjectionQueryParameters(
hitsPerPage = Some(5),
attributesToRetrieve = Some(Seq("title", "excerpt", "publishedAt"))
)
)
)
)
)
),
injectedItems = Some(
Seq(
InjectionInjectedItem(
key = "editorial-picks",
source = InjectedItemSearchSource(
search = InjectedItemSearch(
index = "articles",
params = Some(
BaseInjectionQueryParameters(
filters = Some("editorial_pick:true")
)
)
)
),
position = 0,
length = 1
)
)
)
)
),
"videos" -> FeedInjection(
injection = Injection(
main = InjectionMain(
source = Some(
InjectionMainSearchSource(
search = MainSearch(
index = "videos",
params = Some(
MainInjectionQueryParameters(
hitsPerPage = Some(3),
attributesToRetrieve = Some(Seq("title", "thumbnail", "duration"))
)
)
)
)
)
)
)
)
),
feedsOrder = Some(Seq("products", "articles", "videos"))
)
)
)
),
Duration(100, "sec")
)
// print the response
println(response)// Initialize the client
let client = try CompositionClient(appID: "ALGOLIA_APPLICATION_ID", apiKey: "ALGOLIA_API_KEY")
// Call the API
let response = try await client.putComposition(
compositionID: "my-compo",
composition: Composition(
objectID: "my-compo",
name: "my composition",
behavior: CompositionBehavior
.compositionMultifeedBehavior(CompositionMultifeedBehavior(multifeed: Multifeed(
feeds: [
"products": FeedInjection(injection: Injection(
main: InjectionMain(source: InjectionMainSource
.injectionMainSearchSource(InjectionMainSearchSource(search: MainSearch(
index: "products",
params: MainInjectionQueryParameters(hitsPerPage: 12)
)))),
injectedItems: [InjectionInjectedItem(
key: "featured-products",
source: InjectedItemSource
.injectedItemSearchSource(InjectedItemSearchSource(search: InjectedItemSearch(
index: "products",
params: BaseInjectionQueryParameters(filters: "featured:true")
))),
position: 0,
length: 2
)]
)),
"articles": FeedInjection(injection: Injection(
main: InjectionMain(source: InjectionMainSource
.injectionMainSearchSource(InjectionMainSearchSource(search: MainSearch(
index: "articles",
params: MainInjectionQueryParameters(
attributesToRetrieve: ["title", "excerpt", "publishedAt"],
hitsPerPage: 5
)
)))),
injectedItems: [InjectionInjectedItem(
key: "editorial-picks",
source: InjectedItemSource
.injectedItemSearchSource(InjectedItemSearchSource(search: InjectedItemSearch(
index: "articles",
params: BaseInjectionQueryParameters(filters: "editorial_pick:true")
))),
position: 0,
length: 1
)]
)),
"videos": FeedInjection(injection: Injection(main: InjectionMain(source: InjectionMainSource
.injectionMainSearchSource(InjectionMainSearchSource(search: MainSearch(
index: "videos",
params: MainInjectionQueryParameters(
attributesToRetrieve: ["title", "thumbnail", "duration"],
hitsPerPage: 3
)
)))))),
],
feedsOrder: ["products", "articles", "videos"]
)))
)
)
// print the response
print(response){
"taskID": 1514562690001
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}{
"message": "Invalid Application-Id or API-Key"
}editSettingsAuthorizations
Your Algolia application ID.
Your Algolia API key with the necessary permissions to make the request. Permissions are controlled through access control lists (ACL) and access restrictions. The required ACL to make a request is listed in each endpoint's reference.
Path Parameters
Unique Composition ObjectID. Composition unique identifier.
"my_composition_object_id"
Body
An object containing either an injection or multifeed behavior schema, but not both.
- Option 1
- Option 2
Show child attributes
Show child attributes
Composition name.
"my lovely crafted composition"
Composition unique identifier.
"my_composition_object_id"
Composition description.
"my lovely crafted composition that is used for X purpose"
A mapping of sorting labels to the indices (or replicas) that implement those sorting rules. The sorting indices MUST be related to the associated main targeted index in the composition. Each key is the label your frontend sends at runtime (for example, "Price (asc)"), and each value is the name of the index that should be queried when that label is selected.
When a request includes a "sortBy" parameter, the platform looks up the corresponding index in this mapping and uses it to execute the query. The main targeted index is replaced with the sorting strategy index it is mapped to.
Up to 20 sorting strategies can be defined.
Show child attributes
Show child attributes
{
"Price (asc)": "products-low-to-high",
"Price (desc)": "products-high-to-low"
}
Response
OK
Unique identifier of a task.
A successful API response means that a task was added to a queue.
It might not run immediately.
You can check the task's progress with the task operation and this task ID.
1514562690001
Was this page helpful?