Skip to content

Commit 43f0cd5

Browse files
committed
Merge pull request #644 from danp60/feature/doc_values
Support doc_values attributes on numeric and string mappings and in ElasticProperty attributes
2 parents 88d9dbd + e77d16e commit 43f0cd5

File tree

10 files changed

+940
-875
lines changed

10 files changed

+940
-875
lines changed

src/Nest/Domain/Mapping/Attributes/ElasticPropertyAttribute.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public class ElasticPropertyAttribute : Attribute, IElasticPropertyAttribute
2121
public string Analyzer { get; set; }
2222
public string IndexAnalyzer { get; set; }
2323
public string SearchAnalyzer { get; set; }
24-
public string SortAnalyzer { get; set; }
24+
public string SortAnalyzer { get; set; }
2525
public string NullValue { get; set; }
26-
public string Similarity { get; set; }
26+
public string Similarity { get; set; }
27+
28+
public bool DocValues { get; set; }
2729

2830
public bool OmitNorms { get; set; }
2931
public bool OmitTermFrequencyAndPositions { get; set; }

src/Nest/Domain/Mapping/Attributes/IElasticPropertyAttribute.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
public interface IElasticPropertyAttribute
33
{
44
bool AddSortField { get; set; }
5-
5+
66
bool OptOut { get; set; }
77
string Name { get; set; }
88

@@ -22,7 +22,9 @@ public interface IElasticPropertyAttribute
2222
bool OmitNorms { get; set; }
2323
bool OmitTermFrequencyAndPositions { get; set; }
2424
bool IncludeInAll { get; set; }
25-
bool Store { get; set; }
25+
bool Store { get; set; }
26+
27+
bool DocValues { get; set; }
2628

2729
string Similarity { get; set; }
2830

src/Nest/Domain/Mapping/Descriptors/NumberMappingDescriptor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public NumberMappingDescriptor<T> PrecisionStep(int precisionStep)
6060
return this;
6161
}
6262

63+
public NumberMappingDescriptor<T> DocValues(bool docValues = true)
64+
{
65+
this._Mapping.DocValues = docValues;
66+
return this;
67+
}
68+
6369
public NumberMappingDescriptor<T> IncludeInAll(bool includeInAll = true)
6470
{
6571
this._Mapping.IncludeInAll = includeInAll;

src/Nest/Domain/Mapping/Descriptors/StringMappingDescriptor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public StringMappingDescriptor<T> SearchAnalyzer(string searchAnalyzer)
7676
this._Mapping.SearchAnalyzer = searchAnalyzer;
7777
return this;
7878
}
79+
public StringMappingDescriptor<T> DocValues(bool docValues = true)
80+
{
81+
this._Mapping.DocValues = docValues;
82+
return this;
83+
}
7984
public StringMappingDescriptor<T> IncludeInAll(bool includeInAll = true)
8085
{
8186
this._Mapping.IncludeInAll = includeInAll;

src/Nest/Domain/Mapping/Types/NumberMapping.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class NumberMapping : IElasticType, IElasticCoreType
4040
[JsonProperty("null_value")]
4141
public double? NullValue { get; set; }
4242

43+
[JsonProperty("doc_values")]
44+
public bool? DocValues { get; set; }
45+
4346
[JsonProperty("include_in_all")]
4447
public bool? IncludeInAll { get; set; }
4548

src/Nest/Domain/Mapping/Types/StringMapping.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public class StringMapping : IElasticType, IElasticCoreType
5555
[JsonProperty("search_analyzer")]
5656
public string SearchAnalyzer { get; set; }
5757

58+
[JsonProperty("doc_values")]
59+
public bool? DocValues { get; set; }
60+
5861
[JsonProperty("include_in_all")]
5962
public bool? IncludeInAll { get; set; }
6063

src/Nest/Resolvers/Writers/WritePropertiesFromAttributeVisitor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public void VisitBaseAttribute(IElasticPropertyAttribute att) {
8888
this._jsonWriter.WritePropertyName("omit_norms");
8989
this._jsonWriter.WriteValue("true");
9090
}
91+
if (att.DocValues)
92+
{
93+
this._jsonWriter.WritePropertyName("doc_values");
94+
this._jsonWriter.WriteValue("true");
95+
}
9196
if (att.OmitTermFrequencyAndPositions)
9297
{
9398
this._jsonWriter.WritePropertyName("omit_term_freq_and_positions");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"docvaluesfoo": {
3+
"properties": {
4+
"id": {
5+
"type": "integer"
6+
},
7+
"value": {
8+
"type": "integer",
9+
"doc_values": true
10+
}
11+
}
12+
}
13+
}

src/Tests/Nest.Tests.Unit/Core/Map/Properties/PropertiesTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,31 @@ public void GeoShapeProperty()
246246
)
247247
);
248248
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
249+
}
250+
251+
public class DocValuesFoo
252+
{
253+
public int Id { get; set; }
254+
[ElasticProperty(DocValues=true)]
255+
public int Value { get; set; }
256+
}
257+
258+
[Test]
259+
public void DocValuesProperty()
260+
{
261+
var result = this._client.Map<DocValuesFoo>(m => m.MapFromAttributes());
262+
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
263+
264+
var result2 = this._client.Map<DocValuesFoo>(m => m
265+
.Properties(props => props
266+
.Number(nmd => nmd
267+
.Name("id")
268+
.Type(NumberType.integer))
269+
.Number(nmd => nmd
270+
.Name("value")
271+
.Type(NumberType.integer)
272+
.DocValues())));
273+
this.JsonEquals(result2.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
249274
}
250275

251276
}

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 872 additions & 871 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)