Search in sources :

Example 81 with QueryBuilder

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

the class SuggestionController method nodeTypeSuggest.

@ApiIgnore
@RequestMapping(value = "/nodetypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<String[]> nodeTypeSuggest(@RequestParam("text") String searchText, @RequestParam(value = "isAbstract", required = false) Boolean isAbstract) {
    if (searchText == null || searchText.trim().isEmpty()) {
        return RestResponseBuilder.<String[]>builder().data(new String[0]).build();
    }
    searchText = StringUtils.lowerCase(searchText);
    QueryBuilder queryOnText = QueryBuilders.regexpQuery("elementId", ".*?" + searchText + ".*");
    // FIXME the way of getting the highest version of a component has changed
    // QueryBuilder queryOnHighest = QueryBuilders.termQuery("highestVersion", true);
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().must(queryOnText);
    QueryBuilder query = boolQueryBuilder;
    if (isAbstract != null) {
        query = boolQueryBuilder.must(QueryBuilders.termQuery("abstract", isAbstract));
    }
    return RestResponseBuilder.<String[]>builder().data(dao.selectPath(dao.getIndexForType(NodeType.class), new String[] { MappingBuilder.indexTypeFromClass(NodeType.class) }, query, SortOrder.ASC, "elementId", 0, 10)).build();
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) NodeType(org.alien4cloud.tosca.model.types.NodeType) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiIgnore(springfox.documentation.annotations.ApiIgnore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 82 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleEqualsTextNull.

@Test
public void generateOneQueryRuleEqualsTextNull() {
    String value = null;
    Query<Entity> q = new QueryImpl<>().eq(textAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(boolQuery().mustNot(existsQuery(textAttrName)));
    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 83 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleInInt.

@Test
public void generateOneQueryRuleInInt() {
    Integer value1 = 1;
    Integer value2 = 2;
    Iterable<Object> values = Arrays.asList(value1, value2);
    Query<Entity> q = new QueryImpl<>().in(intAttrName, values);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(termsQuery(intAttrName, 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 84 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleEqualsDateTime.

@Test
public void generateOneQueryRuleEqualsDateTime() throws ParseException {
    Instant value = Instant.parse("2015-05-22T06:12:13Z");
    Query<Entity> q = new QueryImpl<>().eq(dateTimeAttrName, value);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(termQuery(dateTimeAttrName, value.toString()));
    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)

Example 85 with QueryBuilder

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

the class QueryGeneratorTest method generateOneQueryRuleInCategorical_Ids.

@Test
public void generateOneQueryRuleInCategorical_Ids() {
    Iterable<String> values = asList("id0", "id1", "id2");
    Query<Entity> q = new QueryImpl<>().in(categoricalAttrName, values);
    QueryBuilder query = queryGenerator.createQueryBuilder(q, entityType);
    QueryBuilder expectedQuery = constantScoreQuery(nestedQuery(categoricalAttrName, termsQuery(categoricalAttrName + '.' + idAttrName + '.' + FIELD_NOT_ANALYZED, new Object[] { "id0", "id1", "id2" }), ScoreMode.Avg));
    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