Skip to content
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

Point In Time - does not support having a body #8396

Closed
HaggeMan opened this issue Oct 29, 2024 · 3 comments
Closed

Point In Time - does not support having a body #8396

HaggeMan opened this issue Oct 29, 2024 · 3 comments
Labels
8.x Relates to 8.x client version Category: Bug

Comments

@HaggeMan
Copy link

HaggeMan commented Oct 29, 2024

Elastic.Clients.Elasticsearch version: 8.13.2

Elasticsearch version: 8.13.2

.NET runtime version: 8.15.10

Operating system version: Windows 11

Description of the problem including expected versus actual behavior:

public async Task<string> CreatePitAsync(TimeSpan keepAlive, CancellationToken ct = default)
      {
          var keepAliveString = $"{(int)keepAlive.TotalMinutes}m";

          var pitResponse = await _client.OpenPointInTimeAsync(new OpenPointInTimeRequest(_indexName)
          {
              KeepAlive = keepAliveString,
          } 
          ).ConfigureAwait(false);

          if (!pitResponse.IsValidResponse)
              throw new Exception($"Failed to create PIT: {pitResponse.DebugInformation}");

          return pitResponse.Id;
      }

Steps to reproduce:

  1. Create a client in the constructor
  2. Call the method
  3. You will get IsValidResponse = false with the DebufInformation: "does not support having a body", when analyzing the query in Fiddler it looks like {} is sent in the body but nothing should be sent.

Expected behavior
The client should not send {} in the body

Provide DebugInformation (if relevant):
This is how it looks like when sending the body like the client...
Image

When sending an empty body...
Image

@HaggeMan HaggeMan added 8.x Relates to 8.x client version Category: Bug labels Oct 29, 2024
@HaggeMan
Copy link
Author

If someone else do have the issue you can replace the code with the following request using the Transport instead. Until a working solution is in place.

private class PitRequestParameters : RequestParameters {}

public async Task<string> CreatePitAsync(TimeSpan keepAlive, CancellationToken ct = default)
        {
            var keepAliveString = $"{(int)keepAlive.TotalMinutes}m";

            var requestParameters = new PitRequestParameters();
            requestParameters.SetQueryString("keep_alive", keepAliveString);

            var response = await _client.Transport.RequestAsync<StringResponse>(
                method: HttpMethod.POST,
                path: Uri.EscapeDataString(_indexName) + "/_pit",
                postData: PostData.Empty,
                requestParameters,
                ct);

            // Using low-level client for PIT creation
           
            // Parse the response to get PIT ID
            var jsonResponse = JsonNode.Parse(response.Body);
            return jsonResponse["id"].GetValue<string>();
        }

@flobernd
Copy link
Member

Hi @HaggeMan,

thanks for providing a workaround.

Recent versions of Elasticsearch (I tested with 8.15.2) do accept a body with an index_filter property for PIT requests. This capability was recently added to the client as well.

There is no way for the client to tell, if you used that property in the body or not. This causes a body to be sent in all cases. ES 8.15.2 accepts an empty body without returning that validation error, but previous versions (at least the 8.13.2 you are currently using) does not allow a body.

I'm not sure why the Elasticsearch server introduced such a breaking change in a minor version, but I sadly can't do anything to fix this on client side. The client is stateless and does not know to which version of the server it speaks.

@HaggeMan
Copy link
Author

@flobernd thanks for the update. We'll update to latest elastic version shortly and can then start using the method. I'll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Category: Bug
Projects
None yet
Development

No branches or pull requests

2 participants