Skip to main content
This page documents an earlier version of the API client. For the latest version, see Create an A/B test.
Required ACL: editSettings You can set an A/B test on two different indices with different settings, or on the same index with different search parameters by providing a customSearchParameters setting on one of the variants.

Examples

var abTest = new ABTest
{
    Name = "myABTest",
    Variants = new List<Variant>
    {
        new Variant
        {
            Index = "indexName1",
            TrafficPercentage = 90,
            Description = "a description"
        },
        new Variant
        {
            Index = "indexName1-alt",
            TrafficPercentage = 10,
            Description = "a description"
        }
    },
    EndAt = DateTime.UtcNow.AddDays(1)
};

// Add a new A/B Test
AnalyticsClient analytics = new AnalyticsClient("YourApplicationID", "YourWriteAPIKey");
analytics.AddABTest(abtest);

// Asynchronous
await analytics.AddABTestAsync(abtest);

Add an A/B test on a single index with custom search parameters

var abTest = new ABTest
{
    Name = "myABTest",
    Variants = new List<Variant>
    {
        new Variant
        {
            Index = "indexName1",
            TrafficPercentage = 90
        },
        new Variant
        {
            Index = "indexName1",
            TrafficPercentage = 10,
            CustomSearchParameters = new Query { IgnorePlurals = true }
        }
    },
    EndAt = DateTime.UtcNow.AddDays(1)
};

var response = analytics.AddABTest(abTest);

Parameters

abTest
object
required
The definition of the A/B test.

Response

abTestID
integer
Generated Id of the A/B test.
index
string
Base index name for the A/B test.
taskID
integer
The task ID used with the waitTask method.

Response as JSON

This section shows the JSON response returned by the API. Each API client wraps this response in language-specific objects, so the structure may vary. To view the response, use the getLogs method. Don’t rely on the order of properties—JSON objects don’t preserve key order.
JSON
{
  "abTestID": 78,
  "taskID": 111885720
  "index": "atis-abtest-default",
}
I