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
8 changes: 7 additions & 1 deletion src/Nest/Nest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,12 @@
<Compile Include="Search\Search\InnerHits\NamedInnerHits.cs" />
<Compile Include="Search\Search\InnerHits\PathInnerHit.cs" />
<Compile Include="Search\Search\InnerHits\TypeInnerHit.cs" />
<Compile Include="Search\Search\Profile\Collector.cs" />
<Compile Include="Search\Search\Profile\Profile.cs" />
<Compile Include="Search\Search\Profile\QueryBreakdown.cs" />
<Compile Include="Search\Search\Profile\QueryProfile.cs" />
<Compile Include="Search\Search\Profile\SearchProfile.cs" />
<Compile Include="Search\Search\Profile\ShardProfile.cs" />
<Compile Include="Search\Search\Rescoring\Rescore.cs" />
<Compile Include="Search\Search\Rescoring\RescoreQuery.cs" />
<Compile Include="Search\Search\Rescoring\ScoreMode.cs" />
Expand Down Expand Up @@ -1232,4 +1238,4 @@
</ItemGroup>
</When>
</Choose>
</Project>
</Project>
22 changes: 22 additions & 0 deletions src/Nest/Search/Search/Profile/Collector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Nest
{
public class Collector
{
[JsonProperty("name")]
public string Name { get; internal set; }

[JsonProperty("reason")]
public string Reason { get; internal set; }

[JsonProperty("time")]
public Time Time { get; internal set; }

[JsonProperty("children")]
public IEnumerable<Collector> Children { get; internal set; }


}
}
12 changes: 12 additions & 0 deletions src/Nest/Search/Search/Profile/Profile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

namespace Nest
{
public class Profile
{
[JsonProperty("shards")]
public IEnumerable<ShardProfile> Shards { get; internal set; }
}
}
25 changes: 25 additions & 0 deletions src/Nest/Search/Search/Profile/QueryBreakdown.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json;

namespace Nest
{
public class QueryBreakdown
{
[JsonProperty("score")]
public long Score { get; internal set; }

[JsonProperty("next_doc")]
public long NextDoc { get; internal set; }

[JsonProperty("create_weight")]
public long CreateWeight { get; internal set; }

[JsonProperty("build_scorer")]
public long BuildScorer { get; internal set; }

[JsonProperty("advance")]
public long Advance { get; internal set; }

[JsonProperty("match")]
public long Match { get; internal set; }
}
}
23 changes: 23 additions & 0 deletions src/Nest/Search/Search/Profile/QueryProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Nest
{
public class QueryProfile
{
[JsonProperty("query_type")]
public string QueryType { get; internal set; }

[JsonProperty("lucene")]
public string Lucene { get; internal set; }

[JsonProperty("time")]
public Time Time { get; internal set; }

[JsonProperty("breakdown")]
public QueryBreakdown Breakdown { get; internal set; }

[JsonProperty("children")]
public IEnumerable<QueryProfile> Children { get; internal set; }
}
}
17 changes: 17 additions & 0 deletions src/Nest/Search/Search/Profile/SearchProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Nest
{
public class SearchProfile
{
[JsonProperty("rewrite_time")]
public long RewriteTime { get; internal set; }

[JsonProperty("query")]
public IEnumerable<QueryProfile> Query { get; internal set; }

[JsonProperty("collector")]
public IEnumerable<Collector> Collector { get; internal set; }
}
}
15 changes: 15 additions & 0 deletions src/Nest/Search/Search/Profile/ShardProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Nest
{
public class ShardProfile
{
[JsonProperty("id")]
public string Id { get; internal set; }

[JsonProperty("searches")]
public IEnumerable<SearchProfile> Searches { get; internal set; }

}
}
45 changes: 29 additions & 16 deletions src/Nest/Search/Search/SearchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public partial interface ISearchRequest : ICovariantSearchRequest
[JsonProperty(PropertyName = "track_scores")]
bool? TrackScores { get; set; }

[JsonProperty(PropertyName = "profile")]
bool? Profile { get; set; }

[JsonProperty(PropertyName = "min_score")]
double? MinScore { get; set; }

Expand Down Expand Up @@ -101,6 +104,7 @@ public partial class SearchRequest
public bool? Explain { get; set; }
public bool? Version { get; set; }
public bool? TrackScores { get; set; }
public bool? Profile { get; set; }
public double? MinScore { get; set; }
public long? TerminateAfter { get; set; }
public Fields Fields { get; set; }
Expand Down Expand Up @@ -143,6 +147,7 @@ public partial class SearchRequest<T>
public bool? Explain { get; set; }
public bool? Version { get; set; }
public bool? TrackScores { get; set; }
public bool? Profile { get; set; }
public double? MinScore { get; set; }
public long? TerminateAfter { get; set; }
public Fields Fields { get; set; }
Expand Down Expand Up @@ -198,6 +203,7 @@ public partial class SearchDescriptor<T> where T : class
bool? ISearchRequest.Explain { get; set; }
bool? ISearchRequest.Version { get; set; }
bool? ISearchRequest.TrackScores { get; set; }
bool? ISearchRequest.Profile { get; set; }
double? ISearchRequest.MinScore { get; set; }
long? ISearchRequest.TerminateAfter { get; set; }

