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);
abTest := analytics.ABTest{
Name: "myABTest",
Variants: []analytics.Variant{
{
Index: "indexName1",
TrafficPercentage: 90,
Description: "a description",
},
{
Index: "indexName1-alt",
TrafficPercentage: 10,
},
},
EndAt: time.Now().Truncate(time.Hour).Add(24 * time.Hour),
}
client := analytics.NewClient("YourApplicationID", "YourWriteAPIKey")
res, err := client.AddABTest(abTest)
OffsetDateTime utcNow =
OffsetDateTime.now(ZoneOffset.UTC)
.withNano(0)
.withSecond(0);
ABTest abtest = new ABTest(
"myABTest",
Arrays.asList(
new Variant("indexName1", 90, "a description"),
new Variant("indexName1-alt", 10, null)),
utcNow.plusDays(1));
// Add a new AB Test
AnalyticsClient analytics =
DefaultAnalyticsClient.create("YourApplicationID", "YourWriteAPIKey");
analytics.addABTest(abtest);
// Asynchronous
analytics.addABTestAsync(abtest);
const endAt = new Date();
endAt.setDate(endAt.getDate() + 1);
const abTest = {
name: "myABTest",
variants: [
{
index: "indexName1",
trafficPercentage: 90,
},
{
index: "indexName1-alt",
trafficPercentage: 10,
description: "a description",
},
],
endAt: endAt.toISOString().replace(/\.[0-9]{3}/, ""),
};
const analytics = client.initAnalytics({
// optional parameters
region: "de",
appId: "YourApplicationID",
apiKey: "YourWriteAPIKey",
});
analytics.addABTest(abTest).then(({ abTestID }) => {
console.log(abTestID);
});
val dayInMilliseconds = 60 * 60 * 24 * 1000
val abTest = ABTest(
name = "myABTest",
variantA = Variant(
indexName = indexName1,
trafficPercentage = 90,
description = "a description"
),
variantB = Variant(
indexName = indexName2,
trafficPercentage = 10,
description = "a description"
),
endAt = ClientDate(Time.getCurrentTimeMillis() + dayInMilliseconds)
)
clientAnalytics.addABTest(abTest)
$endDate = new \DateTime('tomorrow');
$endDate = $endDate->format('Y-m-d\TH:i:s\Z');
$analytics = AnalyticsClient::create(
'YourApplicationID',
'YourWriteAPIKey'
);
$analytics->addABTest([
'name' => 'myABTest',
'variants' => [
[
'index' => 'indexName1',
'trafficPercentage' => 90,
'description' => 'a description'
],
[
'index' => 'indexName1-alt',
'trafficPercentage' => 10
],
],
"endAt" => $endDate,
]);
ab_test = {
"name": "myABTest",
"variants": [
{
"index": "indexName1",
"trafficPercentage": 90,
"description": "a description",
},
{"index": "indexName1-alt", "trafficPercentage": 10},
],
"endAt": datetime.datetime.utcnow().replace(day=29).strftime("%Y-%m-%dT%H:%M:%SZ"),
}
analytics = AnalyticsClient.create("YourApplicationID", "YourWriteAPIKey")
analytics.add_ab_test(ab_test)
tomorrow = Time.now + 24 * 60 * 60
abtest = {
name: "myABTest",
variants: [
{
index: "indexName1",
trafficPercentage: 90,
description: "a description"
},
{
index: "indexName1-alt",
trafficPercentage: 10
}
],
endAt: tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ")
}
analytics = Algolia::Analytics::Client.create("YourApplicationID", "YourWriteAPIKey")
analytics.add_ab_test(abtest)
val abTest = ABTest(
"myABTest",
Seq(
ABTestVariant("indexName1", 90, Some("a description")),
ABTestVariant("indexName1-alt", 10, None)
),
LocalDateTime.now().plusDays(1)
)
client.execute {
add abTest abTest
}
let analyticsClient = AnalyticsClient(appID: "YourApplicationID", apiKey: "YourWriteAPIKey")
let abTest = ABTest(name: "myABTest",
endAt: Date().addingTimeInterval(.day),
variantA: .init(indexName: "indexName1",
trafficPercentage: 90,
description: "a description"),
variantB: .init(indexName: "indexName2",
trafficPercentage: 10,
description: "a description"))
analyticsClient.addABTest(abTest) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}
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);
abTest := analytics.ABTest{
Name: "myABTest",
Variants: []analytics.Variant{
{
Index: "indexName1",
TrafficPercentage: 90,
},
{
Index: "indexName1",
TrafficPercentage: 10,
CustomSearchParameters: &search.QueryParams{
IgnorePlurals: opt.IgnorePlurals(true),
},
},
},
EndAt: time.Now().Truncate(time.Hour).Add(24 * time.Hour),
}
client := analytics.NewClient("YourApplicationID", "YourWriteAPIKey")
res, err := client.AddABTest(abTest)
OffsetDateTime utcNow =
OffsetDateTime.now(ZoneOffset.UTC)
.withNano(0)
.withSecond(0);
Variant variantWithSearchParam = new Variant("indexName1", 10, null);
variantWithSearchParam.setCustomSearchParameters(
new Query().setIgnorePlurals(IgnorePlurals.of(true)));
ABTest abtest =
new ABTest(
"myABTest",
new Variant("indexName1", 90, null), variantWithSearchParam),
utcNow.plusDays(1));
analytics.addABTest(abtest);
// Asynchronous
analytics.addABTestAsync(abtest);
const endAt = new Date();
endAt.setDate(endAt.getDate() + 1);
const abTest = {
name: "myABTest",
variants: [
{
index: "indexName1",
trafficPercentage: 90,
},
{
index: "indexName1",
trafficPercentage: 10,
description: "a description",
customSearchParameters: { ignorePlurals: true },
},
],
endAt: endAt.toISOString().replace(/\.[0-9]{3}/, ""),
};
const analytics = client.initAnalytics({
// optional parameters
region: "de",
appId: "YourApplicationID",
apiKey: "YourWriteAPIKey",
});
analytics.addABTest(abTest).then(({ abTestID }) => {
console.log(abTestID);
});
val dayInMilliseconds = 60 * 60 * 24 * 1000
val abTest = ABTest(
name = "myABTest",
variantA = Variant(
indexName = indexName1,
trafficPercentage = 90,
description = "a description"
),
variantB = Variant(
indexName = indexName1,
trafficPercentage = 10,
description = "a description",
customSearchParameters = Query(ignorePlurals = IgnorePlurals.True)
),
endAt = ClientDate(Time.getCurrentTimeMillis() + dayInMilliseconds)
)
clientAnalytics.addABTest(abTest)
$endAt = new DateTime('tomorrow');
$abTest = [
'name' => 'myABTest',
'variants' => [
['index' => 'indexName1', 'trafficPercentage' => 90],
[
'index' => 'indexName1',
'trafficPercentage' => 10,
'customSearchParameters' => ['ignorePlurals' => true],
],
],
'endAt' => $endAt->format('Y-m-d\TH:i:s\Z'),
];
$response = $analyticsClient->addABTest($abTest);
end_at = datetime.date.today() + datetime.timedelta(days=1)
ab_test = {
"name": "myABTest",
"variants": [
{"index": "indexName1", "trafficPercentage": 90},
{
"index": "indexName1",
"trafficPercentage": 10,
"customSearchParameters": {"ignorePlurals": True},
},
],
"endAt": end_at.strftime("%Y-%m-%dT%H:%M:%SZ"),
}
analytics.add_ab_test(ab_test)
tomorrow = Time.now + 24 * 60 * 60
abtest = {
name: "myABTest",
variants: [
{
index: "indexName1",
trafficPercentage: 90,
description: "a description"
},
{
index: "indexName1",
trafficPercentage: 10,
customSearchParameters: {ignorePlurals: true}
}
],
endAt: tomorrow.strftime("%Y-%m-%dT%H:%M:%SZ")
}
analytics = client.init_analytics
analytics.add_ab_test(abtest)
val abTest = ABTest(
"myABTest",
Seq(
ABTestVariant("indexName1", 90),
ABTestVariant("indexName1", 10,
customSearchParameters =
Some(Query(ignorePlurals = Some(IgnorePlurals.`true`)))),
),
LocalDateTime.now().plusDays(1)
)
client.execute {
add abTest abTest
}
let analyticsClient = AnalyticsClient(appID: "YourApplicationID", apiKey: "YourWriteAPIKey")
let abTest = ABTest(name: "myABTest",
endAt: Date().addingTimeInterval(.day),
variantA: .init(indexName: "indexName1",
trafficPercentage: 90,
description: "a description"),
variantB: .init(indexName: "indexName2",
trafficPercentage: 10,
customSearchParameters: Query()
.set(\.ignorePlurals, to: true)
description: "a description"))
analyticsClient.addABTest(abTest) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}
Parameters
The definition of the A/B test.
Hide child attributes
Hide child attributes
Name of the A/B test.
A and B variants: the base index and a variant you want to test.
Show child attributes
Show child attributes
Index name
Percentage of the search traffic that should be routed to this variant.
The sum of percentages for both variants should be 100.
Applies search parameters to this variant.
This parameter can only be used of both variants use the same index.
Supported parameters
Supported parameters
Search:
advancedSyntaxalternativesAsExactdistinctenableRulesexactOnSingleWordQueryignorePluralsminProximityqueryTyperemoveStopWordsremoveWordsIfNoResultssumOrFiltersScores
allowTyposOnNumericTokensdisableTypoToleranceOnAttributesminWordSizefor1TypominWordSizefor2TypostypoTolerance
Description of the variant.
This is useful when seeing the results in the dashboard or via the API.
The estimated number of searches that will need to be run to achieve the desired confidence level and statistical power.
A
minimumDetectableEffect must be set in the configuration for this to be used.Configuration settings for this A/B test.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Whether to exclude empty searches from the A/B test results.
Options for calculating the minimum detectable effect.
This requires setting the
estimatedSampleSize parameter on one of the variants.Show child attributes
Show child attributes
The effect that you want to detect.
One of:
conversionRateclickThroughRatepurchaseRateaddToCartRate
The smallest relative difference between the variants that you want to detect.
For example, to detect a 10% difference between the variants,
set this to 0.1. The size must be between 0 and 1.
Response
Generated Id of the A/B test.
Base index name for the A/B test.
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 thegetLogs 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",
}