本文整理汇总了Java中org.elasticsearch.search.sort.SortBuilder类的典型用法代码示例。如果您正苦于以下问题:Java SortBuilder类的具体用法?Java SortBuilder怎么用?Java SortBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortBuilder类属于org.elasticsearch.search.sort包,在下文中一共展示了SortBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sortAdapter
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
/**
*
* @param sort_fileds
* @return
*/
public static List<SortBuilder> sortAdapter(List<String> sort_fileds) {
List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
for (String sort : sort_fileds) {
String[] items = StringUtils.split(sort, " ");
if (items.length > 2 || items.length < 2) {
throw new RuntimeException("排序参数格式不正确,必须为:filed desc|asc,多个filed以逗号分隔!");
}
String[] fileds = items[0].split(",");
for (String filed : fileds) {
SortBuilder sortb = null;
if (items[0].equalsIgnoreCase("desc")) {
sortb = SortBuilders.fieldSort(filed).order(SortOrder.DESC);
} else {
sortb = SortBuilders.fieldSort(filed).order(SortOrder.ASC);
}
sortBuilders.add(sortb);
}
}
return sortBuilders;
}
示例2: doBuild
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
@Override
protected TopHitsAggregatorFactory doBuild(SearchContext context, AggregatorFactory<?> parent, Builder subfactoriesBuilder)
throws IOException {
List<ScriptFieldsContext.ScriptField> fields = new ArrayList<>();
if (scriptFields != null) {
for (ScriptField field : scriptFields) {
SearchScript searchScript = context.getQueryShardContext().getSearchScript(field.script(),
ScriptContext.Standard.SEARCH);
fields.add(new org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(
field.fieldName(), searchScript, field.ignoreFailure()));
}
}
final Optional<SortAndFormats> optionalSort;
if (sorts == null) {
optionalSort = Optional.empty();
} else {
optionalSort = SortBuilder.buildSort(sorts, context.getQueryShardContext());
}
return new TopHitsAggregatorFactory(name, from, size, explain, version, trackScores, optionalSort, highlightBuilder,
storedFieldsContext, fieldDataFields, fields, fetchSourceContext, context, parent, subfactoriesBuilder, metaData);
}
示例3: AbstractAsyncBulkByScrollAction
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
public AbstractAsyncBulkByScrollAction(WorkingBulkByScrollTask task, Logger logger, ParentTaskAssigningClient client,
ThreadPool threadPool, Request mainRequest, ScriptService scriptService, ClusterState clusterState,
ActionListener<BulkByScrollResponse> listener) {
this.task = task;
this.logger = logger;
this.client = client;
this.threadPool = threadPool;
this.scriptService = scriptService;
this.clusterState = clusterState;
this.mainRequest = mainRequest;
this.listener = listener;
BackoffPolicy backoffPolicy = buildBackoffPolicy();
bulkRetry = Retry.on(EsRejectedExecutionException.class).policy(BackoffPolicy.wrap(backoffPolicy, task::countBulkRetry));
scrollSource = buildScrollableResultSource(backoffPolicy);
scriptApplier = Objects.requireNonNull(buildScriptApplier(), "script applier must not be null");
/*
* Default to sorting by doc. We can't do this in the request itself because it is normal to *add* to the sorts rather than replace
* them and if we add _doc as the first sort by default then sorts will never work.... So we add it here, only if there isn't
* another sort.
*/
List<SortBuilder<?>> sorts = mainRequest.getSearchRequest().source().sorts();
if (sorts == null || sorts.isEmpty()) {
mainRequest.getSearchRequest().source().sort(fieldSort("_doc"));
}
mainRequest.getSearchRequest().source().version(needsSourceDocumentVersions());
}
示例4: queryToList
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
/**
*
* @param data
* @param queryBuilder
* @param postFilter
*/
@SuppressWarnings("rawtypes")
private void queryToList(UAVHttpMessage data, QueryBuilder queryBuilder, QueryBuilder postFilter,
SortBuilder[] sorts) {
SearchResponse sr = query(data, queryBuilder, postFilter, sorts);
SearchHits shits = sr.getHits();
List<Map<String, Object>> records = new ArrayList<Map<String, Object>>();
for (SearchHit sh : shits) {
Map<String, Object> record = sh.getSourceAsMap();
if (record == null) {
continue;
}
records.add(record);
}
data.putResponse("rs", JSONHelper.toString(records));
// 返回总的条数
data.putResponse("count", shits.getTotalHits() + "");
}
示例5: queryByBodyContent
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
/**
* 根据协议的报文体内容查询
*
* @param data
*/
@SuppressWarnings("rawtypes")
private void queryByBodyContent(UAVHttpMessage data) {
String[] types = buildTypes(data);
String content = data.getRequest("content");
if (types.length == 0) {
types = typeMap.values().toArray(types);
}
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
for (String type : types) {
for (String field : typeBodyMap.get(type)) {
queryBuilder.should(QueryBuilders.matchQuery(field, content));
}
}
SortBuilder[] sorts = buildSort(data);
queryToList(data, queryBuilder, null, sorts);
}
示例6: buildSort
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes" })
private SortBuilder[] buildSort(UAVHttpMessage data) {
SortBuilder[] sorts = null;
String sort = data.getRequest("sort");
if (sort != null) {
String[] sortFieldStrs = sort.split(",");
List<SortBuilder> ls = new ArrayList<SortBuilder>();
for (String sortFieldStr : sortFieldStrs) {
String[] sortExp = sortFieldStr.split("=");
SortBuilder stimeSort = new FieldSortBuilder(sortExp[0]);
stimeSort.order(SortOrder.fromString(sortExp[1]));
ls.add(stimeSort);
}
sorts = new SortBuilder[ls.size()];
sorts = ls.toArray(sorts);
}
else {
return null;
}
return sorts;
}
示例7: searchUnrestricted
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
@Override
public SearchResponse searchUnrestricted(final QueryBuilder query,
@Nullable final List<SortBuilder> sort,
final int from,
final int size)
{
if (!validateQuery(query)) {
return EMPTY_SEARCH_RESPONSE;
}
final String[] searchableIndexes = getSearchableIndexes(false);
if (searchableIndexes.length == 0) {
return EMPTY_SEARCH_RESPONSE;
}
return executeSearch(query, searchableIndexes, from, size, sort, null);
}
示例8: search
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
@Override
public SearchResponse search(final QueryBuilder query,
@Nullable final List<SortBuilder> sort,
final int from,
final int size)
{
if (!validateQuery(query)) {
return EMPTY_SEARCH_RESPONSE;
}
final String[] searchableIndexes = getSearchableIndexes(true);
if (searchableIndexes.length == 0) {
return EMPTY_SEARCH_RESPONSE;
}
try (SubjectRegistration registration = searchSubjectHelper.register(securityHelper.subject())) {
return executeSearch(query, searchableIndexes, from, size, sort,
QueryBuilders.scriptQuery(ContentAuthPluginScriptFactory.newScript(registration.getId())));
}
}
示例9: mostRecentDocument
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
public Long mostRecentDocument(String index) {
if (client() == null) {
return null;
}
SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client(), SearchAction.INSTANCE);
SortBuilder sort = SortBuilders.fieldSort("_timestamp").order(SortOrder.DESC);
SearchResponse searchResponse = searchRequestBuilder.setIndices(index).addField("_timestamp").setSize(1).addSort(sort).execute().actionGet();
if (searchResponse.getHits().getHits().length == 1) {
SearchHit hit = searchResponse.getHits().getHits()[0];
if (hit.getFields().get("_timestamp") != null) {
return hit.getFields().get("_timestamp").getValue();
} else {
return 0L;
}
}
return null;
}
示例10: sortToUri
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
private static String sortToUri(SortBuilder<?> sort) {
if (sort instanceof FieldSortBuilder) {
FieldSortBuilder f = (FieldSortBuilder) sort;
return f.getFieldName() + ":" + f.order();
}
throw new IllegalArgumentException("Unsupported sort [" + sort + "]");
}
示例11: doWriteTo
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
@Override
protected void doWriteTo(StreamOutput out) throws IOException {
out.writeBoolean(explain);
out.writeOptionalWriteable(fetchSourceContext);
boolean hasFieldDataFields = fieldDataFields != null;
out.writeBoolean(hasFieldDataFields);
if (hasFieldDataFields) {
out.writeVInt(fieldDataFields.size());
for (String fieldName : fieldDataFields) {
out.writeString(fieldName);
}
}
out.writeOptionalWriteable(storedFieldsContext);
out.writeVInt(from);
out.writeOptionalWriteable(highlightBuilder);
boolean hasScriptFields = scriptFields != null;
out.writeBoolean(hasScriptFields);
if (hasScriptFields) {
out.writeVInt(scriptFields.size());
for (ScriptField scriptField : scriptFields) {
scriptField.writeTo(out);
}
}
out.writeVInt(size);
boolean hasSorts = sorts != null;
out.writeBoolean(hasSorts);
if (hasSorts) {
out.writeVInt(sorts.size());
for (SortBuilder<?> sort : sorts) {
out.writeNamedWriteable(sort);
}
}
out.writeBoolean(trackScores);
out.writeBoolean(version);
}
示例12: addSort
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
public InnerHitBuilder addSort(SortBuilder<?> sort) {
if (sorts == null) {
sorts = new ArrayList<>();
}
sorts.add(sort);
return this;
}
示例13: setupInnerHitsContext
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
private void setupInnerHitsContext(QueryShardContext context, InnerHitsContext.BaseInnerHits innerHitsContext) throws IOException {
innerHitsContext.from(from);
innerHitsContext.size(size);
innerHitsContext.explain(explain);
innerHitsContext.version(version);
innerHitsContext.trackScores(trackScores);
if (storedFieldsContext != null) {
innerHitsContext.storedFieldsContext(storedFieldsContext);
}
if (docValueFields != null) {
innerHitsContext.docValueFieldsContext(new DocValueFieldsContext(docValueFields));
}
if (scriptFields != null) {
for (ScriptField field : scriptFields) {
SearchScript searchScript = innerHitsContext.getQueryShardContext().getSearchScript(field.script(),
ScriptContext.Standard.SEARCH);
innerHitsContext.scriptFields().add(new org.elasticsearch.search.fetch.subphase.ScriptFieldsContext.ScriptField(
field.fieldName(), searchScript, field.ignoreFailure()));
}
}
if (fetchSourceContext != null) {
innerHitsContext.fetchSourceContext(fetchSourceContext);
}
if (sorts != null) {
Optional<SortAndFormats> optionalSort = SortBuilder.buildSort(sorts, context);
if (optionalSort.isPresent()) {
innerHitsContext.sort(optionalSort.get());
}
}
if (highlightBuilder != null) {
innerHitsContext.highlight(highlightBuilder.build(context));
}
ParsedQuery parsedQuery = new ParsedQuery(query.toQuery(context), context.copyNamedQueries());
innerHitsContext.parsedQuery(parsedQuery);
}
示例14: addSort
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
/**
* Adds a sort builder. Only sorting by score desc is supported.
*
* By default the matching percolator queries are returned in an undefined order.
*/
public PercolateSourceBuilder addSort(SortBuilder sort) {
if (sorts == null) {
sorts = new ArrayList<>();
}
sorts.add(sort);
return this;
}
示例15: toXContent
import org.elasticsearch.search.sort.SortBuilder; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
if (docBuilder != null) {
docBuilder.toXContent(builder, params);
}
if (queryBuilder != null) {
builder.field("query");
queryBuilder.toXContent(builder, params);
}
if (size != null) {
builder.field("size", size);
}
if (sorts != null) {
builder.startArray("sort");
for (SortBuilder sort : sorts) {
builder.startObject();
sort.toXContent(builder, params);
builder.endObject();
}
builder.endArray();
}
if (trackScores != null) {
builder.field("track_scores", trackScores);
}
if (highlightBuilder != null) {
highlightBuilder.toXContent(builder, params);
}
if (aggregations != null) {
builder.field("aggregations");
builder.startObject();
for (AbstractAggregationBuilder aggregation : aggregations) {
aggregation.toXContent(builder, params);
}
builder.endObject();
}
builder.endObject();
return builder;
}