Skip to content

Commit a556610

Browse files
committed
removed _partial support (to be replaced by source include and exclude)
1 parent 5ba0fe8 commit a556610

File tree

17 files changed

+281
-404
lines changed

17 files changed

+281
-404
lines changed

src/CodeGeneration/CodeGeneration.LowLevelClient/Overrides/Descriptors/SearchDescriptorOverrides.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public IEnumerable<string> SkipQueryStringParams
3333
"version",
3434
"q", //we dont support GET searches
3535
"fields",
36-
"sort"
36+
"sort",
37+
"_source",
38+
"_source_include",
39+
"_source_exclude"
3740
};
3841
}
3942
}

src/Nest/DSL/FluentDictionary.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq.Expressions;
4+
using Nest.Resolvers;
25

36
namespace Nest
47
{
8+
public class FluentFieldList<T> : List<PropertyPathMarker> where T : class
9+
{
10+
public new FluentFieldList<T> Add(Expression<Func<T, object>> k)
11+
{
12+
base.Add(k);
13+
return this;
14+
}
15+
public new FluentFieldList<T> Add(string k)
16+
{
17+
base.Add(k);
18+
return this;
19+
}
20+
}
521
public class FluentDictionary<K, V> : Dictionary<K, V>
622
{
723
public FluentDictionary()

src/Nest/DSL/PartialFieldDescriptor.cs

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/Nest/DSL/SearchDescriptor.cs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,7 @@ internal RawOrFilterDescriptor<T> _FilterOrRaw
280280
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
281281
internal FluentDictionary<string, ScriptFilterDescriptor> _ScriptFields { get; set; }
282282

283-
[JsonProperty(PropertyName = "partial_fields")]
284-
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
285-
internal Dictionary<string, PartialFieldDescriptor<T>> _PartialFields { get; set; }
283+
286284

287285
/// <summary>
288286
/// The number of hits to return. Defaults to 10. When using scroll search type
@@ -449,6 +447,16 @@ public SearchDescriptor<T> Fields(params Expression<Func<T, object>>[] expressio
449447
this._Fields = expressions.Select(e => (PropertyPathMarker)e).ToList();
450448
return this;
451449
}
450+
451+
/// <summary>
452+
/// Allows to selectively load specific fields for each document
453+
/// represented by a search hit. Defaults to load the internal _source field.
454+
/// </summary>
455+
public SearchDescriptor<T> Fields(Func<FluentFieldList<T>, FluentFieldList<T>> properties)
456+
{
457+
this._Fields = properties(new FluentFieldList<T>()).ToList();
458+
return this;
459+
}
452460
/// <summary>
453461
/// Allows to selectively load specific fields for each document
454462
/// represented by a search hit. Defaults to load the internal _source field.
@@ -480,30 +488,6 @@ public SearchDescriptor<T> ScriptFields(
480488
return this;
481489
}
482490

483-
public SearchDescriptor<T> PartialFields(params Action<PartialFieldDescriptor<T>>[] partialFieldDescriptor)
484-
{
485-
if (this._PartialFields == null)
486-
this._PartialFields = new Dictionary<string, PartialFieldDescriptor<T>>();
487-
488-
var descriptors = new List<PartialFieldDescriptor<T>>();
489-
490-
foreach (var selector in partialFieldDescriptor)
491-
{
492-
var filter = new PartialFieldDescriptor<T>();
493-
selector(filter);
494-
descriptors.Add(filter);
495-
}
496-
497-
foreach (var d in descriptors)
498-
{
499-
var key = d._Field;
500-
if (string.IsNullOrEmpty(key))
501-
throw new DslException("Could not infer key for highlight field descriptor");
502-
503-
this._PartialFields.Add(key, d);
504-
}
505-
return this;
506-
}
507491

508492
/// <summary>
509493
/// <para>Allows to add one or more sort on specific fields. Each sort can be reversed as well.

src/Nest/DSL/_Descriptors.generated.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4456,30 +4456,6 @@ public SearchDescriptor<T> Source(string source)
44564456
}
44574457

44584458

4459-
///<summary>True or false to return the _source field or not, or a list of fields to return</summary>
4460-
public SearchDescriptor<T> Source(params string[] _source)
4461-
{
4462-
this._QueryString.Source(_source);
4463-
return this;
4464-
}
4465-
4466-
4467-
///<summary>A list of fields to exclude from the returned _source field</summary>
4468-
public SearchDescriptor<T> SourceExclude(params string[] _source_exclude)
4469-
{
4470-
this._QueryString.SourceExclude(_source_exclude);
4471-
return this;
4472-
}
4473-
4474-
4475-
///<summary>A list of fields to extract and return from the _source field</summary>
4476-
public SearchDescriptor<T> SourceInclude(params string[] _source_include)
4477-
{
4478-
this._QueryString.SourceInclude(_source_include);
4479-
return this;
4480-
}
4481-
4482-
44834459
///<summary>Specific &#39;tag&#39; of the request for logging and statistical purposes</summary>
44844460
public SearchDescriptor<T> Stats(params string[] stats)
44854461
{

src/Nest/Domain/CovariantDictionary.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/Nest/Domain/FieldSelection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Nest.Domain
1313
{
14-
public interface IFieldSelection<out T>
14+
public interface IFieldSelection<T>
1515
{
1616

1717
}

src/Nest/Domain/Hit/Hit.cs

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,47 @@
88
namespace Nest
99
{
1010
//[JsonConverter(typeof(ConcreteTypeConverter))]
11-
public interface IHit<out T> where T : class
12-
{
13-
IFieldSelection<T> Fields { get; }
14-
T Source { get; }
15-
string Index { get; }
16-
double Score { get; }
17-
string Type { get; }
18-
string Version { get; }
19-
string Id { get; }
11+
public interface IHit<out T> where T : class
12+
{
13+
//IFieldSelection<T> Fields { get; }
14+
T Source { get; }
15+
string Index { get; }
16+
double Score { get; }
17+
string Type { get; }
18+
string Version { get; }
19+
string Id { get; }
2020

21-
IEnumerable<object> Sorts { get; }
21+
IEnumerable<object> Sorts { get; }
2222

2323
HighlightFieldDictionary Highlights { get; }
24-
Explanation Explanation { get; }
25-
ICovariantDictionary<T> PartialFields { get; }
26-
}
24+
Explanation Explanation { get; }
25+
}
2726

28-
[JsonObject]
29-
public class Hit<T> : IHit<T>
30-
where T : class
31-
{
32-
[JsonProperty(PropertyName = "fields")]
27+
[JsonObject]
28+
public class Hit<T> : IHit<T>
29+
where T : class
30+
{
31+
[JsonProperty(PropertyName = "fields")]
3332
internal IDictionary<string, object> _fields { get; set; }
3433
[JsonIgnore]
35-
public IFieldSelection<T> Fields { get; internal set; }
36-
[JsonProperty(PropertyName = "_source")]
37-
public T Source { get; internal set; }
38-
[JsonProperty(PropertyName = "_index")]
39-
public string Index { get; internal set; }
40-
[JsonProperty(PropertyName = "_score")]
41-
public double Score { get; internal set; }
42-
[JsonProperty(PropertyName = "_type")]
43-
public string Type { get; internal set; }
44-
[JsonProperty(PropertyName = "_version")]
45-
public string Version { get; internal set; }
46-
[JsonProperty(PropertyName = "_id")]
47-
public string Id { get; internal set; }
34+
public FieldSelection<T> Fields { get; internal set; }
35+
[JsonProperty(PropertyName = "_source")]
36+
public T Source { get; internal set; }
37+
[JsonProperty(PropertyName = "_index")]
38+
public string Index { get; internal set; }
39+
[JsonProperty(PropertyName = "_score")]
40+
public double Score { get; internal set; }
41+
[JsonProperty(PropertyName = "_type")]
42+
public string Type { get; internal set; }
43+
[JsonProperty(PropertyName = "_version")]
44+
public string Version { get; internal set; }
45+
[JsonProperty(PropertyName = "_id")]
46+
public string Id { get; internal set; }
4847

49-
[JsonProperty(PropertyName = "sort")]
50-
public IEnumerable<object> Sorts { get; internal set; }
48+
[JsonProperty(PropertyName = "sort")]
49+
public IEnumerable<object> Sorts { get; internal set; }
5150

52-
[JsonProperty(PropertyName = "highlight")]
51+
[JsonProperty(PropertyName = "highlight")]
5352
[JsonConverter(typeof(DictionaryKeysAreNotPropertyNamesJsonConverter))]
5453
internal Dictionary<string, List<string>> _Highlight { get; set; }
5554

@@ -65,21 +64,14 @@ public HighlightFieldDictionary Highlights
6564
DocumentId = this.Id,
6665
Field = kv.Key,
6766
Highlights = kv.Value
68-
}).ToDictionary(k=>k.Field, v=>v);
67+
}).ToDictionary(k => k.Field, v => v);
6968

7069
return new HighlightFieldDictionary(highlights);
71-
}
70+
}
7271
}
7372

7473
[JsonProperty(PropertyName = "_explanation")]
7574
public Explanation Explanation { get; internal set; }
7675

77-
78-
public ICovariantDictionary<T> PartialFields { get; internal set; }
79-
80-
public Hit()
81-
{
82-
83-
}
84-
}
76+
}
8577
}

src/Nest/Domain/Responses/QueryResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public IEnumerable<T> Documents
9393
}
9494
}
9595
}
96+
9697
[JsonIgnore]
9798
public IEnumerable<IHit<T>> Hits
9899
{
@@ -107,7 +108,6 @@ public IEnumerable<IHit<T>> Hits
107108
}
108109
}
109110

110-
111111
public F Facet<F>(Expression<Func<T, object>> expression) where F : class, IFacet
112112
{
113113
var fieldName = this.ConnectionStatus.Infer.PropertyPath(expression);

src/Nest/ExposedInternals/ElasticSerializer.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ public IQueryResponse<TResult> DeserializeSearchResponse<T, TResult>(ConnectionS
125125
{
126126
var types = (originalSearchDescriptor._Types ?? Enumerable.Empty<TypeNameMarker>())
127127
.Where(t => t.Type != null);
128-
var partialFields = originalSearchDescriptor._PartialFields.EmptyIfNull().Select(x => x.Key);
129-
if (originalSearchDescriptor._ConcreteTypeSelector == null && (
130-
types.Any(t => t.Type != typeof(TResult)))
131-
|| partialFields.Any())
128+
if (originalSearchDescriptor._ConcreteTypeSelector == null && types.Any(t => t.Type != typeof(TResult)))
132129
{
133130
var inferrer = new ElasticInferrer(this._settings);
134131
var typeDictionary = types
@@ -148,7 +145,7 @@ public IQueryResponse<TResult> DeserializeSearchResponse<T, TResult>(ConnectionS
148145

149146
return this.DeserializeInternal<QueryResponse<TResult>>(
150147
status,
151-
piggyBackJsonConverter: new ConcreteTypeConverter<TResult>(originalSearchDescriptor._ConcreteTypeSelector, partialFields)
148+
piggyBackJsonConverter: new ConcreteTypeConverter<TResult>(originalSearchDescriptor._ConcreteTypeSelector)
152149
);
153150
}
154151

0 commit comments

Comments
 (0)