。。。。。。不带http https : 不报错 spring boot elasticsearch rest

。。。。。。不带http https  : 不报错

先telnet

http://onf:8080/getES653/道路桥梁正在“理疗”%20这14条道路纳入市政中修

    @GetMapping("/getES653/{requestTitle}")
    public ResponseEntity getES653(@PathVariable String requestTitle) throws IOException {
        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        String TitleIndex = "search_title";
        String TextIndex = "search_text";
        long timeMillisSpent = 0;
        long startEsSearch = System.currentTimeMillis();
        long endEsSearch;
        String res = "";
        credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("elastic", "aliyun"));
        RestClient restClient = RestClient.builder(new HttpHost("es-cn-mpaliyun232ts.elasticsearch.aliyuncs.com", 9200))
                .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                    @Override
                    public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                        return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                    }
                }).build();
        try {
            String searchStrWithoutTitle = "{"from":0,"size":200,"query":{"bool":{"should":[{"match":{"keyword":{"query":"宝宝","boost":2}}},{"match":{"text":{"query":"婴幼儿,教育,家庭教育,幼儿培训,早教培训,早教课程","boost":1}}}]}},"track_scores":"true","sort":[{"weight":{"order":"desc"}},{"_score":{"order":"desc"}}]}";
            String searchStrWithTitle = "{"from":0,"size":200,"query":{"bool":{"should":{"match":{"title":{"query":" + requestTitle + ","boost":1}}}}},"track_scores":"true","sort":[{"weight":{"order":"desc"}},{"_score":{"order":"desc"}}]}";
            HttpEntity httpEntity = new StringEntity(searchStrWithoutTitle, ContentType.APPLICATION_JSON);

            //search a document
            System.out.println(searchStrWithTitle);
            String endpoint = "/search_text/_search?";
            Response response = restClient.performRequest("GET", endpoint,
                    Collections.singletonMap("pretty", "true"), httpEntity);
            endEsSearch = System.currentTimeMillis();
            timeMillisSpent = endEsSearch - startEsSearch;
            res = EntityUtils.toString(response.getEntity());
            System.out.println("searchES-TimeMillisSpent:" + timeMillisSpent);

        } catch (IOException e) {
            e.printStackTrace();
        }
        String timeMillisSpentStr = Long.toString(timeMillisSpent);
        JSONObject jsonObject = JSONObject.parseObject(res);
        return new ResponseEntity<JSONObject>(jsonObject, HttpStatus.OK);
    }

  

原文地址:https://www.cnblogs.com/rsapaper/p/10114135.html