本文整理匯總了Java中org.elasticsearch.action.search.SearchRequestBuilder.setFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchRequestBuilder.setFrom方法的具體用法?Java SearchRequestBuilder.setFrom怎麽用?Java SearchRequestBuilder.setFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.action.search.SearchRequestBuilder
的用法示例。
在下文中一共展示了SearchRequestBuilder.setFrom方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testFromSize
import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
public void testFromSize() throws Exception {
Builder settings = Settings.builder();
settings.put(SETTING_NUMBER_OF_SHARDS, 1);
settings.put(SETTING_NUMBER_OF_REPLICAS, 0);
assertAcked(prepareCreate("test").setSettings(settings));
for(int i=0;i<5;i++) {
client().prepareIndex("test", "type", ""+i).setSource("text", "hello world").get();
}
refresh();
SearchRequestBuilder request = client().prepareSearch();
request.setQuery(QueryBuilders.termQuery("text", "hello"));
request.setFrom(1);
request.setSize(4);
request.addRescorer(RescoreBuilder.queryRescorer(QueryBuilders.matchAllQuery()), 50);
assertEquals(4, request.get().getHits().getHits().length);
}
示例2: configurePaging
import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
private static void configurePaging(UriInfo uriInfo, SearchRequestBuilder searchRequest) {
int skip = (uriInfo.getSkipOption() == null) ? 0 : uriInfo.getSkipOption().getValue();
searchRequest.setFrom(skip);
int top = (uriInfo.getTopOption() == null) ? 20 : uriInfo.getTopOption().getValue();
searchRequest.setSize(top);
}
示例3: searchQueryRaw
import org.elasticsearch.action.search.SearchRequestBuilder; //導入方法依賴的package包/類
/**
* Executes an ElasticSearch query. This is the core method of the class.
* @param appid name of the {@link com.erudika.para.core.App}
* @param type type of object
* @param query the search query builder
* @param pager a {@link com.erudika.para.utils.Pager}
* @return a list of search results
*/
protected SearchHits searchQueryRaw(String appid, String type, QueryBuilder query, Pager... pager) {
if (StringUtils.isBlank(appid)) {
return null;
}
Pager page = ElasticSearchUtils.getPager(pager);
SortOrder order = page.isDesc() ? SortOrder.DESC : SortOrder.ASC;
int max = page.getLimit();
int pageNum = (int) page.getPage();
int start = (pageNum < 1 || pageNum > Config.MAX_PAGES) ? 0 : (pageNum - 1) * max;
if (query == null) {
query = matchAllQuery();
}
if (!StringUtils.isBlank(type)) {
query = boolQuery().must(query).must(termQuery(Config._TYPE, type));
}
SearchHits hits = null;
try {
SearchRequestBuilder srb = client().prepareSearch(getIndexName(appid)).
setSearchType(SearchType.DFS_QUERY_THEN_FETCH).
setQuery(query).
setSize(max);
if (pageNum <= 1 && !StringUtils.isBlank(page.getLastKey())) {
srb.searchAfter(new Object[]{NumberUtils.toLong(page.getLastKey())});
srb.setFrom(0);
srb.addSort(SortBuilders.fieldSort("_docid").order(order));
} else {
srb.setFrom(start);
for (SortBuilder<?> sortField : ElasticSearchUtils.getSortFieldsFromPager(page)) {
srb.addSort(sortField);
}
}
logger.debug("Elasticsearch query: {}", srb.toString());
hits = srb.execute().actionGet().getHits();
page.setCount(hits.getTotalHits());
if (hits.getHits().length > 0) {
Object id = hits.getAt(hits.getHits().length - 1).getSourceAsMap().get("_docid");
if (id != null) {
page.setLastKey(id.toString());
}
}
} catch (Exception e) {
Throwable cause = e.getCause();
String msg = cause != null ? cause.getMessage() : e.getMessage();
logger.warn("No search results for type '{}' in app '{}': {}.", type, appid, msg);
}
return hits;
}