zoukankan      html  css  js  c++  java
  • ES查询操作

    /**
    *
    * method_name:simpleSearch
    * date:2016年11月4日上午11:10:53
    * author:terry
    * return_type:List<Map<String,Object>>
    * description:简单查询
    */
    public static List<Map<String,Object>> simpleSearch(String alias,String[] indexNames,String[] types, HashMap<String, Object[]> mustSearchContentMap, int from, int offset, String sortField, String sortType,String exisiFiled){
    long sTime = System.currentTimeMillis();
    if (offset <= 0) {
    return null;
    }
    try {
    SearchRequestBuilder searchRequestBuilder = searchClient.prepareSearch(alias).setSearchType(SearchType.DEFAULT)//SearchType.DEFAULT
    .setFrom(from).setSize(offset).setExplain(true);
    if(types != null){
    searchRequestBuilder.setTypes(types);
    }
    if (sortField == null || sortField.isEmpty() || sortType == null || sortType.isEmpty()) {
    /*如果不需要排序*/
    }
    else {
    /*如果需要排序*/
    org.elasticsearch.search.sort.SortOrder sortOrder = sortType.equals("desc") ? org.elasticsearch.search.sort.SortOrder.DESC : org.elasticsearch.search.sort.SortOrder.ASC;
    searchRequestBuilder = searchRequestBuilder.addSort(sortField, sortOrder);
    }

    if(mustSearchContentMap == null){//查询条件为空 则查询所有数据
    searchRequestBuilder = searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
    }else{
    BoolQueryBuilder bool = EsTools.createQueryBuilder(mustSearchContentMap, SearchLogic.must);
    bool.filter(QueryBuilders.existsQuery(exisiFiled));
    searchRequestBuilder = searchRequestBuilder.setQuery(bool);
    }
    //
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    long eTime = System.currentTimeMillis();
    long time = eTime - sTime;
    logger.info("====================simpleSearch查询耗时:"+time+"毫秒===============================");
    return getSearchResult(searchResponse);
    }
    catch (Exception e) {
    logger.error(e.getMessage());
    e.printStackTrace();
    }
    return null;
    }

  • 相关阅读:
    android.graphics(2)
    Android 性能优化:字体 (为自定义字体提供字体内存缓存)
    管道相关函数(1)-pipe
    【译】用boosting构建简单的目标分类器
    Ubuntu下matlab快捷键设置
    mysql导入sql文件,乱码,一个例子
    PHOG特征
    图像卷积、相关以及在MATLAB中的操作
    matlab实现hog特征
    操蛋的CTex
  • 原文地址:https://www.cnblogs.com/fuqiang-terry/p/6836289.html
Copyright © 2011-2022 走看看