Skip to content

Commit 2156ea1

Browse files
authored
Add SequenceNumber and PrimaryTerm to Hits, Get and MulitGetHit (#3714)
* Add SequenceNumber and PrimaryTerm to Hits, Get and MulitGetHit This commit adds the SequenceNumber and PrimaryTerm properties to the Hit<T>, MultiGetHit<T> and GetResponse. * Update SeqNo and SeqNoPrimaryTerm This commit updates - SeqNo - SeqNoPrimaryTerm - IfSeqNo to expand SeqNo out to SequenceNumber, in generated types and methods, ofr consistency Closes #3708
1 parent eba1a5a commit 2156ea1

File tree

15 files changed

+147
-69
lines changed

15 files changed

+147
-69
lines changed

src/CodeGeneration/ApiGenerator/Overrides/GlobalOverrides.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class GlobalOverrides : EndpointOverridesBase
3838
{ "s", "sort_by_columns" },
3939
{ "v", "verbose" },
4040
{ "ts", "include_timestamp" },
41+
{ "if_seq_no", "if_sequence_number" },
42+
{ "seq_no_primary_term", "sequence_number_primary_term" },
4143
};
4244

4345
public override IEnumerable<string> RenderPartial => new[]

src/Elasticsearch.Net/Domain/RequestParameters/RequestParameters.Generated.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ public class DeleteRequestParameters : RequestParameters<DeleteRequestParameters
645645
///<summary>Explicit operation timeout</summary>
646646
public TimeSpan Timeout { get => Q<TimeSpan>("timeout"); set => Q("timeout", value); }
647647
///<summary>only perform the delete operation if the last operation that has changed the document has the specified sequence number</summary>
648-
public long? IfSeqNo { get => Q<long?>("if_seq_no"); set => Q("if_seq_no", value); }
648+
public long? IfSequenceNumber { get => Q<long?>("if_seq_no"); set => Q("if_seq_no", value); }
649649
///<summary>only perform the delete operation if the last operation that has changed the document has the specified primary term</summary>
650650
public long? IfPrimaryTerm { get => Q<long?>("if_primary_term"); set => Q("if_primary_term", value); }
651651
///<summary>Explicit version number for concurrency control</summary>
@@ -919,7 +919,7 @@ public class IndexRequestParameters : RequestParameters<IndexRequestParameters>
919919
///<summary>Specific version type</summary>
920920
public VersionType? VersionType { get => Q<VersionType?>("version_type"); set => Q("version_type", value); }
921921
///<summary>only perform the index operation if the last operation that has changed the document has the specified sequence number</summary>
922-
public long? IfSeqNo { get => Q<long?>("if_seq_no"); set => Q("if_seq_no", value); }
922+
public long? IfSequenceNumber { get => Q<long?>("if_seq_no"); set => Q("if_seq_no", value); }
923923
///<summary>only perform the index operation if the last operation that has changed the document has the specified primary term</summary>
924924
public long? IfPrimaryTerm { get => Q<long?>("if_primary_term"); set => Q("if_primary_term", value); }
925925
///<summary>The pipeline id to preprocess incoming documents with</summary>
@@ -1839,7 +1839,7 @@ public class SearchRequestParameters : RequestParameters<SearchRequestParameters
18391839
///<summary>Specify whether aggregation and suggester names should be prefixed by their respective types in the response</summary>
18401840
public bool? TypedKeys { get => Q<bool?>("typed_keys"); set => Q("typed_keys", value); }
18411841
///<summary>Specify whether to return sequence number and primary term of the last modification of each hit</summary>
1842-
public bool? SeqNoPrimaryTerm { get => Q<bool?>("seq_no_primary_term"); set => Q("seq_no_primary_term", value); }
1842+
public bool? SequenceNumberPrimaryTerm { get => Q<bool?>("seq_no_primary_term"); set => Q("seq_no_primary_term", value); }
18431843
///<summary>Specify if request cache should be used for this request or not, defaults to index level setting</summary>
18441844
public bool? RequestCache { get => Q<bool?>("request_cache"); set => Q("request_cache", value); }
18451845
///<summary>
@@ -2097,7 +2097,7 @@ public class UpdateRequestParameters : RequestParameters<UpdateRequestParameters
20972097
///<summary>Explicit operation timeout</summary>
20982098
public TimeSpan Timeout { get => Q<TimeSpan>("timeout"); set => Q("timeout", value); }
20992099
///<summary>only perform the update operation if the last operation that has changed the document has the specified sequence number</summary>
2100-
public long? IfSeqNo { get => Q<long?>("if_seq_no"); set => Q("if_seq_no", value); }
2100+
public long? IfSequenceNumber { get => Q<long?>("if_seq_no"); set => Q("if_seq_no", value); }
21012101
///<summary>only perform the update operation if the last operation that has changed the document has the specified primary term</summary>
21022102
public long? IfPrimaryTerm { get => Q<long?>("if_primary_term"); set => Q("if_primary_term", value); }
21032103
}
@@ -2834,7 +2834,7 @@ public class PutWatchRequestParameters : RequestParameters<PutWatchRequestParame
28342834
///<summary>Explicit version number for concurrency control</summary>
28352835
public long? Version { get => Q<long?>("version"); set => Q("version", value); }
28362836
///<summary>only update the watch if the last operation that has changed the watch has the specified sequence number</summary>
2837-
public long? IfSeqNo { get => Q<long?>("if_seq_no"); set => Q("if_seq_no", value); }
2837+
public long? IfSequenceNumber { get => Q<long?>("if_seq_no"); set => Q("if_seq_no", value); }
28382838
///<summary>only update the watch if the last operation that has changed the watch has the specified primary term</summary>
28392839
public long? IfPrimaryTerm { get => Q<long?>("if_primary_term"); set => Q("if_primary_term", value); }
28402840
}

