本文整理匯總了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;
}