Search in sources :

Example 86 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleInEnum.

@Test
public void generateOneQueryRuleInEnum() {
    String value1 = "enum0";
    String value2 = "enum1";
    Iterable<Object> values = Arrays.asList(value1, value2);
    Query<Entity> q = new QueryImpl<>().in(enumAttrName, values);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(termsQuery(enumAttrName + '.' + FIELD_NOT_ANALYZED, new Object[] { value1, value2 }));
    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 87 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleInHtml.

@Test
public void generateOneQueryRuleInHtml() {
    String value1 = "<h1>title</h1>";
    String value2 = "<h2>subtitle</h2>";
    Iterable<Object> values = Arrays.asList(value1, value2);
    Query<Entity> q = new QueryImpl<>().in(htmlAttrName, values);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(termsQuery(htmlAttrName + '.' + FIELD_NOT_ANALYZED, new Object[] { value1, value2 }));
    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 88 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleGreaterEqualInt.

@Test
public void generateOneQueryRuleGreaterEqualInt() {
    Integer value = 1;
    Query<Entity> q = new QueryImpl<>().ge(intAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(rangeQuery(intAttrName).gte(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 89 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleSearchOneFieldEnum.

@Test
public void generateOneQueryRuleSearchOneFieldEnum() {
    String value = "enum0";
    Query<Entity> q = new QueryImpl<>().search(enumAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = matchQuery(enumAttrName, 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 90 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleNotEqualsEnum.

@Test
public void generateOneQueryRuleNotEqualsEnum() {
    String value = "enum0";
    Query<Entity> q = new QueryImpl<>().not().eq(enumAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = boolQuery().mustNot(constantScoreQuery(termQuery(enumAttrName + '.' + FIELD_NOT_ANALYZED, value)));
    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)

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