2012-10-02 16 views
9

私は、実行中の弾性検索のインスタンスと、検索Java APIを学ぶための探索的なコーディングを行っています。私は索引に文書を提出し、GETを使用してそれらを取り出すことができますが、単純な検索照会を試すと結果は得られません。いくつかのテストの後elasticsearch java API:matchAll検索クエリで結果が返されませんか?

// first, try a get request, to make sure there is something in the index 
GetResponse results = client.prepareGet(INDEX_NAME, INDEX_TYPE, testID) 
     .execute() 
     .actionGet(); 
// this assertion succeeds, as we expect it to. 
assertThat(results.getId()).isEqualTo(testID); 

// next, try the simplest possible search 
SearchResponse s1 = client.prepareSearch(INDEX_NAME).setQuery(matchAllQuery()) 
     .execute() 
     .actionGet(); 
// this assertion fails. why? answer: when we have an in-memory node, we have to 
// manually call refresh on the indexing, after submitting a document. 
assertThat(s1.getHits().totalHits()).isGreaterThanOrEqualTo(1); 

、私はこの問題は、私が(メモリに)私のノードと関連するクライアントを設定していますどのようにしていると思う:弾性検索グーグルグループの

@BeforeMethod 
    public void setup() { 
     // set up elastic search to run locally. since the transaction 
     // log needs a filesystem, we can't run it as purely in memory, 
     // but we can set the data directories into "target", so that maven will 
     // clean up after the fact: http://bit.ly/OTN7Qf 
     Settings settings = ImmutableSettings.settingsBuilder() 
       .put("node.http.enabled", true) 
       .put("path.logs","target/elasticsearch/logs") 
       .put("path.data","target/elasticsearch/data") 
       .put("gateway.type", "none") 
       .put("index.store.type", "memory") 
       .put("index.number_of_shards", 1) 
       .put("index.number_of_replicas", 1).build(); 

     node = NodeBuilder.nodeBuilder().local(true).settings(settings).node(); 
     client = node.client(); 
    } 

答えて

22

誰かが親切にしました私をここで助けてください。メモリ内ノードにドキュメントを送信した後、インデックスを更新する必要があります。

 node.client().admin().indices().prepareRefresh().execute().actionGet(); 

呼び出しの更新で問題が解決しました。

+0

ここに投稿していただきありがとうございます!時間を節約しました! – Alebon

+0

はい、ESはリアルタイムに近いです。従来のSQLデータベースのようにすぐには機能しません。 – bradvido

関連する問題