当前位置: 首页>>代码示例>>Java>>正文


Java SearchRequestBuilder.setFrom方法代码示例

本文整理汇总了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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:QueryRescorerIT.java

示例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);
}
 
开发者ID:pukkaone,项目名称:odata-spring-boot-starter,代码行数:8,代码来源:EntityRepository.java

示例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;
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:63,代码来源:ElasticSearch.java


注:本文中的org.elasticsearch.action.search.SearchRequestBuilder.setFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。