Skip to content

EnableApiVersioningHeader breaks further API calls on .NET Framework #6260

@SzymonKatra

Description

@SzymonKatra

NEST version: 7.17.0

Elasticsearch version: 8.1.2

.NET runtime version: .NET Framework 4.8

Operating system version: Windows 10 Enterprise, Version 1909, OS build 18363.2037

Description of the problem including expected versus actual behavior:
When EnableApiVersioningHeader() is called on the ConnectionSettings, further requests begin to fail (in this example - ElasticClient.Indices.PutTemplateAsync).

This problem happens only when using .NET Framework (tried with TargetFramework == net471 and net48)
On .NET Core it does not happen. (tried with TargetFramework == netcoreapp3.1 and net6.0)

Without calling EnableApiVersioningHeader the following code works as expected, but I wanted to use EnableApiVersioningHeader to mitigate #6154 issue (missing _type property in Elastic v8).

Steps to reproduce:
Use code below. Provide valid elastic 8.1.2 instance and credentials.
Program.cs

using System;
using Nest;

var settings = new ConnectionSettings(new Uri("https://some-elastic-instance.aws.cloud.es.io:9243"));
settings.BasicAuthentication("username", "password");
settings.EnableDebugMode();
settings.EnableApiVersioningHeader();

var client = new ElasticClient(settings);
var response = await client.Indices.PutTemplateAsync("some-index-template", x => x
    .IndexPatterns(new string[] { "pattern*" })
    .Version(1)
    .Map<IndexType>(m => m.Properties(a => a
        .Keyword(s => s.Name(i => i.FieldA))
        .Keyword(s => s.Name(i => i.FieldB))
)));

Console.WriteLine(response.DebugInformation);

public class IndexType
{
    public string FieldA { get; set; }
    public string FieldB { get; set; }
}

elastictest.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net48</TargetFramework>
    <LangVersion>10.0</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="NEST" Version="7.17.0" />
  </ItemGroup>

</Project>

Code: elastictest.zip

Expected behavior
Using EnableApiVersioningHeader() should not break existing code.

Provide DebugInformation (if relevant):

Without EnableVersioningApiHeader

Valid NEST response built from a successful (200) low level call on PUT: /_template/some-index-template?pretty=true&error_trace=true
# Warnings:
- The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.
# Server indicated deprecations:
- 299 Elasticsearch-8.1.2-31df9689e80bad366ac20176aa7f2371ea5eb4c1 "Legacy index templates are deprecated in favor of composable templates."
# Audit trail of this API call:
 - [1] ProductCheckOnStartup: Took: 00:00:00.5295261
 - [2] ProductCheckSuccess: Node: https://test-elastik.es.eu-central-1.aws.cloud.es.io:9243/ Took: 00:00:00.4956215
 - [3] HealthyResponse: Node: https://test-elastik.es.eu-central-1.aws.cloud.es.io:9243/ Took: 00:00:00.2964671
# Request:
{"index_patterns":["pattern*"],"mappings":{"properties":{"fieldA":{"type":"keyword"},"fieldB":{"type":"keyword"}}},"version":1}
# Response:
{
  "acknowledged" : true
}

# TCP states:
  Established: 77
  TimeWait: 22
  SynSent: 1

# ThreadPool statistics:
  Worker:
    Busy: 0
    Free: 32767
    Min: 8
    Max: 32767
  IOCP:
    Busy: 1
    Free: 999
    Min: 8
    Max: 1000

With EnableVersioningApiHeader
Response contains OriginalException, following DebugInformation is present:

Invalid NEST response built from a unsuccessful (200) low level call on PUT: /_template/some-index-template?pretty=true&error_trace=true
# Warnings:
- The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.
# Server indicated deprecations:
- 299 Elasticsearch-8.1.2-31df9689e80bad366ac20176aa7f2371ea5eb4c1 "Legacy index templates are deprecated in favor of composable templates."
# Audit trail of this API call:
 - [1] ProductCheckOnStartup: Took: 00:00:00.5400530
 - [2] ProductCheckSuccess: Node: https://test-elastik.es.eu-central-1.aws.cloud.es.io:9243/ Took: 00:00:00.4941808
 - [3] BadResponse: Node: https://test-elastik.es.eu-central-1.aws.cloud.es.io:9243/ Took: 00:00:00.2766236
# OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 200 from: PUT /_template/some-index-template?pretty=true&error_trace=true
# Request:
{"index_patterns":["pattern*"],"mappings":{"properties":{"fieldA":{"type":"keyword"},"fieldB":{"type":"keyword"}}},"version":1}
# Response:
{
  "acknowledged" : true
}

# TCP states:
  Established: 77
  TimeWait: 19

# ThreadPool statistics:
  Worker:
    Busy: 0
    Free: 32767
    Min: 8
    Max: 32767
  IOCP:
    Busy: 1
    Free: 999
    Min: 8
    Max: 1000

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.xRelates to a 7.x client version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions