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

      

  • 相关阅读:
    cocos2dx动画常见特效(转)
    cocos2dx常见Action(转)
    cocos2dx常见场景切换动画(转)
    android AlertDialog.Builder(Context context)换行
    使用NPOI操作Excel文件及其日期处理
    java jar文件打包成exe(Launch4j使用说明)
    知识日志2
    知识日记1
    框架体系对小软件作坊的 重要性 第二章
    框架体系对小软件作坊的 重要性 第一章
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10114135.html
Copyright © 2020-2023  润新知