Search in sources :

Example 91 with QueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleInBool.

@Test
public void generateOneQueryRuleInBool() {
    Iterable<Object> values = Arrays.asList(Boolean.TRUE, Boolean.FALSE);
    Query<Entity> q = new QueryImpl<>().in(boolAttrName, values);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(termsQuery(boolAttrName, Boolean.TRUE, Boolean.FALSE));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 92 with QueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleSearchAllFields.

@Test
public void generateOneQueryRuleSearchAllFields() {
    String value = "my text";
    Query<Entity> q = new QueryImpl<>().search(value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = matchPhraseQuery("_all", value).slop(10);
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 93 with QueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleLikeCompoundPartString.

@Test
public void generateOneQueryRuleLikeCompoundPartString() {
    String value = "value";
    Query<Entity> q = new QueryImpl<>().like(compoundPart0AttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = matchPhrasePrefixQuery(compoundPart0AttrName, value).slop(10).analyzer(DEFAULT_ANALYZER);
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 94 with QueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleRangeLong.

@Test
public void generateOneQueryRuleRangeLong() {
    Long low = 3L;
    Long high = 9L;
    Query<Entity> q = new QueryImpl<>().rng(longAttrName, low, high);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(rangeQuery(longAttrName).gte(3).lte(9));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 95 with QueryBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.QueryBuilder in project molgenis by molgenis.

the class QueryGeneratorTest method generateOneQueryRuleEqualsEmailNull.

@Test
public void generateOneQueryRuleEqualsEmailNull() {
    String value = null;
    Query<Entity> q = new QueryImpl<>().eq(emailAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(boolQuery().mustNot(existsQuery(emailAttrName)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Aggregations

QueryBuilder (org.elasticsearch.index.query.QueryBuilder)357 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)245 Test (org.testng.annotations.Test)156 DynamicEntity (org.molgenis.data.support.DynamicEntity)137 SearchResponse (org.elasticsearch.action.search.SearchResponse)55 QueryImpl (org.molgenis.data.support.QueryImpl)36 Map (java.util.Map)32 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)27 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)27 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)27 Test (org.junit.Test)25 SearchHit (org.elasticsearch.search.SearchHit)21 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)20 IOException (java.io.IOException)19 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)19 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)17 List (java.util.List)16 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)15 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)14