src/Nest/Document/Multiple/Bulk/BulkOperation/BulkDelete.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface IBulkDeleteOperation<T> : IBulkOperation
1111
T Document { get; set; }
1212

1313
[DataMember(Name = "if_seq_no")]
14-
long? IfSeqNo { get; set; }
14+
long? IfSequenceNumber { get; set; }
1515

1616
[DataMember(Name = "if_primary_term")]
1717
long? IfPrimaryTerm { get; set; }
@@ -27,7 +27,7 @@ public class BulkDeleteOperation<T> : BulkOperationBase, IBulkDeleteOperation<T>
2727

2828
public T Document { get; set; }
2929

30-
public long? IfSeqNo { get; set; }
30+
public long? IfSequenceNumber { get; set; }
3131

3232
public long? IfPrimaryTerm { get; set; }
3333

@@ -48,7 +48,7 @@ public class BulkDeleteDescriptor<T> : BulkOperationDescriptorBase<BulkDeleteDes
4848
{
4949
protected override Type BulkOperationClrType => typeof(T);
5050
protected override string BulkOperationType => "delete";
51-
long? IBulkDeleteOperation<T>.IfSeqNo { get; set; }
51+
long? IBulkDeleteOperation<T>.IfSequenceNumber { get; set; }
5252
long? IBulkDeleteOperation<T>.IfPrimaryTerm { get; set; }
5353

5454
T IBulkDeleteOperation<T>.Document { get; set; }
@@ -64,7 +64,7 @@ public class BulkDeleteDescriptor<T> : BulkOperationDescriptorBase<BulkDeleteDes
6464
/// </summary>
6565
public BulkDeleteDescriptor<T> Document(T @object) => Assign(@object, (a, v) => a.Document = v);
6666

67-
public BulkDeleteDescriptor<T> IfSeqNo(long? seqNo) => Assign(seqNo, (a, v) => a.IfSeqNo = v);
67+
public BulkDeleteDescriptor<T> IfSequenceNumber(long? sequenceNumber) => Assign(sequenceNumber, (a, v) => a.IfSequenceNumber = v);
6868

6969
public BulkDeleteDescriptor<T> IfPrimaryTerm(long? primaryTerm) => Assign(primaryTerm, (a, v) => a.IfPrimaryTerm = v);
7070
}

src/Nest/Document/Multiple/Bulk/BulkOperation/BulkIndex.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IBulkIndexOperation<T> : IBulkOperation
1717
string Pipeline { get; set; }
1818

1919
[DataMember(Name = "if_seq_no")]
20-
long? IfSeqNo { get; set; }
20+
long? IfSequenceNumber { get; set; }
2121

2222
[DataMember(Name = "if_primary_term")]
2323
long? IfPrimaryTerm { get; set; }
@@ -35,7 +35,7 @@ public class BulkIndexOperation<T> : BulkOperationBase, IBulkIndexOperation<T>
3535

3636
public string Pipeline { get; set; }
3737

38-
public long? IfSeqNo { get; set; }
38+
public long? IfSequenceNumber { get; set; }
3939

4040
public long? IfPrimaryTerm { get; set; }
4141

@@ -59,7 +59,7 @@ public class BulkIndexDescriptor<T> : BulkOperationDescriptorBase<BulkIndexDescr
5959
T IBulkIndexOperation<T>.Document { get; set; }
6060
string IBulkIndexOperation<T>.Percolate { get; set; }
6161
string IBulkIndexOperation<T>.Pipeline { get; set; }
62-
long? IBulkIndexOperation<T>.IfSeqNo { get; set; }
62+
long? IBulkIndexOperation<T>.IfSequenceNumber { get; set; }
6363
long? IBulkIndexOperation<T>.IfPrimaryTerm { get; set; }
6464

