Skip to content

Commit 5eee769

Browse files
author
Juan
committed
Added ExecuteOnPrimaryFirst read preference.
1 parent 8fbd142 commit 5eee769

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ public void TestExecuteOnPrimary()
9090
StringAssert.Contains("preference=_primary", result.ConnectionStatus.RequestUrl);
9191
}
9292
[Test]
93+
public void TestExecuteOnPrimaryFirst()
94+
{
95+
var s = new SearchDescriptor<ElasticSearchProject>()
96+
.From(0)
97+
.Size(10)
98+
.ExecuteOnPrimaryFirst();
99+
var result = this._client.Search(s);
100+
StringAssert.Contains("preference=_primary_first", result.ConnectionStatus.RequestUrl);
101+
}
102+
[Test]
93103
public void TestExecuteOnLocalShard()
94104
{
95105
var s = new SearchDescriptor<ElasticSearchProject>()

src/Nest/DSL/SearchDescriptor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,21 @@ public SearchDescriptor<T> ExecuteOnPrimary()
373373
/// By default, the operation is randomized between the each shard replicas.
374374
/// </para>
375375
/// <para>
376+
/// The operation will go and be executed on the primary shard, and if not available (failover),
377+
/// will execute on other shards.
378+
/// </para>
379+
/// </summary>
380+
public SearchDescriptor<T> ExecuteOnPrimaryFirst()
381+
{
382+
this._Preference = "_primary_first";
383+
return this;
384+
}
385+
/// <summary>
386+
/// <para>
387+
/// Controls a preference of which shard replicas to execute the search request on.
388+
/// By default, the operation is randomized between the each shard replicas.
389+
/// </para>
390+
/// <para>
376391
/// The operation will prefer to be executed on a local allocated shard is possible.
377392
/// </para>
378393
/// </summary>

0 commit comments

Comments
 (0)