您好我正在尝试使用 spring RestTemplate 在弹性搜索中搜索数据。ElasticSearch 有用户名和密码,我想通过 json 进行搜索。
我为此编写了代码,但没有得到任何结果或异常。我有生以来第一次这样做,如果其中有一些愚蠢的错误,我深表歉意。
@Override
protected List<JobPosts> doInBackground(Object[] objects) {
List list = null;
try {
SearchForm searchForms = (SearchForm) objects[0];
String plainCreds = "******:********";
final String url = "*******";
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
HttpEntity<String> request = new HttpEntity<>(searchJson, headers);
Log.d("location", "before exchange");
ResponseEntity<JobPosts[]> response = restTemplate.exchange(url, HttpMethod.GET, request, JobPosts[].class);
JobPosts[] jobPosts = response.getBody();
Log.d("location", "after exchange");
list = Arrays.asList(jobPosts);
} catch (Exception e) {
Log.d("location", e.getMessage());
}