本文整理汇总了Java中org.elasticsearch.search.builder.SearchSourceBuilder.size方法的典型用法代码示例。如果您正苦于以下问题:Java SearchSourceBuilder.size方法的具体用法?Java SearchSourceBuilder.size怎么用?Java SearchSourceBuilder.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.builder.SearchSourceBuilder
的用法示例。
在下文中一共展示了SearchSourceBuilder.size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fullTextQuerySingleField
import org.elasticsearch.search.builder.SearchSourceBuilder; //导入方法依赖的package包/类
public String fullTextQuerySingleField(String textQuery, boolean isPhraseQuery,
String fieldName, int start, int count) {
QueryBuilder qb;
if (!isPhraseQuery)
qb = QueryBuilders.matchQuery(fieldName, textQuery);
else
qb = QueryBuilders.matchPhraseQuery(fieldName, textQuery);
SearchSourceBuilder ssb = new SearchSourceBuilder();
ssb.query(qb);
ssb.from(start);
if (count > -1)
ssb.size(count);
return ssb.toString();
}
示例2: fullTextQueryMultipleFields
import org.elasticsearch.search.builder.SearchSourceBuilder; //导入方法依赖的package包/类
public String fullTextQueryMultipleFields(String textQuery, boolean isPhraseQuery,
List<String> fieldNames, int start, int count) {
BoolQueryBuilder qb = QueryBuilders.boolQuery();
String fn;
Iterator<String>itr = fieldNames.iterator();
while (itr.hasNext()) {
fn = itr.next();
if (!isPhraseQuery)
qb.should(QueryBuilders.matchQuery(fn, textQuery));
else
qb.should(QueryBuilders.matchPhraseQuery(fn, textQuery));
}
SearchSourceBuilder ssb = new SearchSourceBuilder();
ssb.query(qb);
ssb.from(start);
if (count > -1)
ssb.size(count);
return ssb.toString();
}
示例3: toSearchRequest
import org.elasticsearch.search.builder.SearchSourceBuilder; //导入方法依赖的package包/类
public SearchRequest toSearchRequest() {
SearchRequest searchRequest = new SearchRequest(indices());
searchRequest.indicesOptions(indicesOptions());
searchRequest.types(types());
searchRequest.routing(routing());
searchRequest.preference(preference());
searchRequest.source(source());
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.size(0);
if (minScore() != DEFAULT_MIN_SCORE) {
searchSourceBuilder.minScore(minScore());
}
if (terminateAfter() != DEFAULT_TERMINATE_AFTER) {
searchSourceBuilder.terminateAfter(terminateAfter());
}
searchRequest.extraSource(searchSourceBuilder);
return searchRequest;
}
示例4: find
import org.elasticsearch.search.builder.SearchSourceBuilder; //导入方法依赖的package包/类
public String find() {
try {
final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.sort("_score");
searchSourceBuilder.sort("_uid");
final String queryText = "*";
final SimpleQueryStringBuilder simpleQueryStringBuilder =
new SimpleQueryStringBuilder(queryText);
simpleQueryStringBuilder.defaultOperator(Operator.AND);
searchSourceBuilder.query(simpleQueryStringBuilder);
searchSourceBuilder.size(500);
//LOGGER.info("Elasticsearch query: {}", searchSourceBuilder.toString());
final SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("tweets");
searchRequest.types("tweet");
searchRequest.source(searchSourceBuilder);
final SearchResponse searchResponse = restHighLevelClient.search(searchRequest);
return searchResponse.toString();
} catch (IOException e) {
e.printStackTrace();
return e.getMessage();
}
}
示例5: prefixTextQuerySingleField
import org.elasticsearch.search.builder.SearchSourceBuilder; //导入方法依赖的package包/类
/**
* Return all hits which begin with <code>prefix</code>, e.g. "Wh"
* @param prefix
* @param fieldName
* @param start
* @param count
* @return
*/
public String prefixTextQuerySingleField(String prefix, String fieldName, int start, int count) {
QueryBuilder qb = QueryBuilders.prefixQuery(fieldName, prefix);
SearchSourceBuilder ssb = new SearchSourceBuilder();
ssb.query(qb);
ssb.from(start);
if (count > -1)
ssb.size(count);
return ssb.toString();
}
示例6: buildExpandSearchSourceBuilder
import org.elasticsearch.search.builder.SearchSourceBuilder; //导入方法依赖的package包/类
private SearchSourceBuilder buildExpandSearchSourceBuilder(InnerHitBuilder options) {
SearchSourceBuilder groupSource = new SearchSourceBuilder();
groupSource.from(options.getFrom());
groupSource.size(options.getSize());
if (options.getSorts() != null) {
options.getSorts().forEach(groupSource::sort);
}
if (options.getFetchSourceContext() != null) {
if (options.getFetchSourceContext().includes() == null && options.getFetchSourceContext().excludes() == null) {
groupSource.fetchSource(options.getFetchSourceContext().fetchSource());
} else {
groupSource.fetchSource(options.getFetchSourceContext().includes(),
options.getFetchSourceContext().excludes());
}
}
if (options.getDocValueFields() != null) {
options.getDocValueFields().forEach(groupSource::docValueField);
}
if (options.getStoredFieldsContext() != null && options.getStoredFieldsContext().fieldNames() != null) {
options.getStoredFieldsContext().fieldNames().forEach(groupSource::storedField);
}
if (options.getScriptFields() != null) {
for (SearchSourceBuilder.ScriptField field : options.getScriptFields()) {
groupSource.scriptField(field.fieldName(), field.script());
}
}
if (options.getHighlightBuilder() != null) {
groupSource.highlighter(options.getHighlightBuilder());
}
groupSource.explain(options.isExplain());
groupSource.trackScores(options.isTrackScores());
return groupSource;
}
示例7: findByNameEntry
import org.elasticsearch.search.builder.SearchSourceBuilder; //导入方法依赖的package包/类
private ResourceDto<ESSearchResult> findByNameEntry(String nameEntry, Integer perPage, Integer page, String... indices) {
if (nameEntry == null || nameEntry.isEmpty()) {
throw new IllegalArgumentException("Name entry can not be null");
}
if (page == null) {
page = FIRST_PAGE_NUM;
}
if (page <= 0) {
throw new IllegalArgumentException("Page must be greater than zero");
}
if (perPage == null) {
perPage = PER_PAGE_DEFAULT;
}
if (perPage <= 0) {
throw new IllegalArgumentException("Per page value must be greater than zero");
}
JsonNode jsonQuery = matchQueryByName(nameEntry);
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(QueryBuilders.wrapperQuery(jsonQuery.toString()));
int offset = (page - 1) * perPage;
sourceBuilder.from(offset);
sourceBuilder.size(perPage);
SearchRequest searchRequest = new SearchRequest(indices);
searchRequest.source(sourceBuilder);
ResourceDto<ESSearchResult> resultPage = new ResourceDto<>();
try {
SearchResponse response = client.search(searchRequest);
JsonNode result = mapper.readTree(response.toString());
resultPage.setResults(mapToResultList(result));
resultPage.setPagination(getPaginationInfo(page, perPage, response.getHits().getTotalHits()));
} catch (IOException e) {
log.warn("Can not get ES search response. Exception: {}", e);
}
return resultPage;
}
示例8: wildCardTextQuerySingleField
import org.elasticsearch.search.builder.SearchSourceBuilder; //导入方法依赖的package包/类
/**
* <p>e.g. "W?F*HW"
* where "?" matches any character
* where * matches zero or more characters</p>
* <p>Note, avoid using terms which begin with a wildcard,
* e.g. *foo</p>
* @param textQuery
* @param fieldName
* @param start
* @param count
* @return
* @see https://www.elastic.co/guide/en/elasticsearch/guide/current/_wildcard_and_regexp_queries.html
*/
public String wildCardTextQuerySingleField(String textQuery, String fieldName, int start, int count) {
QueryBuilder qb = QueryBuilders.wildcardQuery(fieldName, textQuery);
SearchSourceBuilder ssb = new SearchSourceBuilder();
ssb.query(qb);
ssb.from(start);
if (count > -1)
ssb.size(count);
return ssb.toString();
}