2014-03-28 105 views
3

我正在爲ElasticSearch中的搜索文檔編寫一些測試,但我收到IndexMissingException [indexed_store_detail] missing.I在我的測試中創建了一個節點。在測試開始時,我插入文檔並當我撥打以下電話時,我收到了異常。在彈性搜索中搜索商店時IndexMissingException

SearchResponse response = getClient() 
      .prepareSearch(getIndexNameV2(), getIndexTypeV2()) 
      .setQuery(QueryBuilders.idsQuery().addIds("1")) 
      .execute().actionGet(); 

這很奇怪,因爲GetResponse可以正常工作,並且字面上代碼相同。什麼可能是錯誤的?

GetResponse response = getClient().prepareGet(getIndexNameV2(), getIndexTypeV2(),"1") 
      .execute().actionGet(); 

org.elasticsearch.indices.IndexMissingException: [indexed_store_detail] missing 
at org.elasticsearch.cluster.metadata.MetaData.convertFromWildcards(MetaData.java:648) 
at org.elasticsearch.cluster.metadata.MetaData.concreteIndices(MetaData.java:559) 
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.<init>(TransportSearchTypeAction.java:112) 
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.<init>(TransportSearchQueryThenFetchAction.java:70) 
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.<init>(TransportSearchQueryThenFetchAction.java:61) 
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction.doExecute(TransportSearchQueryThenFetchAction.java:58) 
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction.doExecute(TransportSearchQueryThenFetchAction.java:48) 
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:61) 
at org.elasticsearch.action.search.TransportSearchAction.doExecute(TransportSearchAction.java:108) 
at org.elasticsearch.action.search.TransportSearchAction.doExecute(TransportSearchAction.java:43) 
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:61) 
at org.elasticsearch.client.node.NodeClient.execute(NodeClient.java:92) 
at org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:214) 
at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:841) 
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:62) 
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:57) 
at com.paypal.demandgen.places.search.server.search.TestElasticSearchResponseParserV3toV1.parsePassesForSearchResponse(TestElasticSearchResponseParserV3toV1.java:49) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:597) 
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
+0

是否後第一次運行工作? Elasticsearch中的搜索不是實時的。這是近乎實時的。如果您在命令行中輸入了全部內容(例如,使用'curl'),那麼它可能看起來像是實時的。但是,執行命令之間的時間會更快,所以我希望你輸入的索引名稱錯誤(因此類似404的例外),或者您正在搜索響應的速度太快。坦率地說,我懷疑前者比階梯更重要,因爲索引的存在將在文檔實際可搜索之前出現,但您仍然可以更快。 – pickypg

+0

否第一次運行後它不起作用。每次prepareSearch請求失敗,但每次都通過prepareGet請求 –

+0

因爲這些是由JUnit執行的,所以這些查詢也可能並行(或非常接近它可能會這樣做)。確保索引實際上已經發生了,可能是'@ BeforeClass',並且可能有一個強制延遲。我們能否看到索引代碼(以及它如何與搜索代碼交互)? – pickypg

回答

1

我發現了什麼的錯誤是。它應該被稱爲在以下fashion.It是一個學習對我來說

getClient() .prepareSearch(getIndexNameV2()).getType(getIndexTypeV2()) 
+0

啊哈!很好,我想'indexed_store_detail'是'type'而不是'index'。這是搜索和獲取API之間的一個稍微惱人的區別。 – pickypg