Skip to content

can't created repository,response request body missing #8187

Closed
@firstsaofan

Description

@firstsaofan

Elastic.Clients.Elasticsearch version:

    <PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.13.12" />

Elasticsearch version:8.13.4

docker compose.yml

version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
    ports:
      - "9200:9200"
    volumes:
      - ./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml

.NET runtime version:

.Net8

Operating system version:

Ubuntu 20 and Windows10

Description of the problem including expected versus actual behavior:

can’t create repository by code call ES,

I have modified the config.yml file of ES and added path.repo. I can use Postman to test the request for create repository, and everything is normal.

image-20240515003957186

But I use Elastic Clients Elasticsearch method to create RepositoryAsync, but encountered an error message stating that the request body is missing. However, in the SharedFileSystemRepository class, type is set by default. In fact, I only need to pass location, and I am not sure what I am missing.

error info:
Invalid Elasticsearch response built from a unsuccessful (400) low level call on PUT: /_snapshot/my-fs-epository
 Exception: Request failed to execute. Call: Status code 400 from: PUT /_snapshot/my-fs-epository. ServerError: Type: parse_exception Reason: "request body is required"

# Audit trail of this API call:
 - [1] BadResponse: Node: http://localhost:9200/ Took: 00:00:00.8736147
# OriginalException: Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: PUT /_snapshot/my-fs-epository. ServerError: Type: parse_exception Reason: "request body is required"
# Request:

# Response:
{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}

Steps to reproduce:

  1. Based on the simple Docker Compose file mentioned above, start the ES example and configure the value of path.repo. (On Windows systems, when mounting, the yml file will be treated as a folder and will prompt you to map the folder to the file. You can use Docker cp to copy the configuration file and then map it. At the same time, you need to keep the jvm.options file. Only mounting the config.yml configuration file will cause errors.)
path:
  repo:
    - /usr/share/elasticsearch/data/backups
    - /usr/share/elasticsearch/data/long_term_backups
docker cp elasticsearch:/usr/share/elasticsearch/config ./config/es/

2.Simple example unit test code:

Debugging, break the breakpoint to line 22, and check the value of res to see the error message

        [Fact]
        public async Task CreateFsRepository_Success33()
        {
            //Provide necessary parameters
            string repoName = "my-fs-epository";
            //fs
            string path = "unitTestLocation";
            //var result = await _esBackupRestore.CreateLocalRepository(repoName, path);
            var fsSettings = new SharedFileSystemRepository()
            {
                Settings = new SharedFileSystemRepositorySettings()
                {
                    Location = path
                }
            };
            //var res2 = await Client.Snapshot.GetRepositoryAsync();//I can get repository created,so client init succeed
            var settings = new ElasticsearchClientSettings();
            //.Authentication(new BasicAuthentication("user", "password"));
            var client = new ElasticsearchClient(settings);
            //var res = await client.Snapshot.CreateRepositoryAsync(fsSettings, new Name(repoName));
            var res = await client.Snapshot.CreateRepositoryAsync(fsSettings, new Name(repoName),
                cf => cf.RequestConfiguration(
                    rc => rc.DisableDirectStreaming())
            );
            if (res.ApiCallDetails.HttpStatusCode.Equals(200))
            {
                //return res.ApiCallDetails.HasSuccessfulStatusCode;
                Assert.True(res.ApiCallDetails.HasSuccessfulStatusCode);
            }
            //Assert.True(true);
            Assert.True(res.ApiCallDetails.HasSuccessfulStatusCode);
        }

image-20240515004849279

Expected behavior

Like Postman, successfully created repository

actual

OriginalException: Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: PUT /_snapshot/my-fs-epository. ServerError: Type: parse_exception Reason: "request body is required"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions