Search in sources :

Example 96 with QueryBuilder

use of org.graylog.shaded.elasticsearch7.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)

Example 97 with QueryBuilder

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

the class QueryGeneratorTest method generateMultipleQueryRule.

@Test
public void generateMultipleQueryRule() {
    // query: a or (b and c)
    Boolean booleanValue = Boolean.TRUE;
    String stringValue = "str";
    Integer intValue = 1;
    Query<Entity> q = new QueryImpl<>().eq(boolAttrName, booleanValue).or().nest().eq(stringAttrName, stringValue).and().eq(intAttrName, intValue).unnest();
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder booleanQuery = constantScoreQuery(termQuery(boolAttrName, booleanValue));
    QueryBuilder stringQuery = constantScoreQuery(termQuery(stringAttrName + '.' + FIELD_NOT_ANALYZED, stringValue));
    QueryBuilder intQuery = constantScoreQuery(termQuery(intAttrName, intValue));
    BoolQueryBuilder stringIntQuery = boolQuery().must(stringQuery).must(intQuery);
    QueryBuilder expectedQuery = boolQuery().should(booleanQuery).should(stringIntQuery).minimumShouldMatch(1);
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Example 98 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleSearchOneFieldDateTime.

@Test
public void generateOneQueryRuleSearchOneFieldDateTime() throws ParseException {
    String value = "2015-05-22T06:12:13Z";
    Query<Entity> q = new QueryImpl<>().search(dateTimeAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = matchQuery(dateTimeAttrName, value);
    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 99 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsEnumNull.

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

Example 100 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleGreaterEqualDateTime.

@Test
public void generateOneQueryRuleGreaterEqualDateTime() throws ParseException {
    Instant value = Instant.parse("2015-05-22T06:12:13Z");
    Query<Entity> q = new QueryImpl<>().ge(dateTimeAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(rangeQuery(dateTimeAttrName).gte(DataConverter.toString(value)));
    assertQueryBuilderEquals(query, expectedQuery);
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) Instant(java.time.Instant) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Test(org.testng.annotations.Test)

Aggregations

QueryBuilder (org.elasticsearch.index.query.QueryBuilder)371 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)58 QueryImpl (org.molgenis.data.support.QueryImpl)36 Map (java.util.Map)32 ArrayList (java.util.ArrayList)30 Test (org.junit.Test)30 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)29 HashMap (java.util.HashMap)27 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)27 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)27 IOException (java.io.IOException)23 SearchHit (org.elasticsearch.search.SearchHit)22 AbstractQueryBuilder (org.elasticsearch.index.query.AbstractQueryBuilder)19 TermQueryBuilder (org.elasticsearch.index.query.TermQueryBuilder)19 List (java.util.List)17 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)17 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)15