RequestOptions cannot be resolved to a variable

I am trying to search the data in ES using RestHighLevelClient and referring the documentation available at (https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-search.html) but getting a compilation error "RequestOptions cannot be resolved to a variable" at line "client.search(searchRequest, RequestOptions.DEFAULT);"
Could you please let me know the right way to search the data using RestHighLevelClient.

ES version: 6.3.2

Code:

RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 9200, "http"))
                    .setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
                        public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
                            return requestConfigBuilder.setConnectTimeout(5000)
                                    .setSocketTimeout(100000);
                        }
                    })
            .setMaxRetryTimeoutMillis(100000)
        );
SearchRequest searchRequest = new SearchRequest("");
										  searchRequest.types("doc");
										  SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
										  searchSourceBuilder.query(QueryBuilders.matchAllQuery());
										  searchRequest.source(searchSourceBuilder);
										  SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);

The problem here is that you're trying to use the master documentation against 6.3. Instead, you should be using the 6.3 docs. You can get to the 6.3 docs from the master docs by clicking the version drop down on the right-hand side of the page. If you follow this, you will see that RequestOptions is not referenced there (because we only added it in 6.4), and that instead the code you want is:

SearchResponse searchResponse = client.search(searchRequest);

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.