Skip to content

Commit 9a2a3b4

Browse files
committed
Align naming for Validate API
Closes #1778
1 parent 8f6bd34 commit 9a2a3b4

File tree

11 files changed

+212
-214
lines changed

11 files changed

+212
-214
lines changed

src/Benchmarking/project.lock.json

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

src/Elasticsearch.Net/project.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@
20252025
"System.Dynamic.Runtime/4.0.11-beta-23516": {
20262026
"type": "package",
20272027
"serviceable": true,
2028-
"sha512": "C2GXB20I5vMcO4wemZr5pEjwwEb6H6zVkwF12JSUhripKBIKgI0YKpfp9glyDSL903cYgIXAztMQDajwCR0PmA==",
2028+
"sha512": "ypkxS0e+yUw7F6JEwuB22u0qqruMeZFOmtcImh2efDHpTAuhF2FOqCDJ7f4qLf9yomVvB4kjkZ6xGunbIQryxQ==",
20292029
"files": [
20302030
"lib/DNXCore50/System.Dynamic.Runtime.dll",
20312031
"lib/MonoAndroid10/_._",

src/Nest/Search/Validate/ElasticClient-Validate.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Elasticsearch.Net;
4+
5+
namespace Nest
6+
{
7+
public partial interface IElasticClient
8+
{
9+
/// <summary>
10+
/// The validate API allows a user to validate a potentially expensive query without executing it.
11+
/// <para> </para>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-validate.html
12+
/// </summary>
13+
/// <typeparam name="T">The type used to describe the query</typeparam>
14+
/// <param name="selector">A descriptor that describes the query operation</param>
15+
IValidateQueryResponse ValidateQuery<T>(Func<ValidateQueryDescriptor<T>, IValidateQueryRequest> selector)
16+
where T : class;
17+
18+
/// <inheritdoc/>
19+
IValidateQueryResponse ValidateQuery(IValidateQueryRequest request);
20+
21+
/// <inheritdoc/>
22+
Task<IValidateQueryResponse> ValidateQueryAsync<T>(Func<ValidateQueryDescriptor<T>, IValidateQueryRequest> selector)
23+
where T : class;
24+
25+
/// <inheritdoc/>
26+
Task<IValidateQueryResponse> ValidateQueryAsync(IValidateQueryRequest request);
27+
28+
}
29+
public partial class ElasticClient
30+
{
31+
/// <inheritdoc/>
32+
public IValidateQueryResponse ValidateQuery<T>(Func<ValidateQueryDescriptor<T>, IValidateQueryRequest> selector)
33+
where T : class =>
34+
this.ValidateQuery(selector?.Invoke(new ValidateQueryDescriptor<T>()));
35+
36+
/// <inheritdoc/>
37+
public IValidateQueryResponse ValidateQuery(IValidateQueryRequest request) =>
38+
this.Dispatcher.Dispatch<IValidateQueryRequest, ValidateQueryRequestParameters, ValidateQueryResponse>(
39+
request,
40+
this.LowLevelDispatch.IndicesValidateQueryDispatch<ValidateQueryResponse>
41+
);
42+
43+
/// <inheritdoc/>
44+
public Task<IValidateQueryResponse> ValidateQueryAsync<T>(Func<ValidateQueryDescriptor<T>, IValidateQueryRequest> selector)
45+
where T : class =>
46+
this.ValidateQueryAsync(selector?.Invoke(new ValidateQueryDescriptor<T>()));
47+
48+
/// <inheritdoc/>
49+
public Task<IValidateQueryResponse> ValidateQueryAsync(IValidateQueryRequest request) =>
50+
this.Dispatcher.DispatchAsync<IValidateQueryRequest, ValidateQueryRequestParameters, ValidateQueryResponse, IValidateQueryResponse>(
51+
request,
52+
this.LowLevelDispatch.IndicesValidateQueryDispatchAsync<ValidateQueryResponse>
53+
);
54+
}
55+
}

src/Nest/Search/Validate/ValidateResponse.cs renamed to src/Nest/Search/Validate/ValidateQueryResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
namespace Nest
55
{
6-
public interface IValidateResponse : IResponse
6+
public interface IValidateQueryResponse : IResponse
77
{
88
bool Valid { get; }
99
ShardsMetaData Shards { get; }
1010
IList<ValidationExplanation> Explanations { get; set; }
1111
}
1212

1313
[JsonObject]
14-
public class ValidateResponse : ResponseBase, IValidateResponse
14+
public class ValidateQueryResponse : ResponseBase, IValidateQueryResponse
1515
{
1616
[JsonProperty(PropertyName = "valid")]
1717
public bool Valid { get; internal set; }

src/Nest/project.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,7 @@
20372037
"runtime.any.System.Linq.Expressions/4.0.11-beta-23516": {
20382038
"type": "package",
20392039
"serviceable": true,
2040-
"sha512": "P5nzo1Ye0GxB4BYdWian6Y427eTrhn1JS3jLWZq5bMWVn8hS/OIfyylASN0A/qqeLn4rGA0fOzmJSYqFSKvxgQ==",
2040+
"sha512": "4sPxQCjllMJ1uZNlwz/EataPyHSH+AqSDlOIPPqcy/88R2B+abfhPPC78rd7gvHp8KmMX4qbJF6lcCeDIQpmVg==",
20412041
"files": [
20422042
"lib/DNXCore50/System.Linq.Expressions.dll",
20432043
"lib/MonoAndroid10/_._",
@@ -2345,7 +2345,7 @@
23452345
"System.Dynamic.Runtime/4.0.11-beta-23516": {
23462346
"type": "package",
23472347
"serviceable": true,
2348-
"sha512": "C2GXB20I5vMcO4wemZr5pEjwwEb6H6zVkwF12JSUhripKBIKgI0YKpfp9glyDSL903cYgIXAztMQDajwCR0PmA==",
2348+
"sha512": "ypkxS0e+yUw7F6JEwuB22u0qqruMeZFOmtcImh2efDHpTAuhF2FOqCDJ7f4qLf9yomVvB4kjkZ6xGunbIQryxQ==",
23492349
"files": [
23502350
"lib/DNXCore50/System.Dynamic.Runtime.dll",
23512351
"lib/MonoAndroid10/_._",
@@ -2599,7 +2599,7 @@
25992599
"System.Linq.Expressions/4.0.11-beta-23516": {
26002600
"type": "package",
26012601
"serviceable": true,
2602-
"sha512": "FtKytB13HabzrSvrAgBgOOnG2uxJO4s7zvP5Sk0NS3bwbJUyb5AP1p4897UWnLiB6C95jI4nIkZps51sa9In8g==",
2602+
"sha512": "YEl5oyF5fifLbHHP099cvb/6f2r2h1QVHzoaoINPHOZtpNec+RfqvzETXcYDIdHT7l+bBAYsBuVUkBgfQEoYfQ==",
26032603
"files": [
26042604
"lib/MonoAndroid10/_._",
26052605
"lib/MonoTouch10/_._",

src/Tests/CodeStandards/NamingConventions.doc.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ public void ParityBetweenRequestsAndResponses()
114114
typeof(SourceRequest),
115115
typeof(SourceRequest<>),
116116

117-
// TODO: Remove when https://github.com/elastic/elasticsearch-net/issues/1778 is resolved
118-
typeof(ValidateQueryRequest),
119117
typeof(ValidateQueryRequest<>),
120118

121119
typeof(GetAliasRequest),

src/Tests/Search/Validate/ValidateApiTests.cs renamed to src/Tests/Search/Validate/ValidateQueryApiTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
using Elasticsearch.Net;
2-
using FluentAssertions;
3-
using Nest;
4-
using Tests.Framework;
1+
using Tests.Framework;
52
using Tests.Framework.Integration;
63
using Tests.Framework.MockData;
74
using Xunit;
5+
using Nest;
6+
using Elasticsearch.Net;
7+
using FluentAssertions;
88

99
namespace Tests.Search.Validate
1010
{
1111
[Collection(IntegrationContext.ReadOnly)]
12-
public class ValidateApiTests
13-
: ApiIntegrationTestBase<IValidateResponse, IValidateQueryRequest, ValidateQueryDescriptor<Project>, ValidateQueryRequest<Project>>
12+
public class ValidateQueryApiTests
13+
: ApiIntegrationTestBase<IValidateQueryResponse, IValidateQueryRequest, ValidateQueryDescriptor<Project>, ValidateQueryRequest<Project>>
1414
{
15-
public ValidateApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
15+
public ValidateQueryApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1616

1717
protected override LazyResponses ClientUsage() => Calls(
18-
fluent: (c, f) => c.Validate<Project>(v => v.Query(q => q.MatchAll())),
19-
fluentAsync: (c, f) => c.ValidateAsync<Project>(v => v.Query(q => q.MatchAll())),
20-
request: (c, r) => c.Validate(new ValidateQueryRequest<Project> { Query = new QueryContainer(new MatchAllQuery()) }),
21-
requestAsync: (c, r) => c.ValidateAsync(new ValidateQueryRequest<Project> { Query = new QueryContainer(new MatchAllQuery()) })
18+
fluent: (c, f) => c.ValidateQuery<Project>(v => v.Query(q => q.MatchAll())),
19+
fluentAsync: (c, f) => c.ValidateQueryAsync<Project>(v => v.Query(q => q.MatchAll())),
20+
request: (c, r) => c.ValidateQuery(new ValidateQueryRequest<Project> { Query = new QueryContainer(new MatchAllQuery()) }),
21+
requestAsync: (c, r) => c.ValidateQueryAsync(new ValidateQueryRequest<Project> { Query = new QueryContainer(new MatchAllQuery()) })
2222
);
2323

2424
protected override bool ExpectIsValid => true;
@@ -29,15 +29,15 @@ protected override LazyResponses ClientUsage() => Calls(
2929

3030
[Collection(IntegrationContext.ReadOnly)]
3131
public class ValidateInvalidQueryApiTests
32-
: ApiIntegrationTestBase<IValidateResponse, IValidateQueryRequest, ValidateQueryDescriptor<Project>, ValidateQueryRequest<Project>>
32+
: ApiIntegrationTestBase<IValidateQueryResponse, IValidateQueryRequest, ValidateQueryDescriptor<Project>, ValidateQueryRequest<Project>>
3333
{
3434
public ValidateInvalidQueryApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
3535

3636
protected override LazyResponses ClientUsage() => Calls(
37-
fluent: (c, f) => c.Validate<Project>(v => _descriptor),
38-
fluentAsync: (c, f) => c.ValidateAsync<Project>(v => _descriptor),
39-
request: (c, r) => c.Validate(_request),
40-
requestAsync: (c, r) => c.ValidateAsync(_request)
37+
fluent: (c, f) => c.ValidateQuery<Project>(v => _descriptor),
38+
fluentAsync: (c, f) => c.ValidateQueryAsync<Project>(v => _descriptor),
39+
request: (c, r) => c.ValidateQuery(_request),
40+
requestAsync: (c, r) => c.ValidateQueryAsync(_request)
4141
);
4242

4343
private ValidateQueryDescriptor<Project> _descriptor = new ValidateQueryDescriptor<Project>()
@@ -64,7 +64,7 @@ protected override LazyResponses ClientUsage() => Calls(
6464
protected override HttpMethod HttpMethod => HttpMethod.POST;
6565
protected override string UrlPath => "/project/project/_validate/query";
6666

67-
protected override void ExpectResponse(IValidateResponse response)
67+
protected override void ExpectResponse(IValidateQueryResponse response)
6868
{
6969
response.Valid.Should().BeFalse();
7070
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Threading.Tasks;
2+
using Nest;
3+
using Tests.Framework;
4+
using Tests.Framework.MockData;
5+
using static Tests.Framework.UrlTester;
6+
7+
namespace Tests.Search.Validate
8+
{
9+
public class ValidateQueryUrlTests
10+
{
11+
[U] public async Task Urls()
12+
{
13+
var hardcoded = "hardcoded";
14+
await POST("/project/commits/_validate/query")
15+
.Fluent(c=>c.ValidateQuery<CommitActivity>(s=>s))
16+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest<CommitActivity>()))
17+
.FluentAsync(c=>c.ValidateQueryAsync<CommitActivity>(s=>s))
18+
.RequestAsync(c=>c.ValidateQueryAsync(new ValidateQueryRequest<CommitActivity>()))
19+
;
20+
21+
await POST("/project/hardcoded/_validate/query")
22+
.Fluent(c=>c.ValidateQuery<CommitActivity>(s=>s.Type(hardcoded)))
23+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest<CommitActivity>(typeof(Project), hardcoded)))
24+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest(typeof(Project), hardcoded)))
25+
.FluentAsync(c=>c.ValidateQueryAsync<CommitActivity>(s=>s.Type(hardcoded)))
26+
.RequestAsync(c=>c.ValidateQueryAsync(new ValidateQueryRequest<CommitActivity>(typeof(Project), hardcoded)))
27+
.RequestAsync(c=>c.ValidateQueryAsync(new ValidateQueryRequest(typeof(Project), hardcoded)))
28+
;
29+
30+
await POST("/project/_validate/query")
31+
.Fluent(c=>c.ValidateQuery<Project>(s=>s.Type(Types.All)))
32+
.Fluent(c=>c.ValidateQuery<Project>(s=>s.AllTypes()))
33+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest("project")))
34+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest<Project>("project", Types.All)))
35+
.FluentAsync(c=>c.ValidateQueryAsync<Project>(s=>s.Type(Types.All)))
36+
.RequestAsync(c=>c.ValidateQueryAsync(new ValidateQueryRequest<Project>(typeof(Project), Types.All)))
37+
.FluentAsync(c=>c.ValidateQueryAsync<Project>(s=>s.AllTypes()))
38+
;
39+
40+
await POST("/hardcoded/_validate/query")
41+
.Fluent(c=>c.ValidateQuery<Project>(s=>s.Index(hardcoded).Type(Types.All)))
42+
.Fluent(c=>c.ValidateQuery<Project>(s=>s.Index(hardcoded).AllTypes()))
43+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest(hardcoded)))
44+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest<Project>(hardcoded, Types.All)))
45+
.FluentAsync(c=>c.ValidateQueryAsync<Project>(s=>s.Index(hardcoded).Type(Types.All)))
46+
.RequestAsync(c=>c.ValidateQueryAsync(new ValidateQueryRequest<Project>(hardcoded, Types.All)))
47+
.FluentAsync(c=>c.ValidateQueryAsync<Project>(s=>s.Index(hardcoded).AllTypes()))
48+
;
49+
50+
await POST("/_validate/query")
51+
.Fluent(c=>c.ValidateQuery<Project>(s=>s.AllTypes().AllIndices()))
52+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest()))
53+
.Request(c=>c.ValidateQuery(new ValidateQueryRequest<Project>(Nest.Indices.All, Types.All)))
54+
.FluentAsync(c=>c.ValidateQueryAsync<Project>(s=>s.AllIndices().Type(Types.All)))
55+
.RequestAsync(c=>c.ValidateQueryAsync(new ValidateQueryRequest<Project>(Nest.Indices.All, Types.All)))
56+
.RequestAsync(c=>c.ValidateQueryAsync(new ValidateQueryRequest()))
57+
;
58+
}
59+
}
60+
}

src/Tests/Search/Validate/ValidateUrlTests.cs

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)