Expand All @@ -224,7 +230,7 @@ public SearchDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter>
Assign(a => a.Source = sourceSelector?.Invoke(new SourceFilterDescriptor<T>()));

/// <summary>
/// The number of hits to return. Defaults to 10. When using scroll search type
/// The number of hits to return. Defaults to 10. When using scroll search type
/// size is actually multiplied by the number of shards!
/// </summary>
public SearchDescriptor<T> Size(int size) => Assign(a => a.Size = size);
Expand All @@ -245,14 +251,14 @@ public SearchDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter>
public SearchDescriptor<T> Skip(int skip) => this.From(skip);

/// <summary>
/// A search timeout, bounding the search request to be executed within the
/// A search timeout, bounding the search request to be executed within the
/// specified time value and bail with the hits accumulated up
/// to that point when expired. Defaults to no timeout.
/// </summary>
public SearchDescriptor<T> Timeout(string timeout) => Assign(a => a.Timeout = timeout);

/// <summary>
/// Enables explanation for each hit on how its score was computed.
/// Enables explanation for each hit on how its score was computed.
/// (Use .DocumentsWithMetaData on the return results)
/// </summary>
public SearchDescriptor<T> Explain(bool explain = true) => Assign(a => a.Explain = explain);
Expand All @@ -267,20 +273,27 @@ public SearchDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter>
/// </summary>
public SearchDescriptor<T> TrackScores(bool trackscores = true) => Assign(a => a.TrackScores = trackscores);

/// <summary>
/// The Profile API provides detailed timing information about the execution of individual components in a query.
/// It gives the user insight into how queries are executed at a low level so that the user can understand
/// why certain queries are slow, and take steps to improve their slow queries.
/// </summary>
public SearchDescriptor<T> Profile(bool profile = true) => Assign(a => a.Profile = profile);

/// <summary>
/// Allows to filter out documents based on a minimum score:
/// </summary>
public SearchDescriptor<T> MinScore(double minScore) => Assign(a => a.MinScore = minScore);

/// <summary>
/// The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.
/// If set, the response will have a boolean field terminated_early to indicate whether the query execution has actually terminated_early.
/// The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early.
/// If set, the response will have a boolean field terminated_early to indicate whether the query execution has actually terminated_early.
/// </summary>
public SearchDescriptor<T> TerminateAfter(long terminateAfter) => Assign(a => a.TerminateAfter = terminateAfter);

/// <summary>
/// <para>
/// Controls a preference of which shard replicas to execute the search request on.
/// 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>
Expand All @@ -291,19 +304,19 @@ public SearchDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter>

/// <summary>
/// <para>
/// Controls a preference of which shard replicas to execute the search request on.
/// 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>
/// The operation will go and be executed on the primary shard, and if not available (failover),
/// The operation will go and be executed on the primary shard, and if not available (failover),
/// will execute on other shards.
/// </para>
/// </summary>
public SearchDescriptor<T> ExecuteOnPrimaryFirst() => this.Preference("_primary_first");

/// <summary>
/// <para>
/// Controls a preference of which shard replicas to execute the search request on.
/// 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>
Expand All @@ -314,7 +327,7 @@ public SearchDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter>

/// <summary>
/// <para>
/// Controls a preference of which shard replicas to execute the search request on.
/// 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>
Expand All @@ -325,7 +338,7 @@ public SearchDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter>

