本文整理汇总了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;
}