簡體   English   中英

在Elasticsearch 5.6中存在查找索引

[英]Find index exists in elasticsearch 5.6

我在執行搜索之前嘗試檢查索引是否存在或注意到,我通過執行請求找到了解決方案,但是它不起作用,結果為NullPointerException

@Autowired
private RestHighLevelClient restHighLevelClient;

private List<E> convertToObjectList(SearchRequest searchRequest) {
    SearchResponse searchResponse = null;
    try {
        if (searchRequest != null) {
            RestClient restClient = null;
            Response response = restClient.performRequest("HEAD", "/" + index()); //java.lang.NullPointerException: null
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode != 404) {
                searchResponse = restHighLevelClient.search(searchRequest);
            }
        }
    } catch (IOException e) {
        logger.error("Error" + e);
    }
    ....
}

我絕對可以解釋您的NullPointerException

        RestClient restClient = null;
        Response response = restClient.performRequest("HEAD", "/" + index()); 

在這里,您可以restClient null初始化為restClient ,然后對其進行調用。

就像您打電話時一樣...

null.performRequest(...)

...這可能會使問題更加明顯。

您不能對null值調用任何操作(或獲取字段值或其他任何值)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM