当前位置: 首页>>代码示例>>Java>>正文


Java SortBuilders类代码示例

本文整理汇总了Java中org.elasticsearch.search.sort.SortBuilders的典型用法代码示例。如果您正苦于以下问题:Java SortBuilders类的具体用法?Java SortBuilders怎么用?Java SortBuilders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SortBuilders类属于org.elasticsearch.search.sort包,在下文中一共展示了SortBuilders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sortAdapter

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的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;
}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:27,代码来源:EsSort.java

示例2: fetchReleaseRecord

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的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");
}
 
开发者ID:oneops,项目名称:oneops,代码行数:20,代码来源:DeploymentPlanProcessor.java

示例3: executeRequest

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
/**
 * Execute query request with filter and aggregations.
 * 
 * @param query
 *            search query
 * @return ES search response
 * @throws ODataApplicationException
 *             if any error appeared during executing request
 */
public SearchResponse executeRequest(SearchQuery query) throws ODataApplicationException {
    Pagination pagination = query.getPagination();
    SearchRequestBuilder requestBuilder = client.prepareSearch(query.getIndex())
            .setTypes(query.getTypes()).setQuery(query.getQueryBuilder());
    if (pagination != null) {
        List<Sort> orderBy = pagination.getOrderBy();
        for (Sort sort : orderBy) {
            FieldSortBuilder sortQuery = SortBuilders.fieldSort(sort.getProperty())
                    .order(SortOrder.valueOf(sort.getDirection().toString()));
            requestBuilder.addSort(sortQuery);
        }
        requestBuilder.setSize(pagination.getTop()).setFrom(pagination.getSkip());
    }
    Set<String> fields = query.getFields();
    if (fields != null && !fields.isEmpty()) {
        requestBuilder.setFetchSource(fields.toArray(new String[fields.size()]), null);
    }
    return executeRequest(requestBuilder);
}
 
开发者ID:Hevelian,项目名称:hevelian-olastic,代码行数:29,代码来源:ESClient.java

