我想使用ElasticSearch,所以我構建了一個簡單的JUnit測試,但測試花費了5秒來運行,我認爲它非常慢。不知道我錯過了什麼嗎?爲什麼Elasticsearch在Junit測試中速度如此之慢?
Node node = NodeBuilder.nodeBuilder().node();
Client client = node.client();
BulkRequestBuilder brb = client.prepareBulk();
Map<String, Object> json = new HashMap<>();
Map<String, Object> nest = new HashMap<>();
nest.put("foo", "blah");
json.put("Code", "123");
json.put("nut", nest);
json.put("images", newArrayList("image1", "image2"));
brb.add(new IndexRequest("promotions", "promotion").source(json));
brb.execute().actionGet();
MatchQueryBuilder itemNumber = QueryBuilders.matchQuery("Code", "123");
SearchResponse sr = client.prepareSearch("promotions").setTypes("promotion").setQuery(itemNumber).execute().actionGet();
assertThat((List)sr.getHits().getHits()[0].getSource().get("images")).contains("image1");
assertThat((List)sr.getHits().getHits()[0].getSource().get("images")).contains("image2");
assertThat((List)sr.getHits().getHits()[0].getSource().get("images")).doesNotContain("image3");
它在內存中構建一個es實例來運行測試,所以這可能會有點慢。你是否將測試的搜索部分與測試的初始化部分進行了比較? – mconlin
搜索部分非常快,但初始化和索引需要一段時間。 – toy