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();
}
}