org.elasticsearch.index.query.DisMaxQueryBuilder Java Examples
The following examples show how to use
org.elasticsearch.index.query.DisMaxQueryBuilder.
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: ESSearchTest.java From summerframework with Apache License 2.0 | 6 votes |
@Test public void disMaxQuery() throws IOException { QueryBuilder qb1 = QueryBuilders.termQuery("productName", "android"); QueryBuilder qb2 = QueryBuilders.termQuery("brandName", "李宁"); DisMaxQueryBuilder queryBuilder = QueryBuilders.disMaxQuery(); queryBuilder.add(qb1); queryBuilder.add(qb2); queryBuilder.boost(1.3f).tieBreaker(0.7f); queryCondition.setQueryBuilder(queryBuilder); List<Spu> list = elasticsearchTemplate.analyzeSearchResponse(Spu.class, elasticsearchTemplate.executeQuery("es_test", queryCondition, "type")); log.info("json string is:{}", mapper.writeValueAsString(list)); log.info("list size is:{}", list.size()); assertThat(list.size(), is(1)); assertThat(list.get(0), equalTo(spu1)); }
Example #2
Source File: ESSearchTest.java From summerframework with Apache License 2.0 | 6 votes |
@Test public void disMaxQuery() throws IOException { QueryBuilder qb1 = QueryBuilders.termQuery("productName", "android"); QueryBuilder qb2 = QueryBuilders.termQuery("brandName", "李宁"); DisMaxQueryBuilder queryBuilder = QueryBuilders.disMaxQuery(); queryBuilder.add(qb1); queryBuilder.add(qb2); queryBuilder.boost(1.3f).tieBreaker(0.7f); queryCondition.setQueryBuilder(queryBuilder); List<Spu> list = elasticsearchTemplate.analyzeSearchResponse(Spu.class, elasticsearchTemplate.executeQuery("es_test", queryCondition, "type")); log.info("json string is:{}", mapper.writeValueAsString(list)); log.info("list size is:{}", list.size()); assertThat(list.size(), is(1)); assertThat(list.get(0), equalTo(spu1)); }
Example #3
Source File: ElasticsearchAnySearchDAO.java From syncope with Apache License 2.0 | 6 votes |
private SearchRequest searchRequest( final Set<String> adminRealms, final SearchCond cond, final AnyTypeKind kind, final int from, final int size, final List<SortBuilder<?>> sortBuilders) { Pair<DisMaxQueryBuilder, Set<String>> filter = adminRealmsFilter(adminRealms); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(). query(SyncopeConstants.FULL_ADMIN_REALMS.equals(adminRealms) ? getQueryBuilder(cond, kind) : QueryBuilders.boolQuery(). must(filter.getLeft()). must(getQueryBuilder(buildEffectiveCond(cond, filter.getRight()), kind))). from(from). size(size); sortBuilders.forEach(sourceBuilder::sort); return new SearchRequest(ElasticsearchUtils.getContextDomainName(AuthContextUtils.getDomain(), kind)). searchType(SearchType.QUERY_THEN_FETCH). source(sourceBuilder); }
Example #4
Source File: ElasticsearchAnySearchDAO.java From syncope with Apache License 2.0 | 6 votes |
private QueryBuilder getQueryBuilder(final AssignableCond cond) { Realm realm; try { realm = check(cond); } catch (IllegalArgumentException e) { return EMPTY_QUERY_BUILDER; } DisMaxQueryBuilder builder = QueryBuilders.disMaxQuery(); if (cond.isFromGroup()) { realmDAO.findDescendants(realm).forEach( current -> builder.add(QueryBuilders.termQuery("realm", current.getFullPath()))); } else { for (Realm current = realm; current.getParent() != null; current = current.getParent()) { builder.add(QueryBuilders.termQuery("realm", current.getFullPath())); } builder.add(QueryBuilders.termQuery("realm", realmDAO.getRoot().getFullPath())); } return builder; }
Example #5
Source File: DisMaxQueryParser.java From elasticsearch-sql with MIT License | 5 votes |
@Override public void parse(ElasticDslContext dslContext) { if(dslContext.getSqlContext().selectOperation()!=null&&dslContext.getSqlContext().selectOperation().disMaxClause()!=null){ ElasticsearchParser.DisMaxClauseContext disMaxClauseContext = dslContext.getSqlContext().selectOperation().disMaxClause(); BoolExpressionParser boolExpressionParser=new BoolExpressionParser(); DisMaxQueryBuilder queryBuilder=QueryBuilders.disMaxQuery(); for(ElasticsearchParser.ExpressionContext expressionContext:disMaxClauseContext.expression()){ queryBuilder.add(boolExpressionParser.parseBoolQueryExpr(expressionContext)); } if(disMaxClauseContext.tieBreaker!=null){ queryBuilder.tieBreaker(Float.parseFloat(disMaxClauseContext.tieBreaker.getText())); } dslContext.getParseResult().setWhereCondition(queryBuilder); } }
Example #6
Source File: ElasticsearchAnySearchDAO.java From syncope with Apache License 2.0 | 5 votes |
private Pair<DisMaxQueryBuilder, Set<String>> adminRealmsFilter(final Set<String> adminRealms) { DisMaxQueryBuilder builder = QueryBuilders.disMaxQuery(); Set<String> dynRealmKeys = new HashSet<>(); RealmUtils.normalize(adminRealms).forEach(realmPath -> { if (realmPath.startsWith("/")) { Realm realm = realmDAO.findByFullPath(realmPath); if (realm == null) { SyncopeClientException noRealm = SyncopeClientException.build(ClientExceptionType.InvalidRealm); noRealm.getElements().add("Invalid realm specified: " + realmPath); throw noRealm; } else { realmDAO.findDescendants(realm).forEach( descendant -> builder.add(QueryBuilders.termQuery("realm", descendant.getFullPath()))); } } else { DynRealm dynRealm = dynRealmDAO.find(realmPath); if (dynRealm == null) { LOG.warn("Ignoring invalid dynamic realm {}", realmPath); } else { dynRealmKeys.add(dynRealm.getKey()); builder.add(QueryBuilders.termQuery("dynRealm", dynRealm.getKey())); } } }); if (!dynRealmKeys.isEmpty()) { realmDAO.findAll().forEach( descendant -> builder.add(QueryBuilders.termQuery("realm", descendant.getFullPath()))); } return Pair.of(builder, dynRealmKeys); }
Example #7
Source File: QueryGenerator.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
private QueryBuilder createQueryClauseDisMax(QueryRule queryRule, EntityType entityType) { DisMaxQueryBuilder disMaxQueryBuilder = QueryBuilders.disMaxQuery(); for (QueryRule nestedQueryRule : queryRule.getNestedRules()) { disMaxQueryBuilder.add(createQueryClause(nestedQueryRule, entityType)); } disMaxQueryBuilder.tieBreaker((float) 0.0); if (queryRule.getValue() != null) { disMaxQueryBuilder.boost(Float.parseFloat(queryRule.getValue().toString())); } return disMaxQueryBuilder; }