Java Code Examples for org.elasticsearch.action.search.SearchRequestBuilder#setFetchSource()

The following examples show how to use org.elasticsearch.action.search.SearchRequestBuilder#setFetchSource() . 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 File: BsElevateWordCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 2
Source File: BsRelatedQueryCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 3
Source File: BsBoostDocumentRuleCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 4
Source File: BsElevateWordToLabelCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 5
Source File: BsFileAuthenticationCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 6
Source File: BsJobLogCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 7
Source File: BsDataConfigCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 8
Source File: BsWebConfigCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 9
Source File: BsCrawlingInfoCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 10
Source File: BsRoleTypeCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 11
Source File: BsUserCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 12
Source File: BsGroupCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 13
Source File: BsDuplicateHostCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 14
Source File: BsUserInfoCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 15
Source File: BsClickLogCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 16
Source File: BsScheduledJobCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 17
Source File: BsRequestHeaderCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 18
Source File: BsFailureUrlCB.java    From fess with Apache License 2.0 6 votes vote down vote up
@Override
public SearchRequestBuilder build(SearchRequestBuilder builder) {
    if (_conditionQuery != null) {
        QueryBuilder queryBuilder = _conditionQuery.getQuery();
        if (queryBuilder != null) {
            builder.setQuery(queryBuilder);
        }
        _conditionQuery.getFieldSortBuilderList().forEach(sort -> {
            builder.addSort(sort);
        });
    }

    if (_conditionAggregation != null) {
        _conditionAggregation.getAggregationBuilderList().forEach(builder::addAggregation);
    }

    if (_specification != null) {
        builder.setFetchSource(_specification.columnList.toArray(new String[_specification.columnList.size()]), null);
    }

    return builder;
}
 
Example 19
Source File: ElasticsearchUtil.java    From SpringBootLearn with Apache License 2.0 5 votes vote down vote up
/**
 * 使用分词查询  排序 高亮
 * @param index          索引名称
 * @param type           类型名称,可传入多个type逗号分隔
 * @param query          查询条件
 * @param size           文档大小限制
 * @param fields         需要显示的字段,逗号分隔(缺省为全部字段)
 * @param sortField      排序字段
 * @param highlightField 高亮字段
 * @return 结果
 */
public static List<Map<String, Object>> searchListData(String index, String type, QueryBuilder query, Integer size, String fields, String sortField, String highlightField) {
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index);
    if (StringUtils.isNotEmpty(type)) {
        searchRequestBuilder.setTypes(type.split(","));
    }
    if (StringUtils.isNotEmpty(highlightField)) {
        HighlightBuilder highlightBuilder = new HighlightBuilder();
        // 设置高亮字段
        highlightBuilder.field(highlightField);
        searchRequestBuilder.highlighter(highlightBuilder);
    }
    searchRequestBuilder.setQuery(query);
    if (StringUtils.isNotEmpty(fields)) {
        searchRequestBuilder.setFetchSource(fields.split(","), null);
    }
    searchRequestBuilder.setFetchSource(true);
    if (StringUtils.isNotEmpty(sortField)) {
        searchRequestBuilder.addSort(sortField, SortOrder.ASC);
    }
    if (size != null && size > 0) {
        searchRequestBuilder.setSize(size);
    }//打印的内容 可以在 Elasticsearch head 和 Kibana  上执行查询
    log.info("\n{}", searchRequestBuilder);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    long totalHits = searchResponse.getHits().totalHits;
    long length = searchResponse.getHits().getHits().length;
    log.info("共查询到[{}]条数据,处理数据条数[{}]", totalHits, length);
    if (searchResponse.status().getStatus() == 200) {
        // 解析对象
        return setSearchResponse(searchResponse, highlightField);
    }
    return null;
}
 
Example 20
Source File: ESSearch.java    From common-project with Apache License 2.0 4 votes vote down vote up
public List<Map<String, Object>> execute() throws Exception {
    if (StringUtils.isEmpty(indexName)&& ArrayUtils.isEmpty(types)){
        throw new Exception("indexName or types is null");
    }
    SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch(this.indexName).setTypes(this.types);
    if (page>0&&pageSize>0){
        searchRequestBuilder.setFrom(this.page).setSize(this.pageSize);
    }

    if (!ArrayUtils.isEmpty(showField)){
        searchRequestBuilder.setFetchSource(showField,null);
    }
    if (size>0){
        searchRequestBuilder.setSize(size);
    }
    searchRequestBuilder.setFetchSource(true);
    //按字段排序
    if (!StringUtils.isEmpty(sortField)){
        String[] split = sortField.split(" ");
        if (split[1].equalsIgnoreCase("asc")){
            searchRequestBuilder.addSort(split[0], SortOrder.ASC);
        }
        if (split[1].equalsIgnoreCase("desc")){
            searchRequestBuilder.addSort(split[0], SortOrder.DESC);
        }

    }
    BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    if (bean!=null){
        Map<String, Object> fieldNameAndVauleMapping = ClassUtil.getNotNullFieldNameAndVauleMapping(this.bean);
        if (!fieldNameAndVauleMapping.isEmpty()){
            fieldNameAndVauleMapping.forEach((k,v)->{
                if (matchPhrase==true){
                    boolQuery.must(QueryBuilders.matchPhraseQuery(k,v));
                }else{
                    boolQuery.must(QueryBuilders.matchQuery(k,v));
                }
            });
        }
    }
    searchRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
    searchRequestBuilder.setQuery(boolQuery);
    // 设置是否按查询匹配度排序
    searchRequestBuilder.setExplain(true);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    long totalHits = searchResponse.getHits().totalHits;
    long length = searchResponse.getHits().getHits().length;
    logger.debug("共查询到[{}]条数据,处理数据条数[{}]", totalHits, length);
    return searchResponse(searchResponse,null);
}