本文整理汇总了Java中org.elasticsearch.search.SearchHits.getTotalHits方法的典型用法代码示例。如果您正苦于以下问题:Java SearchHits.getTotalHits方法的具体用法?Java SearchHits.getTotalHits怎么用?Java SearchHits.getTotalHits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.SearchHits
的用法示例。
在下文中一共展示了SearchHits.getTotalHits方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIterable
import org.elasticsearch.search.SearchHits; //导入方法依赖的package包/类
protected <T> ElasticsearchGraphQueryIterable<T> createIterable(
SearchResponse response,
QueryParameters filterParameters,
Iterable<T> MemgraphObjects,
boolean evaluateQueryString,
boolean evaluateHasContainers,
boolean evaluateSortContainers,
long searchTimeInMillis,
SearchHits hits
) {
return new ElasticsearchGraphQueryIterable<>(
this,
response,
filterParameters,
MemgraphObjects,
evaluateQueryString,
evaluateHasContainers,
evaluateSortContainers,
hits.getTotalHits(),
searchTimeInMillis * 1000000,
hits
);
}
示例2: queryByEsQueryDo
import org.elasticsearch.search.SearchHits; //导入方法依赖的package包/类
public EsResponse queryByEsQueryDo(EsQueryDo esQueryObj) throws EsException {
validationEsQuery(esQueryObj.getIndexName(),esQueryObj.getTypeName());
//创建ES查询Request对象
SearchRequestBuilder esSearch=buildSearchRequest (esQueryObj);
//执行查询
SearchResponse response =esSearch.execute().actionGet();
JSONObject resObj = new JSONObject();
//获取facet结果
if(!Check.NuNObject(esQueryObj.aggregationFields())){
parseAggregationResult(response, esQueryObj.aggregationFields(), resObj);
}
//1、获取搜索的文档结果
SearchHits searchHits = response.getHits();
if (searchHits == null || searchHits.getTotalHits() == 0) {
return EsResponse.responseOK(null);
}
SearchHit[] hits = searchHits.getHits();
resObj.put("total", searchHits.getTotalHits());
//1.1、获取搜索结果
parseSearchResult(hits, esQueryObj.isHighLigth(), esQueryObj, resObj);
return EsResponse.responseOK(resObj);
}
示例3: SearchResult
import org.elasticsearch.search.SearchHits; //导入方法依赖的package包/类
public SearchResult(SearchResponse resp) {
SearchHits hits = resp.getHits();
this.total = hits.getTotalHits();
results = new ArrayList<>(hits.getHits().length);
for (SearchHit searchHit : hits.getHits()) {
if (searchHit.getSource() != null) {
results.add(searchHit.getSource());
} else if (searchHit.getFields() != null) {
Map<String, SearchHitField> fields = searchHit.getFields();
results.add(toFieldsMap(fields));
}
}
}
示例4: convertToDocumentsAndTotalCount
import org.elasticsearch.search.SearchHits; //导入方法依赖的package包/类
@Nonnull
@Override
public <T extends AbstractEsDocument> DocumentsAndTotalCount<T> convertToDocumentsAndTotalCount(@Nonnull final SearchResponse searchResponse,
@Nonnull final Class<T> clazz) {
assertSearchResponseNotNull(searchResponse);
assertClazzNotNull(clazz);
final SearchHits searchHits = searchResponse.getHits();
final List<T> documents = extractDocuments(searchHits, clazz);
return new DocumentsAndTotalCount<>(documents, searchHits.getTotalHits());
}
示例5: search
import org.elasticsearch.search.SearchHits; //导入方法依赖的package包/类
/**
* 查询
*
* @param queryBuilder
* @param type
* @param sortField 排序字段
* @param desc
* @param from 分页起始偏移量
* @param size 页面大小
* @return
*/
private static <T> Pagination<T> search(QueryBuilder queryBuilder, IndexType type, String sortField, boolean desc, int from, int size) {
List<T> results = new ArrayList<>();
//不同的索引 变量 代码通用
SearchRequestBuilder serachBuilder = EsClientManager.getClient().prepareSearch(esprop.getIndice())
.setTypes(type.getDataName())
.setQuery(queryBuilder);
if (!StringUtils.isEmpty(sortField)) {
if (sortField.equalsIgnoreCase(SortMode.ORDERVALUE_ASC.getSortField())) {
serachBuilder.addSort("_score", SortOrder.DESC);
}
serachBuilder.addSort(sortField, desc ? SortOrder.DESC : SortOrder.ASC);
}
if (0 != size) {
serachBuilder.setFrom(from).setSize(size);
}
SearchResponse response = serachBuilder.execute().actionGet();
SearchHits searchHits = response.getHits();
SearchHit[] hits = searchHits.getHits();
for (SearchHit hit : hits) {
results.add((T) EsDataUtil.readValue(hit.source(), type.getTypeClass()));
}
int total = (int) searchHits.getTotalHits();
Pagination pagination = new Pagination();
pagination.setDataList(results);
pagination.setTotalCount(total);
return pagination;
}