zoukankan      html  css  js  c++  java
  • 。。。。。。不带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);
        }
    

      

  • 相关阅读:
    友盟—安卓巴士【Android开发原创教程大赛】
    iOS开发视频教程下载/iphone开发视频教程下载
    发一个Android开发的外包项目。欢迎外包团队来骚扰
    安卓巴士总结了近百个Android优秀开源项目,覆盖Android开发的每个领域
    安卓巴士精选Android开发教程
    做了一个系列的Android开发教程列表
    深刻理解C#的传值调用和传引用调用
    《CLR Via C# 第3版》笔记之(四) 类中字段的默认赋值
    《CLR Via C# 第3版》笔记之(七) const和readonly
    《CLR Via C# 第3版》笔记之(十二) 事件
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10114135.html
Copyright © 2011-2022 走看看