示例4: search

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
@Test
void search() {
    TestDocument document = createDocument("1", "value1", 1);
    elasticSearch.flush("document");

    SearchRequest request = new SearchRequest();
    request.query = QueryBuilders.matchQuery("string_field", document.stringField);
    request.sorts.add(SortBuilders.scriptSort(new Script("doc['num_field'].value * 3"), ScriptSortBuilder.ScriptSortType.NUMBER));
    SearchResponse<TestDocument> response = documentType.search(request);

    assertEquals(1, response.totalHits);
    TestDocument returnedDocument = response.hits.get(0);
    assertEquals(document.stringField, returnedDocument.stringField);
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:15,代码来源:ElasticSearchIntegrationTest.java

示例5: testDocIdSort

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
public void testDocIdSort() throws Exception {
    int numShards = setupIndex(true);
    SearchResponse sr = client().prepareSearch("test")
        .setQuery(matchAllQuery())
        .setSize(0)
        .get();
    int numDocs = (int) sr.getHits().getTotalHits();
    assertThat(numDocs, equalTo(NUM_DOCS));
    int max = randomIntBetween(2, numShards*3);
    for (String field : new String[]{"_uid", "random_int", "static_int"}) {
        int fetchSize = randomIntBetween(10, 100);
        SearchRequestBuilder request = client().prepareSearch("test")
            .setQuery(matchAllQuery())
            .setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
            .setSize(fetchSize)
            .addSort(SortBuilders.fieldSort("_doc"));
        assertSearchSlicesWithScroll(request, field, max);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:SearchSliceIT.java

示例6: testNumericSort

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
public void testNumericSort() throws Exception {
    int numShards = setupIndex(true);
    SearchResponse sr = client().prepareSearch("test")
        .setQuery(matchAllQuery())
        .setSize(0)
        .get();
    int numDocs = (int) sr.getHits().getTotalHits();
    assertThat(numDocs, equalTo(NUM_DOCS));

    int max = randomIntBetween(2, numShards*3);
    for (String field : new String[]{"_uid", "random_int", "static_int"}) {
        int fetchSize = randomIntBetween(10, 100);
        SearchRequestBuilder request = client().prepareSearch("test")
            .setQuery(matchAllQuery())
            .setScroll(new Scroll(TimeValue.timeValueSeconds(10)))
            .addSort(SortBuilders.fieldSort("random_int"))
            .setSize(fetchSize);
        assertSearchSlicesWithScroll(request, field, max);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SearchSliceIT.java

示例7: getContributionsByCandName

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
public void getContributionsByCandName(Client client, String candName, int i)
{
	QueryBuilder matchQuery = QueryBuilders.matchQuery("candNm", candName);
	FilterBuilder contribRangeFilter = FilterBuilders.rangeFilter("contbReceiptAmt").gte(i);
	StatisticalFacetBuilder facet = FacetBuilders.statisticalFacet("stat1").field("contbReceiptAmt");
	SearchRequestBuilder request = client.prepareSearch("contributions")
			.addSort(SortBuilders.fieldSort("contbReceiptAmt").order(SortOrder.DESC))
			.setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(matchQuery).setPostFilter(contribRangeFilter)
			.addFacet(facet).setFrom(0).setSize(100)
			.addFields("contbrNm", "candNm", "contbrEmployer", "contbReceiptAmt");
	System.out.println("SEARCH QUERY: " + request.toString());

	SearchResponse response = request.execute().actionGet();
	SearchHits searchHits = response.getHits();
	SearchHit[] hits = searchHits.getHits();
	for (SearchHit hit : hits)
	{
		Map<String, SearchHitField> fields = hit.getFields();
		System.out.println(hit.getId() + ", contbrEmployer=" + fields.get("contbrEmployer").getValue().toString());
	}
}
 
开发者ID:cplutte,项目名称:bts,代码行数:22,代码来源:ElasticTest.java

示例8: findPropertiesByLocation

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
@Override
public List<Property> findPropertiesByLocation(final GeoPoint geoPoint, Double distance, final SortOrder sortOrder) {
    GeoDistanceFilterBuilder filter = FilterBuilders.geoDistanceFilter("location").point(geoPoint.getLat(), geoPoint.getLon())
            .distance(distance, DistanceUnit.KILOMETERS);

    SearchQuery searchQuery = new NativeSearchQueryBuilder()
            .withFilter(filter)
            .withSort(
                    SortBuilders.geoDistanceSort("location").point(geoPoint.getLat(), geoPoint.getLon())
                            .order(sortOrder == null ? SortOrder.ASC : sortOrder)).build();

    searchQuery.addIndices("searchahouse");
    searchQuery.addTypes("property");

    List<Property> properties = this.elasticsearchOperations.queryForList(searchQuery, Property.class);

    return properties;
}
 
开发者ID:gustavoorsi,项目名称:searchahouse.com,代码行数:19,代码来源:PropertyServiceImpl.java

示例9: getMostRecentEntry

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
/**
 * Gets the creation data of the single newest entry.
 *
 * @return ISO8601 formatted time of most recent entry, or null on empty or error.
 */
private String getMostRecentEntry() {
    long totalEntries = client.prepareCount(index).setQuery(matchAllQuery()).execute().actionGet().getCount();
    if (totalEntries > 0) {
        FilteredQueryBuilder updatedAtQuery = QueryBuilders
                .filteredQuery(QueryBuilders.matchAllQuery(), FilterBuilders.existsFilter("created_at"));
        FieldSortBuilder updatedAtSort = SortBuilders.fieldSort("created_at").order(SortOrder.DESC);

        SearchResponse response = client.prepareSearch(index)
                .setQuery(updatedAtQuery)
                .addSort(updatedAtSort)
                .setSize(1)
                .execute()
                .actionGet();

        String createdAt = (String) response.getHits().getAt(0).getSource().get("created_at");
        logger.debug("Most recent event was created at {}", createdAt);
        return createdAt;
    } else {
        // getData will get all data on a null.
        logger.info("No existing entries, assuming first run");
        return null;
    }
}
 
开发者ID:uberVU,项目名称:elasticsearch-river-github,代码行数:29,代码来源:GitHubRiver.java

示例10: mostRecentDocument

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的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;
}
 
开发者ID:jprante,项目名称:elasticsearch-helper,代码行数:18,代码来源:BaseClient.java

示例11: applyDefaultSortPredicates

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
/**
 * Apply our default sort predicate logic
 */
private void applyDefaultSortPredicates( final SearchRequestBuilder srb, final GeoSortFields geoFields ) {
    //we have geo fields, sort through them in visit order
    for ( String geoField : geoFields.fields() ) {

        final GeoDistanceSortBuilder geoSort = geoFields.applyOrder( geoField, SortOrder.ASC );

        srb.addSort( geoSort );
    }

    //now sort by edge timestamp, then entity id
    //sort by the edge timestamp
    srb.addSort( SortBuilders.fieldSort( IndexingUtils.EDGE_TIMESTAMP_FIELDNAME ).order( SortOrder.DESC ) );

    // removing secondary sort by entity ID -- takes ES resources and provides no benefit
    //sort by the entity id if our times are equal
    //srb.addSort( SortBuilders.fieldSort( IndexingUtils.ENTITY_ID_FIELDNAME ).order( SortOrder.ASC ) );

    return;
}
 
开发者ID:apache,项目名称:usergrid,代码行数:23,代码来源:SearchRequestBuilderStrategy.java

示例12: fieldSort

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
@Override
public QueryBuilderHelper fieldSort(String fieldName, boolean desc) {
    if (fieldName == null) {
        return this;
    }
    fieldSort = true;
    FieldSortBuilder sortBuilder = SortBuilders.fieldSort(fieldName);
    if (desc) {
        sortBuilder.order(SortOrder.DESC);
    } else {
        sortBuilder.order(SortOrder.ASC);
    }
    // TODO: change to use sortBuilder.unmappedType
    sortBuilder.ignoreUnmapped(true);
    searchRequestBuilder.addSort(sortBuilder);
    return this;
}
 
开发者ID:alien4cloud,项目名称:elasticsearch-mapping-parent,代码行数:18,代码来源:QueryHelper.java

示例13: addFuzzyQuery

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
private QueryBuilder addFuzzyQuery(
        IndexQueryParams queryParams,
        QueryBuilder queryBuilder,
        SearchRequestBuilder reqBuilder
) {
    if (queryParams.getFuzzyQueryParams().isPresent()) {
        queryBuilder = addTitleQuery(queryParams, queryBuilder);
        if (queryParams.getBroadcastWeighting().isPresent()) {
            queryBuilder = BroadcastQueryBuilder.build(
                    queryBuilder,
                    queryParams.getBroadcastWeighting().get()
            );
        } else {
            queryBuilder = BroadcastQueryBuilder.build(queryBuilder, 5f);
        }
        reqBuilder.addSort(SortBuilders.scoreSort().order(SortOrder.DESC));
    }
    return queryBuilder;
}
 
开发者ID:atlasapi,项目名称:atlas-deer,代码行数:20,代码来源:EsUnequivalentContentIndex.java

示例14: ShellScope

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
/**
 * Creates a new <code>ShellScope</code> given the actual scope object
 * @param scope the actual scope object that depends on the engine in use
 */
ShellScope(Scope scope, ResourceRegistry resourceRegistry) {
    this.scope = scope;
    this.resourceRegistry = resourceRegistry;
    registerJavaClass(Requests.class);
    registerJavaClass(SearchSourceBuilder.class);
    registerJavaClass(QueryBuilders.class);
    registerJavaClass(FilterBuilders.class);
    registerJavaClass(SortBuilders.class);
    registerJavaClass(FacetBuilders.class);
    registerJavaClass(RescoreBuilder.class);
    registerJavaClass(SuggestBuilder.class);
    registerJavaClass(AliasAction.class);
    registerJavaClass(HttpParameters.class);
    registerJavaClass(AllocateAllocationCommand.class);
    registerJavaClass(CancelAllocationCommand.class);
    registerJavaClass(MoveAllocationCommand.class);
    registerJavaClass(ShardId.class);
}
 
开发者ID:javanna,项目名称:elasticshell,代码行数:23,代码来源:ShellScope.java

示例15: buildRequest

import org.elasticsearch.search.sort.SortBuilders; //导入依赖的package包/类
private SearchRequestBuilder buildRequest(String script, Object... params) {
    ensureGreen("test");

    Map<String, Object> paramsMap = new HashMap<>();
    assert (params.length % 2 == 0);
    for (int i = 0; i < params.length; i += 2) {
        paramsMap.put(params[i].toString(), params[i + 1]);
    }

    SearchRequestBuilder req = client().prepareSearch().setIndices("test");
    req.setQuery(QueryBuilders.matchAllQuery())
            .addSort(SortBuilders.fieldSort("_uid")
                    .order(SortOrder.ASC))
            .addScriptField("foo", new Script(ScriptType.INLINE, "expression", script, paramsMap));
    return req;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MoreExpressionTests.java


注:本文中的org.elasticsearch.search.sort.SortBuilders类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。