Skip to content

[Backport 8.3] Add shortcut client methods for indices refresh #6913

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 1 commit into from
Nov 4, 2022
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
38 changes: 38 additions & 0 deletions src/Elastic.Clients.Elasticsearch/Client/IndicesNamespace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// 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.Threading.Tasks;
using System.Threading;

namespace Elastic.Clients.Elasticsearch.IndexManagement;

public partial class IndicesNamespace
{
/// <summary>
/// Refresh one or more indices. A refresh makes recent operations performed on one or more indices available for search. For data streams,
/// the API runs the refresh operation on the stream’s backing indices.
/// </summary>
/// <param name="indices">The index and/or data streams to refresh.</param>
/// <returns>A <see cref="RefreshResponse"/> from the server.</returns>
public RefreshResponse Refresh(Indices indices)
{
var request = new RefreshRequest(indices);
request.BeforeRequest();
return DoRequest<RefreshRequest, RefreshResponse>(request);
}

/// <summary>
/// Refresh one or more indices. A refresh makes recent operations performed on one or more indices available for search. For data streams,
/// the API runs the refresh operation on the stream’s backing indices.
/// </summary>
/// <param name="indices">The index and/or data streams to refresh.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="RefreshResponse"/> from the server.</returns>
public Task<RefreshResponse> RefreshAsync(Indices indices, CancellationToken cancellationToken = default)
{
var request = new RefreshRequest(indices);
request.BeforeRequest();
return DoRequestAsync<RefreshRequest, RefreshResponse>(request, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#nullable restore
namespace Elastic.Clients.Elasticsearch.AsyncSearch;
public class AsyncSearchNamespace : NamespacedClientProxy
public sealed partial class AsyncSearchNamespace : NamespacedClientProxy
{
internal AsyncSearchNamespace(ElasticsearchClient client) : base(client)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#nullable restore
namespace Elastic.Clients.Elasticsearch.Cluster;
public class ClusterNamespace : NamespacedClientProxy
public sealed partial class ClusterNamespace : NamespacedClientProxy
{
internal ClusterNamespace(ElasticsearchClient client) : base(client)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#nullable restore
namespace Elastic.Clients.Elasticsearch.Eql;
public class EqlNamespace : NamespacedClientProxy
public sealed partial class EqlNamespace : NamespacedClientProxy
{
internal EqlNamespace(ElasticsearchClient client) : base(client)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#nullable restore
namespace Elastic.Clients.Elasticsearch.IndexManagement;
public class IndicesNamespace : NamespacedClientProxy
public sealed partial class IndicesNamespace : NamespacedClientProxy
{
internal IndicesNamespace(ElasticsearchClient client) : base(client)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#nullable restore
namespace Elastic.Clients.Elasticsearch.Sql;
public class SqlNamespace : NamespacedClientProxy
public sealed partial class SqlNamespace : NamespacedClientProxy
{
internal SqlNamespace(ElasticsearchClient client) : base(client)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Elastic.Clients.Elasticsearch.IndexManagement;
using Elastic.Clients.Elasticsearch.Mapping;
using Elastic.Clients.Elasticsearch.QueryDsl;
using Tests.Core.Extensions;
Expand Down Expand Up @@ -91,7 +90,7 @@ protected override void IntegrationSetup(ElasticsearchClient client, CallUniqueV
Client.IndexMany(Project.Projects, index);
var cloneIndex = index + "-clone";
Client.Indices.Create(cloneIndex);
Client.Indices.Refresh(new RefreshRequest(Infer.Index(index).And(cloneIndex)));
Client.Indices.Refresh(Infer.Index(index).And(cloneIndex));
}
}

Expand All @@ -102,7 +101,7 @@ protected override LazyResponses ClientUsage() => Calls(
(client, r) => client.DeleteByQueryAsync(r)
);

protected override void OnAfterCall(ElasticsearchClient client) => client.Indices.Refresh(new RefreshRequest(CallIsolatedValue));
protected override void OnAfterCall(ElasticsearchClient client) => client.Indices.Refresh(CallIsolatedValue);

protected override DeleteByQueryRequestDescriptor<Project> NewDescriptor() => new(Indices);

Expand Down Expand Up @@ -276,7 +275,7 @@ protected override void ExpectResponse(DeleteByQueryResponse response)

// Since we only executed one slice of the two, some of the documents that
// match the query will still exist.
Client.Indices.Refresh(new RefreshRequest(CallIsolatedValue));
Client.Indices.Refresh(CallIsolatedValue);

var countResponse = Client.Count<Project>(c => c
.Indices(CallIsolatedValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected override void IntegrationSetup(ElasticsearchClient client, CallUniqueV
foreach (var callUniqueValue in values)
{
client.IndexMany(Project.Projects, callUniqueValue.Value);
client.Indices.Refresh(new RefreshRequest(callUniqueValue.Value));
client.Indices.Refresh(CallIsolatedValue);
}
}

Expand All @@ -62,7 +62,7 @@ protected override LazyResponses ClientUsage() => Calls(
protected override void OnBeforeCall(ElasticsearchClient client)
{
client.IndexMany(Project.Projects, CallIsolatedValue);
client.Indices.Refresh(new RefreshRequest(CallIsolatedValue));
client.Indices.Refresh(CallIsolatedValue);

var deleteByQuery = client.DeleteByQuery<Project>(CallIsolatedValue, u => u
.Conflicts(Conflicts.Proceed)
Expand Down