Skip to main content
Required ACL: editSettings Otherwise, a new one is added.

Usage

// Initialize the client
var client = new CompositionClient(
  new CompositionConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
);

// Call the API
var response = await client.PutCompositionRuleAsync(
  "compositionID",
  "rule-with-deduplication",
  new CompositionRule
  {
    ObjectID = "rule-with-deduplication",
    Description = "my description",
    Enabled = true,
    Conditions = new List<Condition>
    {
      new Condition { Anchoring = Enum.Parse<Anchoring>("Contains"), Pattern = "harry" },
    },
    Consequence = new CompositionRuleConsequence
    {
      Behavior = new CompositionBehavior(
        new CompositionInjectionBehavior
        {
          Injection = new Injection
          {
            Main = new InjectionMain
            {
              Source = new InjectionMainSource(
                new InjectionMainSearchSource { Search = new MainSearch { Index = "my-index" } }
              ),
            },
            InjectedItems = new List<InjectionInjectedItem>
            {
              new InjectionInjectedItem
              {
                Key = "my-unique-injected-item-key",
                Source = new InjectedItemSource(
                  new InjectedItemSearchSource
                  {
                    Search = new InjectedItemSearch { Index = "my-index" },
                  }
                ),
                Position = 0,
                Length = 3,
              },
            },
            Deduplication = new Deduplication
            {
              Positioning = Enum.Parse<DedupPositioning>("HighestInjected"),
            },
          },
        }
      ),
    },
  }
);

// print the response
Console.WriteLine(response);

See the full API reference

For more details about input parameters and response fields.
Last modified on April 23, 2026