Skip to content

Commit

Permalink
Add index filter to field_caps API (#4888) (#4898)
Browse files Browse the repository at this point in the history
Relates: elastic/elasticsearch#57276

Co-authored-by: Russ Cam <russ.cam@elastic.co>
  • Loading branch information
github-actions[bot] and russcam authored Jul 31, 2020
1 parent 48ed33e commit 7c11fa5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/Nest/Search/FieldCapabilities/FieldCapabilitiesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elasticsearch.Net;
using System;
using System.Runtime.Serialization;
using Elasticsearch.Net;

namespace Nest
{
[MapsApi("field_caps.json")]
public partial interface IFieldCapabilitiesRequest { }
public partial interface IFieldCapabilitiesRequest
{
[DataMember(Name = "index_filter")]
QueryContainer IndexFilter { get; set; }
}

public partial class FieldCapabilitiesRequest
{
protected override HttpMethod HttpMethod => HttpMethod.GET;
protected override HttpMethod HttpMethod => IndexFilter != null? HttpMethod.POST : HttpMethod.GET;

public QueryContainer IndexFilter { get; set; }
}

public partial class FieldCapabilitiesDescriptor
{
protected override HttpMethod HttpMethod => HttpMethod.GET;
QueryContainer IFieldCapabilitiesRequest.IndexFilter { get; set; }

protected override HttpMethod HttpMethod => Self.IndexFilter != null? HttpMethod.POST : HttpMethod.GET;

public FieldCapabilitiesDescriptor IndexFilter<T>(Func<QueryContainerDescriptor<T>, QueryContainer> query) where T : class =>
Assign(query, (a, v) => a.IndexFilter = v?.Invoke(new QueryContainerDescriptor<T>()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System;
using System.Linq;
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
Expand Down Expand Up @@ -69,4 +70,64 @@ protected override void ExpectResponse(FieldCapabilitiesResponse response)
jobTitleCapabilities.Searchable.Should().BeTrue();
}
}

[SkipVersion("<7.9.0", "index filter introduced in 7.9.0")]
public class FieldCapabilitiesIndexFilterApiTests
: ApiIntegrationTestBase<ReadOnlyCluster, FieldCapabilitiesResponse, IFieldCapabilitiesRequest, FieldCapabilitiesDescriptor,
FieldCapabilitiesRequest>
{
public FieldCapabilitiesIndexFilterApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }

protected override object ExpectJson => new
{
index_filter = new
{
term = new
{
versionControl = new
{
value = "git"
}
}
}
};

protected override bool SupportsDeserialization { get; } = false;

protected override bool ExpectIsValid => true;

protected override int ExpectStatusCode => 200;

protected override Func<FieldCapabilitiesDescriptor, IFieldCapabilitiesRequest> Fluent => d => d
.Fields("*")
.IndexFilter<Project>(q => q
.Term(t => t
.Field(f => f.VersionControl)
.Value(Project.VersionControlConstant)
)
);

protected override HttpMethod HttpMethod => HttpMethod.POST;

protected override FieldCapabilitiesRequest Initializer => new FieldCapabilitiesRequest(Index<Project>().And<Developer>())
{
Fields = "*",
IndexFilter = new TermQuery
{
Field = Field<Project>(f => f.VersionControl),
Value = Project.VersionControlConstant
}
};

protected override string UrlPath => "/project%2Cdevs/_field_caps?fields=%2A";

protected override LazyResponses ClientUsage() => Calls(
(c, f) => c.FieldCapabilities(Index<Project>().And<Developer>(), f),
(c, f) => c.FieldCapabilitiesAsync(Index<Project>().And<Developer>(), f),
(c, r) => c.FieldCapabilities(r),
(c, r) => c.FieldCapabilitiesAsync(r)
);

protected override void ExpectResponse(FieldCapabilitiesResponse response) => response.ShouldBeValid();
}
}

0 comments on commit 7c11fa5

Please sign in to comment.