org.elasticsearch.search.collapse.CollapseBuilder Java Examples
The following examples show how to use
org.elasticsearch.search.collapse.CollapseBuilder.
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: ElasticSqlParseResult.java From elasticsearch-sql with MIT License | 6 votes |
private SearchRequest toRequest() { SearchRequest searchRequest = new SearchRequest(); List<String> indexList = indices.parallelStream().map(StringManager::removeStringSymbol).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(indexList)) { searchRequest.indices(indexList.toArray(new String[0])); } else { throw new ElasticSql2DslException("[syntax error] indices name must be set"); } //这里不会修改from的值 searchSourceBuilder.from(Math.max(from, 0)); searchSourceBuilder.size(Math.max(size, 0)); searchSourceBuilder.trackTotalHits(this.trackTotalHits); if (CollectionUtils.isNotEmpty(highlighter)) { HighlightBuilder highlightBuilder = HighlightBuilders.highlighter(highlighter); searchSourceBuilder.highlighter(highlightBuilder); } searchSourceBuilder.query(whereCondition); if (StringUtils.isNotBlank(distinctName)) { searchSourceBuilder.collapse(new CollapseBuilder(distinctName)); } if (CollectionUtils.isNotEmpty(orderBy)) { for (SortBuilder sortBuilder : orderBy) { searchSourceBuilder.sort(sortBuilder); } } searchSourceBuilder.fetchSource(includeFields.toArray(new String[0]), excludeFields.toArray(new String[0])); if (CollectionUtils.isNotEmpty(routingBy)) { searchRequest.routing(routingBy.toArray(new String[0])); } if (CollectionUtils.isNotEmpty(groupBy)) { for (AggregationBuilder aggItem : groupBy) { searchSourceBuilder.aggregation(aggItem); } } return searchRequest.source(searchSourceBuilder); }
Example #2
Source File: QueryAction.java From elasticsearch-sql with Apache License 2.0 | 5 votes |
protected void updateRequestWithCollapse(Select select, SearchRequestBuilder request) throws SqlParseException { for (Hint hint : select.getHints()) { if (hint.getType() == HintType.COLLAPSE && hint.getParams() != null && 0 < hint.getParams().length) { try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, hint.getParams()[0].toString())) { request.setCollapse(CollapseBuilder.fromXContent(parser)); } catch (IOException e) { throw new SqlParseException("could not parse collapse hint: " + e.getMessage()); } } } }
Example #3
Source File: FessEsClient.java From fess with Apache License 2.0 | 5 votes |
protected CollapseBuilder getCollapseBuilder(final FessConfig fessConfig) { final InnerHitBuilder innerHitBuilder = new InnerHitBuilder().setName(fessConfig.getQueryCollapseInnerHitsName()).setSize( fessConfig.getQueryCollapseInnerHitsSizeAsInteger()); fessConfig.getQueryCollapseInnerHitsSortBuilders().ifPresent( builders -> stream(builders).of(stream -> stream.forEach(innerHitBuilder::addSort))); return new CollapseBuilder(fessConfig.getIndexFieldContentMinhashBits()).setMaxConcurrentGroupRequests( fessConfig.getQueryCollapseMaxConcurrentGroupResultsAsInteger()).setInnerHits(innerHitBuilder); }