Skip to content

Add version to PutTemplateRequest #2971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public interface ITemplateMapping

[JsonProperty("aliases")]
IAliases Aliases { get; set; }

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

public class TemplateMapping : ITemplateMapping
Expand All @@ -32,5 +35,7 @@ public class TemplateMapping : ITemplateMapping
public IMappings Mappings { get; set; }

public IAliases Aliases { get; set; }

public int? Version { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

namespace Nest
{
Expand All @@ -14,6 +15,8 @@ public partial class PutIndexTemplateRequest

public int? Order { get; set; }

public int? Version { get; set; }

public IIndexSettings Settings { get; set; }

public IMappings Mappings { get; set; }
Expand All @@ -26,17 +29,22 @@ public partial class PutIndexTemplateDescriptor
{
int? ITemplateMapping.Order { get; set; }

int? ITemplateMapping.Version { get; set; }

IIndexSettings ITemplateMapping.Settings { get; set; }

IMappings ITemplateMapping.Mappings { get; set; }

IAliases ITemplateMapping.Aliases { get; set; }

IReadOnlyCollection<string> ITemplateMapping.IndexPatterns {get;set;}
IReadOnlyCollection<string> ITemplateMapping.IndexPatterns { get; set; }

public PutIndexTemplateDescriptor Order(int order) => Assign(a => a.Order = order);

public PutIndexTemplateDescriptor Version(int version) => Assign(a => a.Version = version);

public PutIndexTemplateDescriptor IndexPatterns(params string[] patterns)=> Assign(a => a.IndexPatterns = patterns);

public PutIndexTemplateDescriptor IndexPatterns(IEnumerable<string> patterns)=> Assign(a => a.IndexPatterns = patterns?.ToArray());

public PutIndexTemplateDescriptor Settings(Func<IndexSettingsDescriptor, IPromise<IIndexSettings>> settingsSelector) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Linq;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Framework;
using Tests.Framework.Integration;
Expand All @@ -9,7 +11,7 @@
namespace Tests.Indices.IndexSettings.IndexTemplates.GetIndexTemplate
{
public class GetIndexTemplateApiTests
: ApiTestBase<WritableCluster, IGetIndexTemplateResponse, IGetIndexTemplateRequest, GetIndexTemplateDescriptor, GetIndexTemplateRequest>
: ApiIntegrationTestBase<WritableCluster, IGetIndexTemplateResponse, IGetIndexTemplateRequest, GetIndexTemplateDescriptor, GetIndexTemplateRequest>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

{
public GetIndexTemplateApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
protected override LazyResponses ClientUsage() => Calls(
Expand All @@ -25,6 +27,46 @@ protected override LazyResponses ClientUsage() => Calls(
protected override Func<GetIndexTemplateDescriptor, IGetIndexTemplateRequest> Fluent => d => d
.Name(CallIsolatedValue);

protected override int ExpectStatusCode => 200;

protected override bool ExpectIsValid => true;

protected override GetIndexTemplateRequest Initializer => new GetIndexTemplateRequest(CallIsolatedValue);

protected override object ExpectJson => null;

protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
{
foreach (var callUniqueValue in values)
{
var putTemplateResponse = client.PutIndexTemplate(callUniqueValue.Value, d =>
d.IndexPatterns("startingwiththis-*")
.Settings(s => s.NumberOfShards(2))
.Version(1)
);

if (!putTemplateResponse.IsValid)
throw new Exception($"Problem putting index template for integration test: {putTemplateResponse.DebugInformation}");
}
}

protected override void ExpectResponse(IGetIndexTemplateResponse response)
{
response.ShouldBeValid();

response.TemplateMappings.Should().NotBeNull();
response.TemplateMappings.Should().HaveCount(1);

var responseTemplateMapping = response.TemplateMappings[CallIsolatedValue];

responseTemplateMapping.IndexPatterns.Should().NotBeNull();
responseTemplateMapping.IndexPatterns.Should().HaveCount(1);
responseTemplateMapping.IndexPatterns.First().Should().Be("startingwiththis-*");

responseTemplateMapping.Version.Should().Be(1);

responseTemplateMapping.Settings.Should().NotBeNull();
responseTemplateMapping.Settings.NumberOfShards.Should().Be(2);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Tests.Framework;
using Tests.Framework.Integration;
Expand All @@ -10,7 +11,7 @@
namespace Tests.Indices.IndexSettings.IndexTemplates.PutIndexTemplate
{
public class PutIndexTemplateApiTests
: ApiTestBase<WritableCluster, IPutIndexTemplateResponse, IPutIndexTemplateRequest, PutIndexTemplateDescriptor, PutIndexTemplateRequest>
: ApiIntegrationTestBase<WritableCluster, IPutIndexTemplateResponse, IPutIndexTemplateRequest, PutIndexTemplateDescriptor, PutIndexTemplateRequest>
{
public PutIndexTemplateApiTests(WritableCluster cluster, EndpointUsage usage) : base(cluster, usage)
{
Expand All @@ -24,14 +25,15 @@ protected override LazyResponses ClientUsage() => Calls(
);

protected override HttpMethod HttpMethod => HttpMethod.PUT;

protected override string UrlPath => $"/_template/{CallIsolatedValue}?create=false";

protected override bool SupportsDeserialization => false;
protected override int ExpectStatusCode => 200;
protected override bool ExpectIsValid => true;

protected override object ExpectJson { get; } = new
{
order = 1,
version = 2,
index_patterns = new [] {"nestx-*" },
settings = new Dictionary<string, object> { { "index.number_of_shards", 1 } },
mappings = new
Expand Down Expand Up @@ -61,6 +63,7 @@ protected override LazyResponses ClientUsage() => Calls(

protected override Func<PutIndexTemplateDescriptor, IPutIndexTemplateRequest> Fluent => d => d
.Order(1)
.Version(2)
.IndexPatterns("nestx-*")
.Create(false)
.Settings(p=>p.NumberOfShards(1))
Expand All @@ -80,9 +83,12 @@ protected override LazyResponses ClientUsage() => Calls(
)
);



protected override PutIndexTemplateRequest Initializer => new PutIndexTemplateRequest(CallIsolatedValue)
{
Order = 1,
Version = 2,
IndexPatterns = new[] { "nestx-*" },
Create = false,
Settings = new Nest.IndexSettings
Expand Down Expand Up @@ -110,5 +116,11 @@ protected override LazyResponses ClientUsage() => Calls(
}
}
};

protected override void ExpectResponse(IPutIndexTemplateResponse response)
{
response.ShouldBeValid();
response.Acknowledged.Should().BeTrue();
}
}
}