Skip to content

Commit

Permalink
Fix/6.1 deprecations (#2993)
Browse files Browse the repository at this point in the history
* bulk uses _routing while valid this produces deprecation warnings as per elastic/elasticsearch#27414

* update deprecated underscore params from more like this and added missing properties

* update multi get routing and add support for version/versiontype'

* updated term vectors request to include routing/version/version_type

* large min and max ngram setting

* max difference in shingle size in one test was too large

* tests shouldn't use _default_ anymore

* update shingle difference to be 2 not 3 due to unigram usage
  • Loading branch information
Mpdreamz authored Dec 29, 2017
1 parent 9de6fa9 commit c7851d2
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/Nest/Document/Multiple/Bulk/BulkOperation/IBulkOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public interface IBulkOperation
[JsonProperty("_id")]
Id Id { get; set; }

[JsonProperty("_version")]
[JsonProperty("version")]
long? Version { get; set; }

[JsonProperty("_version_type")]
[JsonProperty("version_type")]
[JsonConverter(typeof(StringEnumConverter))]
VersionType? VersionType { get; set; }

[JsonProperty("_routing")]
[JsonProperty("routing")]
string Routing { get; set; }

[JsonProperty("_parent")]
[JsonProperty("parent")]
Id Parent { get; set; }

[JsonProperty("_timestamp")]
Expand All @@ -41,7 +41,7 @@ public interface IBulkOperation
[Obsolete("This feature is no longer supported on indices created in Elasticsearch 5.0.0 and up")]
Time Ttl { get; set; }

[JsonProperty("_retry_on_conflict")]
[JsonProperty("retry_on_conflict")]
int? RetriesOnConflict { get; set; }

object GetBody();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Elasticsearch.Net;
using Newtonsoft.Json;

namespace Nest
Expand All @@ -19,12 +20,18 @@ public interface IMultiGetOperation
[JsonProperty("stored_fields")]
Fields StoredFields { get; set; }

[JsonProperty("_routing")]
[JsonProperty("routing")]
string Routing { get; set; }

[JsonProperty("_source")]
Union<bool, ISourceFilter> Source { get; set; }

[JsonProperty("version")]
long? Version { get; set; }

[JsonProperty("version_type")]
VersionType? VersionType { get; set; }

Type ClrType { get; }

bool CanBeFlattened { get; }
Expand Down
10 changes: 10 additions & 0 deletions src/Nest/Document/Multiple/MultiGet/Request/MultiGetOperation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Elasticsearch.Net;

namespace Nest
{
Expand All @@ -12,6 +13,7 @@ public MultiGetOperation(Id id)
this.Type = typeof(T);
}

public VersionType? VersionType { get; set; }
Type IMultiGetOperation.ClrType => typeof(T);

public IndexName Index { get; set; }
Expand All @@ -24,6 +26,8 @@ public MultiGetOperation(Id id)

public Union<bool, ISourceFilter> Source { get; set; }

public long? Version { get; set; }

public string Routing { get; set; }

bool IMultiGetOperation.CanBeFlattened =>
Expand All @@ -45,6 +49,8 @@ public class MultiGetOperationDescriptor<T> : DescriptorBase<MultiGetOperationDe
Id IMultiGetOperation.Id { get; set; }
string IMultiGetOperation.Routing { get; set; }
Union<bool, ISourceFilter> IMultiGetOperation.Source { get; set; }
long? IMultiGetOperation.Version { get; set; }
VersionType? IMultiGetOperation.VersionType { get; set; }
Fields IMultiGetOperation.StoredFields { get; set; }
Type IMultiGetOperation.ClrType => typeof(T);

Expand Down Expand Up @@ -113,5 +119,9 @@ public MultiGetOperationDescriptor<T> StoredFields(Func<FieldsDescriptor<T>, IPr

public MultiGetOperationDescriptor<T> StoredFields(Fields fields) => Assign(a => a.StoredFields = fields);

public MultiGetOperationDescriptor<T> Version(long? version) => Assign(a => a.Version = version);

public MultiGetOperationDescriptor<T> VersionType(VersionType versionType) => Assign(a => a.VersionType = versionType);

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Elasticsearch.Net;
using Newtonsoft.Json;

namespace Nest
Expand Down Expand Up @@ -28,6 +29,12 @@ public interface IMultiTermVectorOperation
bool? FieldStatistics { get; set; }
[JsonProperty("filter")]
ITermVectorFilter Filter { get; set; }
[JsonProperty("version")]
long? Version { get; set; }
[JsonProperty("version_type")]
VersionType? VersionType { get; set; }
[JsonProperty("routing")]
string Routing { get; set; }
}

public class MultiTermVectorOperation<T> : IMultiTermVectorOperation
Expand All @@ -51,6 +58,9 @@ public MultiTermVectorOperation(Id id)
public bool? TermStatistics { get; set; }
public bool? FieldStatistics { get; set; }
public ITermVectorFilter Filter { get; set; }
public long? Version { get; set; }
public VersionType? VersionType { get; set; }
public string Routing { get; set; }
}

