/*
package com.tashow.cloud.es.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import java.util.Arrays;

@Slf4j
@AutoConfiguration
@EnableConfigurationProperties(ElasticsearchProperties.class)
public class ElasticsearchConfigTest {

    @Bean
    public ElasticsearchClient elasticsearchClient(ElasticsearchProperties properties) {
        // 1. 创建低级 REST 客户端
        RestClient restClient = RestClient.builder(buildHttpHosts(properties))
                .setHttpClientConfigCallback(httpClientBuilder -> {
                    // 认证配置
                    if (properties.getUsername() != null) {
                        CredentialsProvider credsProvider = new BasicCredentialsProvider();
                        credsProvider.setCredentials(
                                AuthScope.ANY,
                                new UsernamePasswordCredentials(properties.getUsername(), properties.getPassword())
                        );
                        httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
                    }
                    return httpClientBuilder;
                })
                .build();

        // 2. 创建 Transport 层
        ElasticsearchTransport transport = new RestClientTransport(
                restClient,
                new JacksonJsonpMapper() // 使用 Jackson 处理 JSON
        );

        // 3. 返回新客户端
        return new ElasticsearchClient(transport);
    }

    private HttpHost[] buildHttpHosts(ElasticsearchProperties properties) {
        return Arrays.stream(properties.getUris())
                .map(uri -> {
                    try {
                        return HttpHost.create(uri);
                    } catch (Exception e) {
                        throw new IllegalArgumentException("Invalid Elasticsearch URI: " + uri, e);
                    }
                })
                .toArray(HttpHost[]::new);
    }
}*/
