elasticsearch:インターフェースを呼び出してsearch.max_bucketsの値を設定します

elasticsearch:インターフェースを呼び出してsearch.max_bucketsの値を設定します

public class ElasticsearchBucketsTest {
    private static final String SET_MAX_BUCKETS_URL = "http://localhost:5601/api/console/proxy?path=_cluster%2Fsettings&method=PUT";
    private static void setMaxBuckets(int i ) throws IOException {
        Map<String,Integer> maxBuckets = new HashMap<>();
        maxBuckets.put("search.max_buckets",i);
        Map<String,Map> bodyMap = new HashMap<>();
        bodyMap.put("persistent",maxBuckets);
        String s = JSON.toJSONString(bodyMap);

        CloseableHttpResponse response = null;
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(SET_MAX_BUCKETS_URL);
        httpPost.addHeader("kbn-version","7.1.1");
        httpPost.addHeader("Content-Type","application/json");
        httpPost.setEntity(new StringEntity(s,APPLICATION_JSON));
        try{
            response = httpClient.execute(httpPost);
            String s1 = IOUtils.toString(response.getEntity().getContent(), "utf-8");
            System.out.println(s1);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            response.close();
        }
    }

おすすめ

転載: blog.csdn.net/Ice__cola/article/details/105428329