SearchResponse actionGet = tc.search(new SearchRequest("vulcan").types("secrets")).actionGet(); Assert.assertEquals(1, actionGet.getHits().getHits().length); System.out.println("------- 6 ---------"); actionGet = tc.search(new SearchRequest("searchguard")).actionGet(); Assert.assertEquals(0, actionGet.getHits().getHits().length);
SearchResponse actionGet = tc.search(new SearchRequest("vulcan").types("secrets")).actionGet(); Assert.assertEquals(1, actionGet.getHits().getHits().length); System.out.println("------- 6 ---------"); actionGet = tc.search(new SearchRequest("searchguard")).actionGet(); Assert.assertEquals(0, actionGet.getHits().getHits().length);
/** * 非同期でドキュメントを検索. * @param index インデックス名 * @param query クエリ情報 * @return 非同期応答 */ public ActionFuture<SearchResponse> asyncSearch(String index, Map<String, Object> query) { SearchRequest req = new SearchRequest(index).searchType(SearchType.DEFAULT); if (query != null) { req.source(query); } ActionFuture<SearchResponse> ret = esTransportClient.search(req); this.fireEvent(Event.afterRequest, index, null, null, JSONObject.toJSONString(query), "Search"); return ret; }
/** * 非同期でドキュメントを検索. <br /> * Queryの指定方法をMapで直接記述せずにQueryBuilderにするため、非推奨とする. * @param index インデックス名 * @param routingId routingId * @param query クエリ情報 * @return 非同期応答 */ public ActionFuture<SearchResponse> asyncSearch( String index, String routingId, Map<String, Object> query) { SearchRequest req = new SearchRequest(index).searchType(SearchType.DEFAULT); if (query != null) { req.source(query); } if (routingFlag) { req = req.routing(routingId); } ActionFuture<SearchResponse> ret = esTransportClient.search(req); this.fireEvent(Event.afterRequest, index, null, null, JSONObject.toJSONString(query), "Search"); return ret; }
/** * 非同期でドキュメントを検索. * @param index インデックス名 * @param type タイプ名 * @param routingId routingId * @param query クエリ情報 * @return 非同期応答 */ public ActionFuture<SearchResponse> asyncSearch( String index, String type, String routingId, Map<String, Object> query) { SearchRequest req = new SearchRequest(index).types(type).searchType(SearchType.DEFAULT); if (query != null) { req.source(query); } if (routingFlag) { req = req.routing(routingId); } ActionFuture<SearchResponse> ret = esTransportClient.search(req); this.fireEvent(Event.afterRequest, index, type, null, JSONObject.toJSONString(query), "Search"); return ret; }
/** * クエリを指定してスクロールサーチを実行する. * @param index インデックス名 * @param type タイプ名 * @param query 検索クエリ * @return 非同期応答 */ public ActionFuture<SearchResponse> asyncScrollSearch(String index, String type, Map<String, Object> query) { SearchRequest req = new SearchRequest(index) .searchType(SearchType.SCAN) .scroll(new TimeValue(SCROLL_SEARCH_KEEP_ALIVE_TIME)); if (type != null) { req.types(type); } if (query != null) { req.source(query); } ActionFuture<SearchResponse> ret = esTransportClient.search(req); return ret; }
/** * 非同期でドキュメントを検索. * @param index インデックス名 * @param type タイプ名 * @param routingId routingId * @param builder クエリ情報 * @return 非同期応答 */ public ActionFuture<SearchResponse> asyncSearch( String index, String type, String routingId, SearchSourceBuilder builder) { SearchRequest req = new SearchRequest(index).types(type).searchType(SearchType.DEFAULT).source(builder); if (routingFlag) { req = req.routing(routingId); } ActionFuture<SearchResponse> ret = esTransportClient.search(req); this.fireEvent(Event.afterRequest, index, type, null, new String(builder.buildAsBytes().toBytes()), "Search"); return ret; }
Assert.assertEquals(1L, tc.search(new SearchRequest("test")).actionGet().getHits().getTotalHits());
/** * 非同期でドキュメントを検索. * @param index インデックス名 * @param routingId routingId * @param query クエリ情報 * @return 非同期応答 */ public ActionFuture<SearchResponse> asyncSearch( String index, String routingId, QueryBuilder query) { SearchRequest req = new SearchRequest(index).searchType(SearchType.DEFAULT); String queryString = "null"; if (query != null) { req.source(new SearchSourceBuilder().query(query)); queryString = query.buildAsBytes().toUtf8(); } if (routingFlag) { req = req.routing(routingId); } ActionFuture<SearchResponse> ret = esTransportClient.search(req); this.fireEvent(Event.afterRequest, index, null, null, queryString, "Search"); return ret; }
Assert.assertEquals("test", tc.index(new IndexRequest("test","test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"a\":5}", XContentType.JSON)).actionGet().getIndex()); log.debug("Index created"); Assert.assertEquals(1L, tc.search(new SearchRequest("test")).actionGet().getHits().getTotalHits()); log.debug("Search done"); Assert.assertEquals(3, tc.admin().cluster().health(new ClusterHealthRequest("test")).actionGet().getNumberOfNodes());
Assert.assertEquals("test", tc.index(new IndexRequest("test","test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"a\":5}", XContentType.JSON)).actionGet().getIndex()); log.debug("Index created"); Assert.assertEquals(1L, tc.search(new SearchRequest("test")).actionGet().getHits().getTotalHits()); log.debug("Search done"); Assert.assertEquals(3, tc.admin().cluster().health(new ClusterHealthRequest("test")).actionGet().getNumberOfNodes());