6565
protected override object GetBulkOperationBody() => Self.Document;
@@ -80,8 +80,8 @@ public class BulkIndexDescriptor<T> : BulkOperationDescriptorBase<BulkIndexDescr
8080

8181
public BulkIndexDescriptor<T> Percolate(string percolate) => Assign(percolate, (a, v) => a.Percolate = v);
8282

83-
public BulkIndexDescriptor<T> IfSeqNo(long? seqNo) => Assign(seqNo, (a, v) => a.IfSeqNo = v);
83+
public BulkIndexDescriptor<T> IfSequenceNumber(long? seqNo) => Assign(seqNo, (a, v) => a.IfSequenceNumber = v);
8484

85-
public BulkIndexDescriptor<T> IfPrimaryTerm(long? primaryTerm) => Assign(primaryTerm, (a, v) => a.IfSeqNo = v);
85+
public BulkIndexDescriptor<T> IfPrimaryTerm(long? primaryTerm) => Assign(primaryTerm, (a, v) => a.IfSequenceNumber = v);
8686
}
8787
}

src/Nest/Document/Multiple/MultiGet/Response/MultiGetHit.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public interface IMultiGetHit<out TDocument> where TDocument : class
2222
string Type { get; }
2323

2424
long Version { get; }
25+
26+
long? SequenceNumber { get; }
27+
28+
long? PrimaryTerm { get; }
2529
}
2630

2731
[DataContract]
@@ -55,5 +59,11 @@ public class MultiGetHit<TDocument> : IMultiGetHit<TDocument>
5559

5660
[DataMember(Name = "_version")]
5761
public long Version { get; internal set; }
62+
63+
[DataMember(Name = "_seq_no")]
64+
public long? SequenceNumber { get; internal set; }
65+
66+
[DataMember(Name = "_primary_term")]
67+
public long? PrimaryTerm { get; internal set; }
5868
}
5969
}

src/Nest/Document/Single/Get/GetResponse.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
using System;
2-
using System.Runtime.Serialization;
1+
using System.Runtime.Serialization;
32
using Elasticsearch.Net;
43

54
namespace Nest
65
{
6+
// TODO: Looks like this can be removed?
77
public interface IGetResponse<out TDocument> : IResponse where TDocument : class
88
{
99
TDocument Source { get; }
1010
}
11+
1112
public class GetResponse<TDocument> : ResponseBase, IGetResponse<TDocument> where TDocument : class
1213
{
1314
[DataMember(Name = "fields")]
@@ -22,9 +23,15 @@ public class GetResponse<TDocument> : ResponseBase, IGetResponse<TDocument> wher
2223
[DataMember(Name = "_index")]
2324
public string Index { get; internal set; }
2425

26+
[DataMember(Name = "_primary_term")]
27+
public long? PrimaryTerm { get; internal set; }
28+
2529
[DataMember(Name = "_routing")]
2630
public string Routing { get; internal set; }
2731

32+
[DataMember(Name = "_seq_no")]
33+
public long? SequenceNumber { get; internal set; }
34+
2835
[DataMember(Name = "_source")]
2936
[JsonFormatter(typeof(SourceFormatter<>))]
3037
public TDocument Source { get; internal set; }

src/Nest/Search/Search/Hits/Hit.cs

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ public interface IHitMetadata<out TDocument> where TDocument : class
1111
{
1212
[DataMember(Name = "_id")]
1313
string Id { get; }
14+
1415
[DataMember(Name = "_index")]
1516
string Index { get; }
17+
18+
[DataMember(Name = "_primary_term")]
19+
long? PrimaryTerm { get; }
20+
1621
[DataMember(Name = "_routing")]
1722
string Routing { get; }
1823

24+
[DataMember(Name = "_seq_no")]
25+
long? SequenceNumber { get; }
26+
1927
[DataMember(Name = "_source")]
2028
[JsonFormatter(typeof(SourceFormatter<>))]
2129
TDocument Source { get; }
@@ -25,7 +33,7 @@ public interface IHitMetadata<out TDocument> where TDocument : class
2533
string Type { get; }
2634

2735
[DataMember(Name = "_version")]
28-
long? Version { get; }
36+
long Version { get; }
2937
}
3038

3139
internal static class HitMetadataConversionExtensions
@@ -39,9 +47,7 @@ public static IHitMetadata<TTarget> Copy<TDocument, TTarget>(this IHitMetadata<T
3947
Type = source.Type,
4048
Index = source.Index,
4149
Id = source.Id,
42-
#pragma warning disable 618
4350
Routing = source.Routing,
44-
#pragma warning restore 618
4551
Source = mapper(source.Source)
4652
};
4753
}
@@ -58,52 +64,38 @@ public interface IHit<out TDocument> : IHitMetadata<TDocument>
5864
[DataMember(Name = "fields")]
5965
FieldValues Fields { get; }
6066

67+
/// <summary> see <see cref="Highlights" /> for easier access into this data structure </summary>
68+
[DataMember(Name = "highlight")]
69+
[JsonFormatter(typeof(VerbatimDictionaryKeysBaseFormatter<Dictionary<string, List<string>>, string, List<string>>))]
70+
Dictionary<string, List<string>> Highlight { get; }
71+
72+
// TODO investigate this mapping
73+
/// <summary> This provides easier access into <see cref="Highlight" /> </summary>
74+
[IgnoreDataMember]
75+
HighlightFieldDictionary Highlights { get; }
76+
6177
[DataMember(Name = "inner_hits")]
6278
[JsonFormatter(typeof(VerbatimInterfaceReadOnlyDictionaryKeysFormatter<string, InnerHitsResult>))]
6379
IReadOnlyDictionary<string, InnerHitsResult> InnerHits { get; }
6480

65-
[DataMember(Name = "_nested")]
66-
NestedIdentity Nested { get; }
67-
6881
[DataMember(Name = "matched_queries")]
6982
IReadOnlyCollection<string> MatchedQueries { get; }
7083

84+
[DataMember(Name = "_nested")]
85+
NestedIdentity Nested { get; }
86+
7187
[DataMember(Name = "_score")]
7288
double? Score { get; }
7389

7490
[DataMember(Name = "sort")]
7591
IReadOnlyCollection<object> Sorts { get; }
76-
77-
// TODO investigate this mapping
78-
/// <summary> This provides easier access into <see cref="Highlight"/> </summary>
79-
[IgnoreDataMember]
80-
HighlightFieldDictionary Highlights { get; }
81-
82-
/// <summary> see <see cref="Highlights"/> for easier access into this data structure </summary>
83-
[DataMember(Name = "highlight")]
84-
[JsonFormatter(typeof(VerbatimDictionaryKeysBaseFormatter<Dictionary<string, List<string>>, string, List<string>>))]
85-
Dictionary<string, List<string>> Highlight { get; }
8692
}
8793

