本文整理汇总了Java中org.elasticsearch.search.sort.SortBuilder.order方法的典型用法代码示例。如果您正苦于以下问题:Java SortBuilder.order方法的具体用法?Java SortBuilder.order怎么用?Java SortBuilder.order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.search.sort.SortBuilder
的用法示例。
在下文中一共展示了SortBuilder.order方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: withScriptSort
import org.elasticsearch.search.sort.SortBuilder; //导入方法依赖的package包/类
public SimpleSearchQueryBuilder withScriptSort(String script, SortOrder order){
if(StringUtils.isBlank(script))
return this;
Script sortScript = new Script(script);
SortBuilder sortBuilder = SortBuilders.scriptSort(sortScript, "number");
sortBuilder.order(order);
this.searchQueryBuilder.withSort(sortBuilder);
return this;
}
示例3: addSort
import org.elasticsearch.search.sort.SortBuilder; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T extends SearchCriteria> T addSort(String filed, boolean asc) {
SortBuilder s = new FieldSortBuilder(filed);
if (asc) {
s.order(SortOrder.ASC);
} else {
s.order(SortOrder.DESC);
}
return (T) this;
}
示例4: create
import org.elasticsearch.search.sort.SortBuilder; //导入方法依赖的package包/类
private TestContext create(SearchType... searchTypes) throws Exception {
assertAcked(prepareCreate("index").addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("field1")
.field("type", "long")
.endObject()
.startObject("field2")
.field("type", "keyword")
.endObject()
.startObject("nested")
.field("type", "nested")
.startObject("properties")
.startObject("field3")
.field("type", "long")
.endObject()
.startObject("field4")
.field("type", "keyword")
.endObject()
.endObject()
.endObject()
.endObject().endObject().endObject()));
int numDocs = 2 + randomInt(512);
int scrollRequestSize = randomIntBetween(1, rarely() ? numDocs : numDocs / 2);
boolean unevenRouting = randomBoolean();
int numMissingDocs = scaledRandomIntBetween(0, numDocs / 100);
IntHashSet missingDocs = new IntHashSet(numMissingDocs);
for (int i = 0; i < numMissingDocs; i++) {
while (!missingDocs.add(randomInt(numDocs))) {}
}
for (int i = 1; i <= numDocs; i++) {
IndexRequestBuilder indexRequestBuilder = client()
.prepareIndex("index", "type", String.valueOf(i));
if (missingDocs.contains(i)) {
indexRequestBuilder.setSource("x", "y");
} else {
indexRequestBuilder.setSource(jsonBuilder().startObject()
.field("field1", i)
.field("field2", String.valueOf(i))
.startObject("nested")
.field("field3", i)
.field("field4", String.valueOf(i))
.endObject()
.endObject());
}
if (unevenRouting && randomInt(3) <= 2) {
indexRequestBuilder.setRouting("a");
}
indexRandom(false, indexRequestBuilder);
}
refresh();
final SortBuilder sort;
if (randomBoolean()) {
if (randomBoolean()) {
sort = SortBuilders.fieldSort("field1").missing(1);
} else {
sort = SortBuilders.fieldSort("field2")
.missing("1");
}
} else {
if (randomBoolean()) {
sort = SortBuilders.fieldSort("nested.field3").missing(1);
} else {
sort = SortBuilders.fieldSort("nested.field4").missing("1");
}
}
sort.order(randomBoolean() ? SortOrder.ASC : SortOrder.DESC);
SearchType searchType = RandomPicks.randomFrom(random(), Arrays.asList(searchTypes));
logger.info("numDocs={}, scrollRequestSize={}, sort={}, searchType={}", numDocs, scrollRequestSize, sort, searchType);
return new TestContext(numDocs, scrollRequestSize, sort, searchType);
}