/// <summary>
/// <para>
/// Controls a preference of which shard replicas to execute the search request on.
/// 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>
Expand All @@ -335,15 +348,15 @@ public SearchDescriptor<T> Source(Func<SourceFilterDescriptor<T>, ISourceFilter>
public SearchDescriptor<T> ExecuteOnPreferredNode(string node) => this.Preference(node.IsNullOrEmpty() ? null : $"_prefer_node:{node}");

/// <summary>
/// Allows to configure different boost level per index when searching across
/// 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).
/// </summary>
public SearchDescriptor<T> IndicesBoost(Func<FluentDictionary<IndexName, double>, FluentDictionary<IndexName, double>> boost) =>
Assign(a => a.IndicesBoost = boost?.Invoke(new FluentDictionary<IndexName, double>()));

/// <summary>
/// Allows to selectively load specific fields for each document
/// Allows to selectively load specific fields for each document
/// represented by a search hit. Defaults to load the internal _source field.
/// </summary>
public SearchDescriptor<T> Fields(Func<FieldsDescriptor<T>, IPromise<Fields>> fields) =>
Expand All @@ -363,7 +376,7 @@ public SearchDescriptor<T> ScriptFields(Func<ScriptFieldsDescriptor, IPromise<IS
///</summary>
public SearchDescriptor<T> Sort(Func<SortDescriptor<T>, IPromise<IList<ISort>>> selector) => Assign(a => a.Sort = selector?.Invoke(new SortDescriptor<T>())?.Value);

public SearchDescriptor<T> InnerHits(Func<NamedInnerHitsDescriptor<T>, IPromise<INamedInnerHits>> selector) =>
public SearchDescriptor<T> InnerHits(Func<NamedInnerHitsDescriptor<T>, IPromise<INamedInnerHits>> selector) =>
Assign(a => a.InnerHits = selector?.Invoke(new NamedInnerHitsDescriptor<T>())?.Value);

///<summary>
Expand All @@ -390,7 +403,7 @@ public SearchDescriptor<T> PostFilter(Func<QueryContainerDescriptor<T>, QueryCon
Assign(a => a.PostFilter = filter.InvokeQuery(new QueryContainerDescriptor<T>()));

/// <summary>
/// Allow to highlight search results on one or more fields. The implementation uses the either lucene fast-vector-highlighter or highlighter.
/// Allow to highlight search results on one or more fields. The implementation uses the either lucene fast-vector-highlighter or highlighter.
/// </summary>
public SearchDescriptor<T> Highlight(Func<HighlightDescriptor<T>, IHighlight> highlightSelector) =>
Assign(a => a.Highlight = highlightSelector?.Invoke(new HighlightDescriptor<T>()));
Expand All @@ -405,4 +418,4 @@ public SearchDescriptor<T> ConcreteTypeSelector(Func<dynamic, Hit<dynamic>, Type
Assign(a => a.TypeSelector = typeSelector);

}
}
}
28 changes: 16 additions & 12 deletions src/Nest/Search/Search/SearchResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface ISearchResponse<T> : IResponse where T : class
ShardsMetaData Shards { get; }
HitsMetaData<T> HitsMetaData { get; }
IDictionary<string, IAggregate> Aggregations { get; }
Profile Profile { get; }
AggregationsHelper Aggs { get; }
IDictionary<string, Suggest[]> Suggest { get; }
int Took { get; }
Expand All @@ -20,9 +21,9 @@ public interface ISearchResponse<T> : IResponse where T : class
long Total { get; }
double MaxScore { get; }
/// <summary>
/// Returns a view on the documents inside the hits that are returned.
/// <para>NOTE: if you use Fields() on the search descriptor .Documents will be empty use
/// .Fields instead or try the 'source filtering' feature introduced in Elasticsearch 1.0
/// Returns a view on the documents inside the hits that are returned.
/// <para>NOTE: if you use Fields() on the search descriptor .Documents will be empty use
/// .Fields instead or try the 'source filtering' feature introduced in Elasticsearch 1.0
/// using .Source() on the search descriptor to get Documents of type T with only certain parts selected
/// </para>
/// </summary>
Expand Down Expand Up @@ -52,7 +53,10 @@ public class SearchResponse<T> : ResponseBase, ISearchResponse<T> where T : clas
[JsonProperty(PropertyName = "aggregations")]
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))]
public IDictionary<string, IAggregate> Aggregations { get; internal set; } = new Dictionary<string, IAggregate>();


[JsonProperty(PropertyName = "profile")]
public Profile Profile { get; internal set; }

private AggregationsHelper _agg = null;
[JsonIgnore]
public AggregationsHelper Aggs => _agg ?? (_agg = new AggregationsHelper(this.Aggregations));
Expand Down Expand Up @@ -81,20 +85,20 @@ public class SearchResponse<T> : ResponseBase, ISearchResponse<T> where T : clas
[JsonIgnore]
public double MaxScore => this.HitsMetaData?.MaxScore ?? 0;

private IList<T> _documents;
private IList<T> _documents;
/// <inheritdoc/>
[JsonIgnore]
public IEnumerable<T> Documents =>
public IEnumerable<T> Documents =>
this._documents ?? (this._documents = this.Hits
.Select(h => h.Source)
.ToList());

[JsonIgnore]
public IEnumerable<IHit<T>> Hits => this.HitsMetaData?.Hits ?? Enumerable.Empty<IHit<T>>();

private IList<FieldValues> _fields;
private IList<FieldValues> _fields;
/// <inheritdoc/>
public IEnumerable<FieldValues> Fields =>
public IEnumerable<FieldValues> Fields =>
this._fields ?? (this._fields = this.Hits
.Select(h => h.Fields)
.ToList());
Expand All @@ -108,12 +112,12 @@ public HighlightDocumentDictionary Highlights
{
get
{
if (_highlights != null) return _highlights;
if (_highlights != null) return _highlights;

var dict = new HighlightDocumentDictionary();
if (this.HitsMetaData == null || !this.HitsMetaData.Hits.HasAny())
return dict;


foreach (var hit in this.HitsMetaData.Hits)
{
Expand All @@ -126,4 +130,4 @@ public HighlightDocumentDictionary Highlights
}
}
}
}
}
Loading