8894
public class Hit<TDocument> : IHit<TDocument>
8995
where TDocument : class
9096
{
9197
public Explanation Explanation { get; internal set; }
9298
public FieldValues Fields { get; internal set; }
93-
public string Id { get; internal set; }
94-
public string Index { get; internal set; }
95-
public IReadOnlyDictionary<string, InnerHitsResult> InnerHits { get; internal set; } =
96-
EmptyReadOnly<string, InnerHitsResult>.Dictionary;
97-
public IReadOnlyCollection<string> MatchedQueries { get; internal set; }
98-
= EmptyReadOnly<string>.Collection;
99-
public NestedIdentity Nested { get; internal set; }
100-
public string Routing { get; internal set; }
101-
public double? Score { get; set; }
102-
public IReadOnlyCollection<object> Sorts { get; internal set; }
103-
= EmptyReadOnly<object>.Collection;
104-
public TDocument Source { get; internal set; }
105-
public string Type { get; internal set; }
106-
public long? Version { get; internal set; }
10799

108100
public Dictionary<string, List<string>> Highlight { get; set; }
109101

@@ -114,17 +106,33 @@ public HighlightFieldDictionary Highlights
114106
if (Highlight == null)
115107
return new HighlightFieldDictionary();
116108

117-
var highlights = Highlight.Select(kv => new HighlightHit
118-
{
119-
DocumentId = Id,
120-
Field = kv.Key,
121-
Highlights = kv.Value
122-
})
109+
var highlights = Highlight.Select(kv => new HighlightHit { DocumentId = Id, Field = kv.Key, Highlights = kv.Value })
123110
.ToDictionary(k => k.Field, v => v);
124111

125112
return new HighlightFieldDictionary(highlights);
126113
}
127114
}
128115

116+
public string Id { get; internal set; }
117+
public string Index { get; internal set; }
118+
119+
public IReadOnlyDictionary<string, InnerHitsResult> InnerHits { get; internal set; } =
120+
EmptyReadOnly<string, InnerHitsResult>.Dictionary;
121+
122+
public IReadOnlyCollection<string> MatchedQueries { get; internal set; }
123+
= EmptyReadOnly<string>.Collection;
124+
125+
public NestedIdentity Nested { get; internal set; }
126+
public long? PrimaryTerm { get; internal set; }
127+
public string Routing { get; internal set; }
128+
public double? Score { get; set; }
129+
public long? SequenceNumber { get; internal set; }
130+
131+
public IReadOnlyCollection<object> Sorts { get; internal set; }
132+
= EmptyReadOnly<object>.Collection;
133+
134+
public TDocument Source { get; internal set; }
135+
public string Type { get; internal set; }
136+
public long Version { get; internal set; }
129137
}
130138
}

0 commit comments

Comments
 (0)