You're viewing an archived version of our docs. Check out our current documentation →

Upsert a composition

Upsert a composition in the current Algolia application.

Usage

Required ACL: editSettings
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
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.PutCompositionAsync(
  "my-metadata-compo",
  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" } }
                  },
                },
              },
            },
          },
        },
      },
    },
  }
);