Skip to content

Update index settings with PutSettingsAsync fails with error status code 400: "request body is required" #8204

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

Closed
apr-un opened this issue May 28, 2024 · 1 comment · Fixed by #8201
Labels
8.x Relates to a 8.x client version Category: Bug

Comments

@apr-un
Copy link

apr-un commented May 28, 2024

Elastic.Clients.Elasticsearch version:
8.13.12

Elasticsearch version:
8.9

.NET runtime version:
net 8

Operating system version:
docker with linux container

Description of the problem including expected versus actual behavior:
I had this error in two cases:

  • when I try to change analyzer ( exactly update synonyms and stopwords ) (static setting on closed index)
  • when I try to block/unblock write on index (dynamic setting on open index)

In both cases I use similar code like for index creation (its working there, index is created with given settings).
But when I use PutSettingsAsync I get error "request body is required". From debugging I know that my settings are correctly serializable (using JsonSerializer), but they're lost somewhere inside Elastic.Transport.PostData.WriteAsync function. Stream which should contain my settings was empty, which lead to serialization into empty json {} and in result give error "request body is required" )

Steps to reproduce:
Please use code like this (simplified version, _elasticClient initialized by dependency injection):

var sourceIndexName ="testindex"; // it exists and is open
IndexSettings sourceIndexSettings = new IndexSettings();
sourceIndexSettings.Blocks = new IndexSettingBlocks() { Write = true };
try
{
    var x = JsonSerializer.Serialize<IndexSettings>(sourceIndexSettings); // test => x contain correct json
}
catch (Exception ex)
{
}
var updateStatusSrc = await _elasticClient.Indices.PutSettingsAsync(sourceIndexSettings, Indices.Index(sourceIndexName));

or this code

var indexName ="testindex"; // it exists and is open
await _elasticClient.Indices.CloseAsync(indexName);
                    
IndexSettings settings = new IndexSettings();
settings.MaxNgramDiff = 20;
IndexSettingsAnalysis analysis = new IndexSettingsAnalysis();
TokenFilters tokenFilters = new TokenFilters();
tokenFilters.Add("custom_asciifolding", new AsciiFoldingTokenFilter() { PreserveOriginal = true });
tokenFilters.Add("custom_polish_stop", new StopTokenFilter() { Stopwords = ["a","i","z"], RemoveTrailing = true });
tokenFilters.Add("substrings", new EdgeNGramTokenFilter() { MinGram = 2, MaxGram = 20 });
tokenFilters.Add("custom_synonym", new SynonymGraphTokenFilter() { Synonyms = 
    [
        "dom, chata, budynek",
        "zwierzę, pies, kot"
    ] 
});
analysis.TokenFilters = tokenFilters;
Analyzers analyzers = new Analyzers();
analyzers.Add("custom_analyzer", new CustomAnalyzer() { 
    Tokenizer = "standard", 
    CharFilter = ["html_strip"],
    Filter = [
        "lowercase",
        "custom_polish_stop",
        "substrings",
        "custom_asciifolding"
    ]
});
analysis.Analyzers = analyzers;
settings.Analysis = analysis;
try
{ 
    var x = JsonSerializer.Serialize<IndexSettings>(settings); // test , x contains correct json with settings
}
catch (Exception ex) 
{ 
}

var updateStatus = await _elasticClient.Indices.PutSettingsAsync(settings, Indices.Index(indexName));

Expected behavior
Index settings should be updated according to new settings, other settings should not be changed (preserve existing was not required in 7.x version)

Provide ConnectionSettings (if relevant):
Most notable:
EnableHttpCompression = true // also tried with false, error stays the same
DisableDirectStreaming = false // also tried with true, error stays the same

Provide DebugInformation (if relevant):
stacktrace:

Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: PUT /testindex/_settings?pretty=true. ServerError: Type: parse_exception Reason: "request body is required"
   at Elastic.Transport.DistributedTransport`1.HandleTransportException(RequestData data, Exception clientException, TransportResponse response)
   at Elastic.Transport.DistributedTransport`1.FinalizeResponse[TResponse](RequestData requestData, RequestPipeline pipeline, List`1 seenExceptions, TResponse response)
   at Elastic.Transport.DistributedTransport`1.RequestCoreAsync[TResponse](Boolean isAsync, HttpMethod method, String path, PostData data, RequestParameters requestParameters, OpenTelemetryData openTelemetryData, CancellationToken cancellationToken)

Regards,
Arnold

@apr-un apr-un added 8.x Relates to a 8.x client version Category: Bug labels May 28, 2024
@flobernd
Copy link
Member

Hi @apr-un,

thanks for the detailed bug report. I just fixed this problem 🙂 A patch will be released in a few minutes.

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

Successfully merging a pull request may close this issue.

2 participants