Skip to content

Commit

Permalink
Fields() on SearchDescriptor missing string overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Jul 30, 2012
1 parent 98758a1 commit f2d79d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Nest.Tests.Unit/JsonifyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ public void TestFields()
Assert.True(json.JsonEquals(expected));
}
[Test]
public void TestFieldsByName()
{
var s = new SearchDescriptor<ElasticSearchProject>()
.From(0)
.Size(10)
.Fields("id", "name");
var json = ElasticClient.Serialize(s);
var expected = @"{ from: 0, size: 10,
fields: [""id"", ""name""]
}";
Assert.True(json.JsonEquals(expected));
}
[Test]
public void TestSort()
{
var s = new SearchDescriptor<ElasticSearchProject>()
Expand Down
11 changes: 10 additions & 1 deletion src/Nest/DSL/Descriptors/SearchDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public SearchDescriptor()
internal bool? _Explain { get; set; }
[JsonProperty(PropertyName = "version")]
internal bool? _Version { get; set; }
[JsonProperty(PropertyName = "track_scores ")]
[JsonProperty(PropertyName = "track_scores ")]
internal bool? _TrackScores { get; set; }

[JsonProperty(PropertyName = "min_score")]
Expand Down Expand Up @@ -350,6 +350,15 @@ public SearchDescriptor<T> Fields(params Expression<Func<T, object>>[] expressio
return this;
}
/// <summary>
/// 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(params string[] fields)
{
this._Fields = fields;
return this;
}
/// <summary>
/// <para>Allows to add one or more sort on specific fields. Each sort can be reversed as well.
/// The sort is defined on a per field level, with special field name for _score to sort by score.
/// </para>
Expand Down

1 comment on commit f2d79d6

@q42jaap
Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, I needed that today, I came up with a workaround:
public class ClassWithId { public string Id { get; set; } }

To get the id of a document only (to avoid loading _source)

Please sign in to comment.