1

I am getting bellow error some time and not able to get search results.

 2020-05-26 16:03:30.207 ERROR [default task-284][SearchMVCAction:148]
 exception in getting response java.io.IOException: Unrecognized SSL
 message, plaintext connection? 
 at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:954)
 at org.elasticsearch.client.RestClient.performRequest(RestClient.java:229)

my code is as below.

try{
    RestClientBuilder builder = SearchResultsUtil.getRestClientBuilder();
    RestHighLevelClient esClient = new RestHighLevelClient(builder);
    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.timeout(new TimeValue(600, TimeUnit.SECONDS)); // Request timeout
    sourceBuilder.from(pagenumber);
    sourceBuilder.sort(new ScoreSortBuilder().order(SortOrder.DESC)); //Result set ordering
    BoolQueryBuilder query = new BoolQueryBuilder();
         query.must(QueryBuilders.queryStringQuery("*"+searchWildKeyword+"*").field("content").field("title",10.0f).field("description").lenient(true).escape(true).analyzeWildcard(true).fuzziness(Fuzziness.ZERO).defaultOperator(Operator.OR).boost(1.0f));
    sourceBuilder.query(query);
    SearchRequest searchRequest = new SearchRequest(esIndice);
    searchRequest.source(sourceBuilder);
    SearchResponse searchResponse  = esClient.search(searchRequest, RequestOptions.DEFAULT);
    SearchHits hits = searchResponse.getHits();
    System.out.println("results:"+hits);
    }catch (Exception e) {
        _log.error("Exception Getting Response",e);

    }finally {
        _log.info("inside finally block");
        esClient.close();
    }

also i tried flush() but no luck.

finally {
    _log.info("inside finally block");
    esClient.close();
    esClient.indices().flush(new FlushRequest(esIndice), RequestOptions.DEFAULT);
}

kindly help what might be the cause and i am using ES 9200 port and https protocol.

Madhava
  • 47
  • 6

1 Answers1

0

You will have to refactor your code a bit. Please find working example with regards to RestHighLevelClient below.

    @Bean
public RestHighLevelClient elasticRestClient () {
    String[] httpHosts = httpHostsProperty.split(";");
    HttpHost[] httpHostsAsArray = new HttpHost[httpHosts.length];
    int index = 0;

    for (String httpHostAsString : httpHosts) {
        HttpHost httpHost = new HttpHost(httpHostAsString.split(":")[0], new Integer(httpHostAsString.split(":")[1]), "http");
        httpHostsAsArray[index++] = httpHost;
    }

    RestClientBuilder restClientBuilder = RestClient.builder(httpHostsAsArray)
            .setRequestConfigCallback(builder -> builder
                    .setConnectTimeout(connectTimeOutInMs)
                    .setSocketTimeout(socketTimeOutInMs)
            );

    return new RestHighLevelClient(restClientBuilder);
}

and the class using the RestHighLevelClient:

    @Autowired
private RestHighLevelClient restClient;

        IndexResponse indexResponse = restClient.index(indexRequest, RequestOptions.DEFAULT);
  • I got the issue and it is fixed. my above code will exactly work.. only issue is in one of the node xpack.security.http.ssl.enabled: true property seted as false. After setting true i am not getting this error. thank you. – Madhava Jun 01 '20 at 10:15