diff --git a/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs b/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs index 5595b9c518f..38cfbcb8893 100644 --- a/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs +++ b/src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs @@ -120,6 +120,16 @@ public void TestExecuteOnNode() StringAssert.Contains("preference=_only_node:somenode", result.ConnectionStatus.RequestUrl); } [Test] + public void TestExecuteOnPreferredNode() + { + var s = new SearchDescriptor() + .From(0) + .Size(10) + .ExecuteOnPreferredNode("somenode"); + var result = this._client.Search(s); + StringAssert.Contains("preference=_prefer_node:somenode", result.ConnectionStatus.RequestUrl); + } + [Test] public void TestFields() { var s = new SearchDescriptor() diff --git a/src/Nest/DSL/SearchDescriptor.cs b/src/Nest/DSL/SearchDescriptor.cs index b20995e7337..d43195c4481 100644 --- a/src/Nest/DSL/SearchDescriptor.cs +++ b/src/Nest/DSL/SearchDescriptor.cs @@ -28,7 +28,7 @@ public abstract class SearchDescriptorBase internal Func, Type> _ConcreteTypeSelector; - + } [JsonObject(MemberSerialization = MemberSerialization.OptIn)] @@ -412,6 +412,21 @@ public SearchDescriptor ExecuteOnNode(string node) return this; } /// + /// + /// Controls a preference of which shard replicas to execute the search request on. + /// By default, the operation is randomized between the each shard replicas. + /// + /// + /// Prefers execution on the node with the provided node id if applicable. + /// + /// + public SearchDescriptor ExecuteOnPreferredNode(string node) + { + node.ThrowIfNull("node"); + this._Preference = string.Format("_prefer_node:{0}", node); + return this; + } + /// /// Allows to configure different boost level per index when searching across /// more than one indices. This is very handy when hits coming from one index /// matter more than hits coming from another index (think social graph where each user has an index). @@ -888,18 +903,18 @@ public SearchDescriptor PhraseSuggest(string name, Func CompletionSuggest(string name, Func, CompletionSuggestDescriptor> suggest) - { - name.ThrowIfNullOrEmpty("name"); - suggest.ThrowIfNull("suggest"); - if (this._Suggest == null) - this._Suggest = new Dictionary>(); - CompletionSuggestDescriptor desc = new CompletionSuggestDescriptor(); - CompletionSuggestDescriptor item = suggest(desc); - SuggestDescriptorBucket bucket = new SuggestDescriptorBucket { _Text = item._Text, CompletionSuggest = item }; - this._Suggest.Add(name, bucket); - return this; - } + public SearchDescriptor CompletionSuggest(string name, Func, CompletionSuggestDescriptor> suggest) + { + name.ThrowIfNullOrEmpty("name"); + suggest.ThrowIfNull("suggest"); + if (this._Suggest == null) + this._Suggest = new Dictionary>(); + CompletionSuggestDescriptor desc = new CompletionSuggestDescriptor(); + CompletionSuggestDescriptor item = suggest(desc); + SuggestDescriptorBucket bucket = new SuggestDescriptorBucket { _Text = item._Text, CompletionSuggest = item }; + this._Suggest.Add(name, bucket); + return this; + } /// /// Describe the query to perform using a query descriptor lambda @@ -907,7 +922,7 @@ public SearchDescriptor CompletionSuggest(string name, Func Query(Func, BaseQuery> query) { query.ThrowIfNull("query"); - var q = new QueryDescriptor() {IsStrict = this._Strict}; + var q = new QueryDescriptor() { IsStrict = this._Strict }; var bq = query(q); return this.Query(bq);