Java Code Examples for org.elasticsearch.search.sort.SortMode

The following examples show how to use org.elasticsearch.search.sort.SortMode. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: elasticsearch-sql   Author: iamazy   File: QueryOrderByParser.java    License: MIT License 6 votes vote down vote up
@Override
public void parse(ElasticDslContext dslContext) {
    if(dslContext.getSqlContext().selectOperation()!=null&&dslContext.getSqlContext().selectOperation().groupByClause()==null){
        if(dslContext.getSqlContext().selectOperation().orderClause()!=null){
            ElasticsearchParser.OrderClauseContext orderClauseContext=dslContext.getSqlContext().selectOperation().orderClause();
            for(ElasticsearchParser.OrderContext orderContext:orderClauseContext.order()){
                ElasticsearchParser.NameClauseContext nameContext = orderContext.nameClause();
                if(nameContext instanceof ElasticsearchParser.FieldNameContext){
                    ElasticsearchParser.FieldNameContext fieldNameContext=(ElasticsearchParser.FieldNameContext)nameContext;
                    String field = fieldNameContext.field.getText();
                    if(fieldNameContext.highlighter!=null){
                        dslContext.getParseResult().getHighlighter().add(field);
                    }
                    SortOrder sortOrder;
                    if(orderContext.ASC()!=null) {
                        sortOrder=SortOrder.ASC;
                    }else{
                        sortOrder=SortOrder.DESC;
                    }
                    SortBuilder sortBuilder = SortBuilders.fieldSort(field).sortMode(SortMode.AVG).order(sortOrder);
                    dslContext.getParseResult().getOrderBy().add(sortBuilder);
                }
            }
        }
    }
}
 
Example #2
Source Project: james-project   Author: apache   File: SortConverter.java    License: Apache License 2.0 4 votes vote down vote up
public static FieldSortBuilder convertSort(SearchQuery.Sort sort) {
    return getSortClause(sort.getSortClause())
        .order(getOrder(sort))
        .sortMode(SortMode.MIN);
}
 
Example #3
Source Project: molgenis   Author: molgenis   File: SortContentBuilder.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
private SortBuilder createSort(SortOrder sortOrder) {
  String field = sortOrder.getField();
  org.elasticsearch.search.sort.SortOrder order = toSortOrder(sortOrder.getDirection());
  return SortBuilders.fieldSort(field).order(order).sortMode(SortMode.MIN);
}