• 。。。。。。不带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);
        }
    

      

  • 相关阅读:
    第010讲~第011讲:一个打了激素的数组
    练习15--阅读文件
    第007讲~第009讲:了不起的分支和循环
    第006讲:Python之常用操作符
    第005讲:闲聊之python的数据类型
    练习14--提示和传递
    第004讲:改进我们的小游戏
    ICPC Central Europe Regional Contest 2019 H. Ponk Warshall
    2019 ICPC Asia Yinchuan Regional G. Pot!!(线段树 区间更新 区间查询)
    CF1286A Garland
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10114135.html
Copyright © 2020-2023  润新知