本文整理汇总了Java中org.elasticsearch.search.sort.SortOrder类的典型用法代码示例。如果您正苦于以下问题:Java SortOrder类的具体用法?Java SortOrder怎么用?Java SortOrder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortOrder类属于org.elasticsearch.search.sort包,在下文中一共展示了SortOrder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: minMaxQuery
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
private SearchResponse minMaxQuery(ScoreMode scoreMode, int minChildren, Integer maxChildren) throws SearchPhaseExecutionException {
HasChildQueryBuilder hasChildQuery = hasChildQuery(
"child",
QueryBuilders.functionScoreQuery(constantScoreQuery(QueryBuilders.termQuery("foo", "two")),
new FunctionScoreQueryBuilder.FilterFunctionBuilder[]{
new FunctionScoreQueryBuilder.FilterFunctionBuilder(weightFactorFunction(1)),
new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("foo", "three"), weightFactorFunction(1)),
new FunctionScoreQueryBuilder.FilterFunctionBuilder(QueryBuilders.termQuery("foo", "four"), weightFactorFunction(1))
}).boostMode(CombineFunction.REPLACE).scoreMode(FiltersFunctionScoreQuery.ScoreMode.SUM), scoreMode)
.minMaxChildren(minChildren, maxChildren != null ? maxChildren : HasChildQueryBuilder.DEFAULT_MAX_CHILDREN);
return client()
.prepareSearch("test")
.setQuery(hasChildQuery)
.addSort("_score", SortOrder.DESC).addSort("id", SortOrder.ASC).get();
}
示例2: fetchReleaseRecord
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
private CmsRelease fetchReleaseRecord(String nsPath, Date ts, int genTime) throws InterruptedException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(CmsConstants.SEARCH_TS_PATTERN);
Thread.sleep(3000);
SearchQuery latestRelease = new NativeSearchQueryBuilder()
.withIndices("cms-*")
.withTypes("release").withFilter(
FilterBuilders.andFilter(
FilterBuilders.queryFilter(QueryBuilders.termQuery("nsPath.keyword", nsPath)),
FilterBuilders.queryFilter(QueryBuilders.rangeQuery("created").
from(simpleDateFormat.format(DateUtils.addMinutes(ts, -(genTime + 10)))).
to(simpleDateFormat.format(ts))))).
withSort(SortBuilders.fieldSort("created").order(SortOrder.DESC)).build();
List<CmsReleaseSearch> ciList = indexer.getTemplate().queryForList(latestRelease, CmsReleaseSearch.class);
if (!ciList.isEmpty()) {
return ciList.get(0);
}
throw new RuntimeException("Cant find bom release for deployment plan generation event");
}
示例3: getTopicByCateAndUser
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
@Override
public FacetedPage<Topic> getTopicByCateAndUser(String cate , String q , String user ,final int p , final int ps) {
FacetedPage<Topic> pages = null ;
NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(termQuery("cate" , cate)).withQuery(termQuery("creater" , user)).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC));
if(!StringUtils.isBlank(q)){
searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
}
SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps));
if(elasticsearchTemplate.indexExists(Topic.class)){
if(!StringUtils.isBlank(q)){
pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class, new UKResultMapper());
}else{
pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class);
}
}
return pages ;
}
示例4: getDocumentUsingScroll
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
/**
* This method used to get the document using scroll concept
*/
@Override
public void getDocumentUsingScroll() {
try {
client = ESclient.getInstant();
QueryBuilder qb = termQuery("name", "sundar");
SearchResponse scrollResp = client.prepareSearch("school", "college")
.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
.setScroll(new TimeValue(60000))
.setQuery(qb)
.setSize(100).get(); //max of 100 hits will be returned for each scroll, Scroll until no hits are returned
do {
for (SearchHit hit : scrollResp.getHits().getHits()) {
//Handle the hit...
hit.getField("name");
}
scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
} while (scrollResp.getHits().getHits().length != 0); // Zero hits mark the end of the scroll and the while loop.
} catch (Exception ex) {
log.info("Exception occurred while Scroll Document : " + ex);
}
}
示例5: testNoopFielddataBreaker
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
public void testNoopFielddataBreaker() throws Exception {
assertAcked(prepareCreate("cb-test", 1, Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))));
Client client = client();
// index some different terms so we have some field data for loading
int docCount = scaledRandomIntBetween(300, 1000);
List<IndexRequestBuilder> reqs = new ArrayList<>();
for (long id = 0; id < docCount; id++) {
reqs.add(client.prepareIndex("cb-test", "type", Long.toString(id)).setSource("test", id));
}
indexRandom(true, reqs);
// Sorting using fielddata and thus the FIELDDATA breaker
client.prepareSearch("cb-test").setQuery(matchAllQuery()).addSort("test", SortOrder.DESC).get();
// no exception because the breaker is a noop
}
示例6: testTopLevel
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
public void testTopLevel() throws Exception {
Aggregation result;
if (randomBoolean()) {
result = testCase(new MatchAllDocsQuery(), topHits("_name").sort("string", SortOrder.DESC));
} else {
Query query = new QueryParser("string", new KeywordAnalyzer()).parse("d^1000 c^100 b^10 a^1");
result = testCase(query, topHits("_name"));
}
SearchHits searchHits = ((TopHits) result).getHits();
assertEquals(3L, searchHits.getTotalHits());
assertEquals("3", searchHits.getAt(0).getId());
assertEquals("type", searchHits.getAt(0).getType());
assertEquals("2", searchHits.getAt(1).getId());
assertEquals("type", searchHits.getAt(1).getType());
assertEquals("1", searchHits.getAt(2).getId());
assertEquals("type", searchHits.getAt(2).getType());
}
示例7: testQueryThenFetchWithSort
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
public void testQueryThenFetchWithSort() throws Exception {
prepareData();
int total = 0;
SearchResponse searchResponse = client().prepareSearch("test").setQuery(termQuery("multi", "test")).setSize(60).setExplain(true).addSort("age", SortOrder.ASC).setScroll(TimeValue.timeValueSeconds(30)).get();
while (true) {
assertNoFailures(searchResponse);
assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L));
SearchHit[] hits = searchResponse.getHits().getHits();
if (hits.length == 0) {
break; // finished
}
for (int i = 0; i < hits.length; ++i) {
SearchHit hit = hits[i];
assertThat(hit.getExplanation(), notNullValue());
assertThat("id[" + hit.getId() + "]", hit.getId(), equalTo(Integer.toString(total + i)));
}
total += hits.length;
searchResponse = client().prepareSearchScroll(searchResponse.getScrollId()).setScroll(TimeValue.timeValueSeconds(30)).get();
}
clearScroll(searchResponse.getScrollId());
assertEquals(100, total);
}
示例8: testCloseAndReopenOrDeleteWithActiveScroll
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
public void testCloseAndReopenOrDeleteWithActiveScroll() throws IOException {
createIndex("test");
for (int i = 0; i < 100; i++) {
client().prepareIndex("test", "type1", Integer.toString(i)).setSource(jsonBuilder().startObject().field("field", i).endObject()).execute().actionGet();
}
refresh();
SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.setSize(35)
.setScroll(TimeValue.timeValueMinutes(2))
.addSort("field", SortOrder.ASC)
.execute().actionGet();
long counter = 0;
assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L));
assertThat(searchResponse.getHits().getHits().length, equalTo(35));
for (SearchHit hit : searchResponse.getHits()) {
assertThat(((Number) hit.getSortValues()[0]).longValue(), equalTo(counter++));
}
if (randomBoolean()) {
client().admin().indices().prepareClose("test").get();
client().admin().indices().prepareOpen("test").get();
ensureGreen("test");
} else {
client().admin().indices().prepareDelete("test").get();
}
}
示例9: assertBasicSearchWorks
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
void assertBasicSearchWorks(String indexName) {
logger.info("--> testing basic search");
SearchRequestBuilder searchReq = client().prepareSearch(indexName).setQuery(QueryBuilders.matchAllQuery());
SearchResponse searchRsp = searchReq.get();
ElasticsearchAssertions.assertNoFailures(searchRsp);
long numDocs = searchRsp.getHits().getTotalHits();
logger.info("Found {} in old index", numDocs);
logger.info("--> testing basic search with sort");
searchReq.addSort("long_sort", SortOrder.ASC);
ElasticsearchAssertions.assertNoFailures(searchReq.get());
logger.info("--> testing exists filter");
searchReq = client().prepareSearch(indexName).setQuery(QueryBuilders.existsQuery("string"));
searchRsp = searchReq.get();
ElasticsearchAssertions.assertNoFailures(searchRsp);
assertEquals(numDocs, searchRsp.getHits().getTotalHits());
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings(indexName).get();
Version versionCreated = Version.fromId(Integer.parseInt(getSettingsResponse.getSetting(indexName, "index.version.created")));
if (versionCreated.onOrAfter(Version.V_2_4_0)) {
searchReq = client().prepareSearch(indexName).setQuery(QueryBuilders.existsQuery("field.with.dots"));
searchRsp = searchReq.get();
ElasticsearchAssertions.assertNoFailures(searchRsp);
assertEquals(numDocs, searchRsp.getHits().getTotalHits());
}
}
示例10: doCreateTestQueryBuilder
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
/**
* @return a {@link HasChildQueryBuilder} with random values all over the place
*/
@Override
protected HasChildQueryBuilder doCreateTestQueryBuilder() {
int min = randomIntBetween(0, Integer.MAX_VALUE / 2);
int max = randomIntBetween(min, Integer.MAX_VALUE);
QueryBuilder innerQueryBuilder = RandomQueryBuilder.createQuery(random());
if (randomBoolean()) {
requiresRewrite = true;
innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
}
HasChildQueryBuilder hqb = new HasChildQueryBuilder(CHILD_TYPE, innerQueryBuilder,
RandomPicks.randomFrom(random(), ScoreMode.values()));
hqb.minMaxChildren(min, max);
hqb.ignoreUnmapped(randomBoolean());
if (randomBoolean()) {
hqb.innerHit(new InnerHitBuilder()
.setName(randomAsciiOfLengthBetween(1, 10))
.setSize(randomIntBetween(0, 100))
.addSort(new FieldSortBuilder(STRING_FIELD_NAME_2).order(SortOrder.ASC)), hqb.ignoreUnmapped());
}
return hqb;
}
示例11: doCreateTestQueryBuilder
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
/**
* @return a {@link HasChildQueryBuilder} with random values all over the place
*/
@Override
protected NestedQueryBuilder doCreateTestQueryBuilder() {
QueryBuilder innerQueryBuilder = RandomQueryBuilder.createQuery(random());
if (randomBoolean()) {
requiresRewrite = true;
innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
}
NestedQueryBuilder nqb = new NestedQueryBuilder("nested1", innerQueryBuilder,
RandomPicks.randomFrom(random(), ScoreMode.values()));
nqb.ignoreUnmapped(randomBoolean());
if (randomBoolean()) {
nqb.innerHit(new InnerHitBuilder()
.setName(randomAsciiOfLengthBetween(1, 10))
.setSize(randomIntBetween(0, 100))
.addSort(new FieldSortBuilder(INT_FIELD_NAME).order(SortOrder.ASC)), nqb.ignoreUnmapped());
}
return nqb;
}
示例12: doCreateTestQueryBuilder
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
/**
* @return a {@link HasChildQueryBuilder} with random values all over the place
*/
@Override
protected HasParentQueryBuilder doCreateTestQueryBuilder() {
QueryBuilder innerQueryBuilder = RandomQueryBuilder.createQuery(random());
if (randomBoolean()) {
requiresRewrite = true;
innerQueryBuilder = new WrapperQueryBuilder(innerQueryBuilder.toString());
}
HasParentQueryBuilder hqb = new HasParentQueryBuilder(PARENT_TYPE, innerQueryBuilder, randomBoolean());
hqb.ignoreUnmapped(randomBoolean());
if (randomBoolean()) {
hqb.innerHit(new InnerHitBuilder()
.setName(randomAsciiOfLengthBetween(1, 10))
.setSize(randomIntBetween(0, 100))
.addSort(new FieldSortBuilder(STRING_FIELD_NAME_2).order(SortOrder.ASC)), hqb.ignoreUnmapped());
}
return hqb;
}
示例13: findUrlsByStatusAndSource
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
public List<HttpUrl> findUrlsByStatusAndSource(Enum status, String source, int count) {
BoolQueryBuilder filter = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("status", String.valueOf(status)))
.must(QueryBuilders.termQuery("source", source));
SearchResponse response = getConnection().getClient()
.prepareSearch(getIndex())
.setTypes(getType())
.setSearchType(SearchType.DEFAULT)
.setPostFilter(filter)
.addSort("created", SortOrder.DESC)
.setSize(count)
.setFetchSource(true)
.setExplain(false)
.execute()
.actionGet();
SearchHits hits = response.getHits();
return Arrays.stream(hits.getHits())
.map(SearchHit::getSource)
.map(s -> {
HttpUrl httpUrl = new HttpUrl();
httpUrl.setUrl(Objects.toString(s.get("url"), null));
httpUrl.setPublished(Objects.toString(s.get("published"), null));
httpUrl.setDiscovered(EsDataParser.nullOrDate(s.get("created")));
httpUrl.setSource(source);
return httpUrl;
})
.collect(Collectors.toList());
}
示例14: findEnabledSources
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
public List<HttpSource> findEnabledSources() {
BoolQueryBuilder filter = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("enabled", true));
SearchResponse response = getConnection().getClient()
.prepareSearch(getIndex())
.setTypes(getType())
.setSearchType(SearchType.DEFAULT)
.setPostFilter(filter)
.addSort("updated", SortOrder.ASC)
.setSize(10000)
.setFetchSource(true)
.setExplain(false)
.execute()
.actionGet();
SearchHits hits = response.getHits();
return Arrays.stream(hits.getHits())
.map(SearchHit::sourceAsMap)
.map(this::mapToHttpSource)
.collect(Collectors.toList());
}
示例15: relatedInfo
import org.elasticsearch.search.sort.SortOrder; //导入依赖的package包/类
/**
* 获取query的关联信息
*
* @param query 查询queryString
* @param size 结果集数量
* @return 相关信息
*/
public Pair<Map<String, List<Terms.Bucket>>, List<Webpage>> relatedInfo(String query, int size) {
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
.setTypes(TYPE_NAME)
.setQuery(QueryBuilders.queryStringQuery(query))
.addSort("gatherTime", SortOrder.DESC)
.addAggregation(AggregationBuilders.terms("relatedPeople").field("namedEntity.nr"))
.addAggregation(AggregationBuilders.terms("relatedLocation").field("namedEntity.ns"))
.addAggregation(AggregationBuilders.terms("relatedInstitution").field("namedEntity.nt"))
.addAggregation(AggregationBuilders.terms("relatedKeywords").field("keywords"))
.setSize(size);
SearchResponse response = searchRequestBuilder.execute().actionGet();
Map<String, List<Terms.Bucket>> info = Maps.newHashMap();
info.put("relatedPeople", ((Terms) response.getAggregations().get("relatedPeople")).getBuckets());
info.put("relatedLocation", ((Terms) response.getAggregations().get("relatedLocation")).getBuckets());
info.put("relatedInstitution", ((Terms) response.getAggregations().get("relatedInstitution")).getBuckets());
info.put("relatedKeywords", ((Terms) response.getAggregations().get("relatedKeywords")).getBuckets());
return Pair.of(info, warpHits2List(response.getHits()));
}