Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Nest.Tests.Unit/Search/SearchOptions/SearchOptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ public void TestExecuteOnNode()
StringAssert.Contains("preference=_only_node:somenode", result.ConnectionStatus.RequestUrl);
}
[Test]
public void TestExecuteOnPreferredNode()
{
var s = new SearchDescriptor<ElasticSearchProject>()
.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<ElasticSearchProject>()
Expand Down
43 changes: 29 additions & 14 deletions src/Nest/DSL/SearchDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class SearchDescriptorBase

internal Func<dynamic, Hit<dynamic>, Type> _ConcreteTypeSelector;


}

[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
Expand Down Expand Up @@ -412,6 +412,21 @@ public SearchDescriptor<T> ExecuteOnNode(string node)
return this;
}
/// <summary>
/// <para>
/// Controls a preference of which shard replicas to execute the search request on.
/// By default, the operation is randomized between the each shard replicas.
/// </para>
/// <para>
/// Prefers execution on the node with the provided node id if applicable.
/// </para>
/// </summary>
public SearchDescriptor<T> ExecuteOnPreferredNode(string node)
{
node.ThrowIfNull("node");
this._Preference = string.Format("_prefer_node:{0}", node);
return this;
}
/// <summary>
/// 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).
Expand Down Expand Up @@ -888,26 +903,26 @@ public SearchDescriptor<T> PhraseSuggest(string name, Func<PhraseSuggestDescript
return this;
}

public SearchDescriptor<T> CompletionSuggest(string name, Func<CompletionSuggestDescriptor<T>, CompletionSuggestDescriptor<T>> suggest)
{
name.ThrowIfNullOrEmpty("name");
suggest.ThrowIfNull("suggest");
if (this._Suggest == null)
this._Suggest = new Dictionary<String, SuggestDescriptorBucket<T>>();
CompletionSuggestDescriptor<T> desc = new CompletionSuggestDescriptor<T>();
CompletionSuggestDescriptor<T> item = suggest(desc);
SuggestDescriptorBucket<T> bucket = new SuggestDescriptorBucket<T> { _Text = item._Text, CompletionSuggest = item };
this._Suggest.Add(name, bucket);
return this;
}
public SearchDescriptor<T> CompletionSuggest(string name, Func<CompletionSuggestDescriptor<T>, CompletionSuggestDescriptor<T>> suggest)
{
name.ThrowIfNullOrEmpty("name");
suggest.ThrowIfNull("suggest");
if (this._Suggest == null)
this._Suggest = new Dictionary<String, SuggestDescriptorBucket<T>>();
CompletionSuggestDescriptor<T> desc = new CompletionSuggestDescriptor<T>();
CompletionSuggestDescriptor<T> item = suggest(desc);
SuggestDescriptorBucket<T> bucket = new SuggestDescriptorBucket<T> { _Text = item._Text, CompletionSuggest = item };
this._Suggest.Add(name, bucket);
return this;
}

/// <summary>
/// Describe the query to perform using a query descriptor lambda
/// </summary>
public SearchDescriptor<T> Query(Func<QueryDescriptor<T>, BaseQuery> query)
{
query.ThrowIfNull("query");
var q = new QueryDescriptor<T>() {IsStrict = this._Strict};
var q = new QueryDescriptor<T>() { IsStrict = this._Strict };

var bq = query(q);
return this.Query(bq);
Expand Down