Java Code Examples for org.elasticsearch.index.query.DisMaxQueryBuilder#add()
The following examples show how to use
org.elasticsearch.index.query.DisMaxQueryBuilder#add() .
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 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 4
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 5
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; }