2014-09-03 20 views
12

當我嘗試索引數據,然後做查詢,一切都很好,但如果我啓動我的應用程序,並會做查詢沒有索引之前,我得到這個錯誤elasticsearch失敗,出現錯誤「無法執行階段[query_fetch],所有的碎片失敗」

Exception in thread "main" org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query_fetch], all shards failed at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:272) 
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:224) 
    at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:307) 
    at org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryAndFetchAction.java:71) 
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216) 
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:203) 
    at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:186) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 

這裏是我的代碼和elasticsearch

// settings 
    ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder(); 
    settings.put("client.transport.sniff", false); 
    settings.put("path.home", "/path/to/elastic/home"); 
    settings.put("index.number_of_replicas", 0); 
    settings.put("index.number_of_shards", 1); 
    settings.put("action.write_consistency", "one"); 

    settings.build(); 
    // creating of node and client 
    NodeBuilder nb = new NodeBuilder().settings(settings).local(true).data(true); 
    Node node = nb.node(); 
    Client client = node.client(); 


    /* 
     for (int i = 0; i <= 15; i++) { 
     IndexResponse response = client.prepareIndex("twitter2", "tweet2", String.valueOf(i)) 
       .setSource(json1) 
       .execute() 
       .actionGet(); 
     } 
    */ 

     searchRequestBuilder = client.prepareSearch("twitter2") 
      .setTypes("tweet2") 
      .setQuery(QueryBuilders.matchQuery("user", "user0")) 
      .setQuery(QueryBuilders.matchQuery("message","message1")) 
      .setExplain(true) 
      .setSearchType(SearchType.DFS_QUERY_AND_FETCH).setSize(200); 

     SearchResponse searchRespons = searchRequestBuilder.execute().actionGet(); // here is error 

的設置有什麼不對我的設置?

+0

你不能搜索一個不存在的索引/類型嗎?通過評論twitter2/tweet2的索引,你只是沒有任何東西可以搜索。 – mconlin 2014-09-03 12:27:38

+0

但我看到的路徑/路徑/到/彈性/家庭文件夾,其中包含索引我創建之前,因爲它我認爲它可能 – user3569530 2014-09-03 12:34:40

+0

你需要設置一個path.data,以便數據持久到相同點之間運行? – mconlin 2014-09-03 12:55:26

回答

4

你可以嘗試同樣增加睡眠後說10秒後

Client client = node.client(); 

我覺得Elasticsearch還沒有恢復的碎片已點擊搜索請求之前。 即使管理員呼籲「等待黃色」應該爲你工作

相關問題