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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public IEnumerable<string> SkipQueryStringParams
"_source_include",
"_source_exclude",
"track_scores",
"terminate_after"
"terminate_after",
"fielddata_fields"
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5451,16 +5451,6 @@ public SearchRequestParameters Df(string df)
}


internal IEnumerable<object> _fielddata_fields { get; set; }
///<summary>A comma-separated list of fields to return as the field data representation of a field for each hit</summary>
public SearchRequestParameters FielddataFields(params string[] fielddata_fields)
{
this._fielddata_fields = fielddata_fields.Select(f=>(object)f);
this.AddQueryString("fielddata_fields", this._fielddata_fields);
return this;
}


internal bool _ignore_unavailable { get; set; }
///<summary>Whether specified concrete indices should be ignored when unavailable (missing or closed)</summary>
public SearchRequestParameters IgnoreUnavailable(bool ignore_unavailable)
Expand Down
13 changes: 9 additions & 4 deletions src/Nest/DSL/Search/IGlobalInnerHit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using System.Linq.Expressions;

namespace Nest
{
Expand Down Expand Up @@ -35,7 +36,7 @@ public class GlobalInnerHitDescriptor<T> : IGlobalInnerHit where T : class
bool? IInnerHits.Explain { get; set; }
ISourceFilter IInnerHits.Source { get; set; }
bool? IInnerHits.Version { get; set; }
IEnumerable<string> IInnerHits.FielddataFields { get; set; }
IList<PropertyPathMarker> IInnerHits.FielddataFields { get; set; }
IDictionary<string, IScriptFilter> IInnerHits.ScriptFields { get; set; }

public GlobalInnerHitDescriptor<T> Query(Func<QueryDescriptor<T>, IQueryContainer> querySelector)
Expand Down Expand Up @@ -89,13 +90,17 @@ public GlobalInnerHitDescriptor<T> Name(string name)

public GlobalInnerHitDescriptor<T> FielddataFields(params string[] fielddataFields)
{
Self.FielddataFields = fielddataFields;
if (fielddataFields.HasAny())
return this;
Self.FielddataFields = fielddataFields.Select(f => (PropertyPathMarker)f).ToList();
return this;
}

public GlobalInnerHitDescriptor<T> FielddataFields(IEnumerable<string> fielddataFields)
public GlobalInnerHitDescriptor<T> FielddataFields(params Expression<Func<T, object>>[] fielddataFields)
{
Self.FielddataFields = fielddataFields;
if (!fielddataFields.HasAny())
return this;
Self.FielddataFields = fielddataFields.Select(e => (PropertyPathMarker)e).ToList();
return this;
}

Expand Down
16 changes: 10 additions & 6 deletions src/Nest/DSL/Search/InnerHitsDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface IInnerHits
bool? Version { get; set; }

[JsonProperty(PropertyName = "fielddata_fields")]
IEnumerable<string> FielddataFields { get; set; }
IList<PropertyPathMarker> FielddataFields { get; set; }

[JsonProperty(PropertyName = "script_fields")]
[JsonConverter(typeof (DictionaryKeysAreNotPropertyNamesJsonConverter))]
Expand All @@ -62,7 +62,7 @@ public class InnerHits : IInnerHits

public bool? Version { get; set; }

public IEnumerable<string> FielddataFields { get; set; }
public IList<PropertyPathMarker> FielddataFields { get; set; }

public IDictionary<string, IScriptFilter> ScriptFields { get; set; }
}
Expand All @@ -79,7 +79,7 @@ public class InnerHitsDescriptor<T> : IInnerHits where T : class
bool? IInnerHits.Explain { get; set; }
ISourceFilter IInnerHits.Source { get; set; }
bool? IInnerHits.Version { get; set; }
IEnumerable<string> IInnerHits.FielddataFields { get; set; }
IList<PropertyPathMarker> IInnerHits.FielddataFields { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ for catching this before releasing @gmarz !

IDictionary<string, IScriptFilter> IInnerHits.ScriptFields { get; set; }

public InnerHitsDescriptor<T> From(int? from)
Expand All @@ -102,13 +102,17 @@ public InnerHitsDescriptor<T> Name(string name)

public InnerHitsDescriptor<T> FielddataFields(params string[] fielddataFields)
{
Self.FielddataFields = fielddataFields;
if (fielddataFields.HasAny())
return this;
Self.FielddataFields = fielddataFields.Select(f => (PropertyPathMarker)f).ToList();
return this;
}

public InnerHitsDescriptor<T> FielddataFields(IEnumerable<string> fielddataFields)
public InnerHitsDescriptor<T> FielddataFields(params Expression<Func<T, object>>[] fielddataFields)
{
Self.FielddataFields = fielddataFields;
if (!fielddataFields.HasAny())
return this;
Self.FielddataFields = fielddataFields.Select(e => (PropertyPathMarker)e).ToList();
return this;
}

Expand Down
29 changes: 29 additions & 0 deletions src/Nest/DSL/SearchDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public interface ISearchRequest : IQueryPath<SearchRequestParameters>
[JsonProperty(PropertyName = "fields")]
IList<PropertyPathMarker> Fields { get; set; }

[JsonProperty(PropertyName = "fielddata_fields")]
IList<PropertyPathMarker> FielddataFields { get; set; }

[JsonProperty(PropertyName = "script_fields")]
[JsonConverter(typeof (DictionaryKeysAreNotPropertyNamesJsonConverter))]
IDictionary<string, IScriptFilter> ScriptFields { get; set; }
Expand Down Expand Up @@ -155,6 +158,7 @@ public SearchRequest(IEnumerable<IndexNameMarker> indices, IEnumerable<TypeNameM
public double? MinScore { get; set; }
public long? TerminateAfter { get; set; }
public IList<PropertyPathMarker> Fields { get; set; }
public IList<PropertyPathMarker> FielddataFields { get; set; }
public IDictionary<string, IScriptFilter> ScriptFields { get; set; }
public ISourceFilter Source { get; set; }
public IList<KeyValuePair<PropertyPathMarker, ISort>> Sort { get; set; }
Expand Down Expand Up @@ -237,6 +241,7 @@ protected override void UpdatePathInfo(IConnectionSettingsValues settings, Elast
public IHighlightRequest Highlight { get; set; }
public IRescore Rescore { get; set; }
public IList<PropertyPathMarker> Fields { get; set; }
public IList<PropertyPathMarker> FielddataFields { get; set; }
public IDictionary<string, IScriptFilter> ScriptFields { get; set; }
public ISourceFilter Source { get; set; }
public IDictionary<string, IInnerHitsContainer> InnerHits { get; set; }
Expand Down Expand Up @@ -350,6 +355,8 @@ string ISearchRequest.Routing

IList<PropertyPathMarker> ISearchRequest.Fields { get; set; }

IList<PropertyPathMarker> ISearchRequest.FielddataFields { get; set; }

IDictionary<string, IScriptFilter> ISearchRequest.ScriptFields { get; set; }

ISourceFilter ISearchRequest.Source { get; set; }
Expand Down Expand Up @@ -617,6 +624,28 @@ public SearchDescriptor<T> Fields(params string[] fields)
return this;
}

///<summary>
///A comma-separated list of fields to return as the field data representation of a field for each hit
///</summary>
public SearchDescriptor<T> FielddataFields(params string[] fielddataFields)
{
if (fielddataFields.HasAny())
return this;
Self.FielddataFields = fielddataFields.Select(f => (PropertyPathMarker)f).ToList();
return this;
}

///<summary>
///A comma-separated list of fields to return as the field data representation of a field for each hit
///</summary>
public SearchDescriptor<T> FielddataFields(params Expression<Func<T, object>>[] fielddataFields)
{
if (!fielddataFields.HasAny())
return this;
Self.FielddataFields = fielddataFields.Select(f => (PropertyPathMarker)f).ToList();
return this;
}

public SearchDescriptor<T> ScriptFields(
Func<FluentDictionary<string, Func<ScriptFilterDescriptor, ScriptFilterDescriptor>>,
FluentDictionary<string, Func<ScriptFilterDescriptor, ScriptFilterDescriptor>>> scriptFields)
Expand Down
19 changes: 0 additions & 19 deletions src/Nest/DSL/_Descriptors.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5079,25 +5079,6 @@ public SearchDescriptor<T> Df(string df)
}


///<summary>A comma-separated list of fields to return as the field data representation of a field for each hit</summary>
public SearchDescriptor<T> FielddataFields(params string[] fielddata_fields)
{
this.Request.RequestParameters.FielddataFields(fielddata_fields);
return this;
}


///<summary>A comma-separated list of fields to return as the field data representation of a field for each hit</summary>
public SearchDescriptor<T> FielddataFields(params Expression<Func<T, object>>[] typedPathLookups)
{
if (!typedPathLookups.HasAny())
return this;

this.Request.RequestParameters._FielddataFields(typedPathLookups);
return this;
}


///<summary>Whether specified concrete indices should be ignored when unavailable (missing or closed)</summary>
public SearchDescriptor<T> IgnoreUnavailable(bool ignore_unavailable = true)
{
Expand Down
16 changes: 0 additions & 16 deletions src/Nest/DSL/_Requests.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4572,14 +4572,6 @@ public string Df
}


///<summary>A comma-separated list of fields to return as the field data representation of a field for each hit</summary>
public IList<PropertyPathMarker> FielddataFields
{
get { return this.Request.RequestParameters.GetQueryStringValue<IList<PropertyPathMarker>>("fielddata_fields"); }
set { this.Request.RequestParameters.AddQueryString("fielddata_fields", value); }
}


///<summary>Whether specified concrete indices should be ignored when unavailable (missing or closed)</summary>
public bool IgnoreUnavailable
{
Expand Down Expand Up @@ -6481,14 +6473,6 @@ public string Df
}


///<summary>A comma-separated list of fields to return as the field data representation of a field for each hit</summary>
public IList<PropertyPathMarker> FielddataFields
{
get { return this.Request.RequestParameters.GetQueryStringValue<IList<PropertyPathMarker>>("fielddata_fields"); }
set { this.Request.RequestParameters.AddQueryString("fielddata_fields", value); }
}


///<summary>Whether specified concrete indices should be ignored when unavailable (missing or closed)</summary>
public bool IgnoreUnavailable
{
Expand Down
12 changes: 0 additions & 12 deletions src/Nest/Domain/RequestParametersExtensions.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,6 @@ internal static NodesStatsRequestParameters _Fields<T>(
}


///<summary>A comma-separated list of fields to return as the field data representation of a field for each hit</summary>
internal static SearchRequestParameters _FielddataFields<T>(
this SearchRequestParameters qs,
IEnumerable<Expression<Func<T, object>>> fielddata_fields)
where T : class
{
var _fielddata_fields = fielddata_fields.Select(e=>(PropertyPathMarker)e);
qs.AddQueryString("fielddata_fields", _fielddata_fields);
return qs;
}


///<summary>Specify which field to use for suggestions</summary>
internal static SearchRequestParameters _SuggestField<T>(
this SearchRequestParameters qs,
Expand Down
16 changes: 16 additions & 0 deletions src/Tests/Nest.Tests.Integration/Search/FieldTests/FieldsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,21 @@ public void Search_WithFieldsRemoved_ReturnsDocuments_ResultingArrayOfDocsShould
}

}

[Test]
public void FielddataFieldsTest()
{
var result = this.Client.Search<ElasticsearchProject>(s => s
.FielddataFields(p => p.Name)
);

result.IsValid.Should().BeTrue();

foreach(var hit in result.Hits)
{
var fieldValues = hit.Fields.FieldValues<string[]>("name");
fieldValues.Should().NotBeEmpty();
}
}
}
}
3 changes: 3 additions & 0 deletions src/Tests/Nest.Tests.Integration/Search/InnerHitsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void Search()
.InnerHits(innerInnerHits => innerInnerHits
.Add("barons", iii => iii.Type<Baron>())
)
.FielddataFields(p => p.Name)
)
)
.Add("princes", i => i.Type<Prince>())
Expand All @@ -136,6 +137,8 @@ public void Search()
var earlHits = hit.InnerHits["earls"].Hits;
earlHits.Total.Should().BeGreaterThan(0);
earlHits.Hits.Should().NotBeEmpty().And.HaveCount(5);
foreach(var earlHit in earlHits.Hits)
earlHit.Fields.FieldValues<string[]>("name").Should().NotBeEmpty();
var earls = earlHits.Documents<Earl>();
earls.Should().NotBeEmpty().And.OnlyContain(earl => !earl.Name.IsNullOrEmpty());
foreach (var earlHit in earlHits.Hits)
Expand Down