public class MultiTermVectorOperationDescriptor<T> : DescriptorBase<MultiTermVectorOperationDescriptor<T>, IMultiTermVectorOperation>, IMultiTermVectorOperation
Expand All @@ -67,6 +77,9 @@ public class MultiTermVectorOperationDescriptor<T> : DescriptorBase<MultiTermVec
bool? IMultiTermVectorOperation.TermStatistics { get; set; }
bool? IMultiTermVectorOperation.FieldStatistics { get; set; }
ITermVectorFilter IMultiTermVectorOperation.Filter { get; set; }
long? IMultiTermVectorOperation.Version { get; set; }
VersionType? IMultiTermVectorOperation.VersionType { get; set; }
string IMultiTermVectorOperation.Routing { get; set; }

public MultiTermVectorOperationDescriptor<T> StoredFields(Func<FieldsDescriptor<T>, IPromise<Fields>> fields) =>
Assign(a => a.StoredFields = fields?.Invoke(new FieldsDescriptor<T>())?.Value);
Expand All @@ -89,5 +102,11 @@ public MultiTermVectorOperationDescriptor<T> StoredFields(Func<FieldsDescriptor<

public MultiTermVectorOperationDescriptor<T> Filter(Func<TermVectorFilterDescriptor, ITermVectorFilter> filterSelector) =>
Assign(a => a.Filter = filterSelector?.Invoke(new TermVectorFilterDescriptor()));

public MultiTermVectorOperationDescriptor<T> Version(long? version) => Assign(a => a.Version = version);

public MultiTermVectorOperationDescriptor<T> VersionType(VersionType versionType) => Assign(a => a.VersionType = versionType);

public MultiTermVectorOperationDescriptor<T> Routing(string routing) => Assign(a => a.Routing = routing);
}
}
33 changes: 33 additions & 0 deletions src/Nest/QueryDsl/Specialized/MoreLikeThis/MoreLikeThisQuery.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Elasticsearch.Net;
using Newtonsoft.Json;

namespace Nest
Expand Down Expand Up @@ -51,7 +52,21 @@ public interface IMoreLikeThisQuery : IQuery
[JsonProperty("include")]
bool? Include { get; set; }

/// <summary>
/// Provide a different analyzer than the one at the field.
/// This is useful in order to generate term vectors in any fashion, especially when using artificial documents.
/// </summary>
[JsonProperty("per_field_analyzer")]
IPerFieldAnalyzer PerFieldAnalyzer { get; set; }

[JsonProperty("version")]
long? Version { get; set; }

[JsonProperty("version_type")]
VersionType? VersionType { get; set; }

[JsonProperty("routing")]
string Routing { get; set; }
}

public class MoreLikeThisQuery : QueryBase, IMoreLikeThisQuery
Expand All @@ -72,6 +87,12 @@ public class MoreLikeThisQuery : QueryBase, IMoreLikeThisQuery
public bool? Include { get; set; }
public IEnumerable<Like> Like { get; set; }
public IEnumerable<Like> Unlike { get; set; }
/// <inheritdoc/>
public IPerFieldAnalyzer PerFieldAnalyzer { get; set; }

public long? Version { get; set; }
public VersionType? VersionType { get; set; }
public string Routing { get; set; }

internal override void InternalWrapInContainer(IQueryContainer c) => c.MoreLikeThis = this;
internal static bool IsConditionless(IMoreLikeThisQuery q) => q.Fields.IsConditionless() || (!q.Like.HasAny() || q.Like.All(Nest.Like.IsConditionless));
Expand All @@ -94,6 +115,10 @@ public class MoreLikeThisQueryDescriptor<T>
double? IMoreLikeThisQuery.BoostTerms { get; set; }
string IMoreLikeThisQuery.Analyzer { get; set; }
bool? IMoreLikeThisQuery.Include { get; set; }
IPerFieldAnalyzer IMoreLikeThisQuery.PerFieldAnalyzer { get; set; }
long? IMoreLikeThisQuery.Version { get; set; }
VersionType? IMoreLikeThisQuery.VersionType { get; set; }
string IMoreLikeThisQuery.Routing { get; set; }
IEnumerable<Like> IMoreLikeThisQuery.Like { get; set; }
IEnumerable<Like> IMoreLikeThisQuery.Unlike { get; set; }

Expand Down Expand Up @@ -137,5 +162,13 @@ public MoreLikeThisQueryDescriptor<T> Like(Func<LikeDescriptor<T>, IPromise<List
public MoreLikeThisQueryDescriptor<T> Unlike(Func<LikeDescriptor<T>, IPromise<List<Like>>> selector) =>
Assign(a => a.Unlike = selector?.Invoke(new LikeDescriptor<T>())?.Value);

public MoreLikeThisQueryDescriptor<T> PerFieldAnalyzer(Func<PerFieldAnalyzerDescriptor<T>, IPromise<IPerFieldAnalyzer>> analyzerSelector) =>
Assign(a => a.PerFieldAnalyzer = analyzerSelector?.Invoke(new PerFieldAnalyzerDescriptor<T>())?.Value);

public MoreLikeThisQueryDescriptor<T> Version(long? version) => Assign(a => a.Version = version);

public MoreLikeThisQueryDescriptor<T> VersionType(VersionType versionType) => Assign(a => a.VersionType = versionType);

public MoreLikeThisQueryDescriptor<T> Routing(string routing) => Assign(a => a.Routing = routing);
}
}
12 changes: 6 additions & 6 deletions src/Tests/Analysis/TokenFilters/TokenFilterUsageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public class TokenFilterUsageTests : PromiseUsageTestBase<IIndexSettings, IndexS
{
type = "ngram",
min_gram = 3,
max_gram = 30
max_gram = 4
},
pc = new
{
Expand All @@ -183,7 +183,7 @@ public class TokenFilterUsageTests : PromiseUsageTestBase<IIndexSettings, IndexS
{
type = "shingle",
min_shingle_size = 8,
max_shingle_size = 12,
max_shingle_size = 10,
output_unigrams = true,
output_unigrams_if_no_shingles = true,
token_separator = "|",
Expand Down Expand Up @@ -352,7 +352,7 @@ public class TokenFilterUsageTests : PromiseUsageTestBase<IIndexSettings, IndexS
.Lowercase("lc")
.NGram("ngram", t => t
.MinGram(3)
.MaxGram(30)
.MaxGram(4)
)
.PatternCapture("pc", t => t
.Patterns(@"\d", @"\w")
Expand All @@ -366,7 +366,7 @@ public class TokenFilterUsageTests : PromiseUsageTestBase<IIndexSettings, IndexS
.Reverse("rev")
.Shingle("shing", t => t
.FillerToken("x")
.MaxShingleSize(12)
.MaxShingleSize(10)
.MinShingleSize(8)
.OutputUnigrams()
.OutputUnigramsIfNoShingles()
Expand Down Expand Up @@ -506,7 +506,7 @@ public class TokenFilterUsageTests : PromiseUsageTestBase<IIndexSettings, IndexS
{"length", new LengthTokenFilter {Min = 10, Max = 200}},
{"limit", new LimitTokenCountTokenFilter {ConsumeAllTokens = true, MaxTokenCount = 12}},
{"lc", new LowercaseTokenFilter()},
{"ngram", new NGramTokenFilter {MinGram = 3, MaxGram = 30}},
{"ngram", new NGramTokenFilter {MinGram = 3, MaxGram = 4}},
{"pc", new PatternCaptureTokenFilter {Patterns = new[] {@"\d", @"\w"}, PreserveOriginal = true}},
{"pr", new PatternReplaceTokenFilter {Pattern = @"(\d|\w)", Replacement = "replacement"}},
{"porter", new PorterStemTokenFilter()},
Expand All @@ -515,7 +515,7 @@ public class TokenFilterUsageTests : PromiseUsageTestBase<IIndexSettings, IndexS
"shing", new ShingleTokenFilter
{
FillerToken = "x",
MaxShingleSize = 12,
MaxShingleSize = 10,
MinShingleSize = 8,
OutputUnigrams = true,
OutputUnigramsIfNoShingles = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected override LazyResponses ClientUsage() => Calls(
settings = new Dictionary<string, object> { { "index.number_of_shards", 1 } },
mappings = new
{
_default_ = new
doc = new
{
dynamic_templates = new object[]
{
Expand Down Expand Up @@ -67,7 +67,7 @@ protected override LazyResponses ClientUsage() => Calls(
.Create(false)
.Settings(p=>p.NumberOfShards(1))
.Mappings(m => m
.Map("_default_", tm => tm
.Map("doc", tm => tm
.DynamicTemplates(t => t
.DynamicTemplate("base", dt => dt
.Match("*")
Expand Down Expand Up @@ -96,7 +96,7 @@ protected override LazyResponses ClientUsage() => Calls(
},
Mappings = new Mappings
{
{ "_default_", new TypeMapping
{ "doc", new TypeMapping
{
DynamicTemplates = new DynamicTemplateContainer
{
Expand Down
6 changes: 3 additions & 3 deletions src/Tests/Mapping/Types/SingleMappingPropertyTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override LazyResponses ClientUsage() => Calls(
settings = new Dictionary<string, object> { { "index.number_of_shards", 1 } },
mappings = new
{
_default_ = new
doc = new
{
dynamic_templates = new object[]
{
Expand All @@ -61,7 +61,7 @@ protected override LazyResponses ClientUsage() => Calls(
.Create(false)
.Settings(p=>p.NumberOfShards(1))
.Mappings(m => m
.Map("_default_", tm => tm
.Map("doc", tm => tm
.DynamicTemplates(t => t
.DynamicTemplate("base", dt => dt
.Match("*")
Expand All @@ -86,7 +86,7 @@ protected override LazyResponses ClientUsage() => Calls(
},
Mappings = new Mappings
{
{ "_default_", new TypeMapping
{ "doc", new TypeMapping
{
DynamicTemplates = new DynamicTemplateContainer
{
Expand Down

0 comments on commit c7851d2

Please sign in to comment.