use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project symphony by b3log.
the class ElasticsearchTestCase method QueryDslBuilder.
@Test
public void QueryDslBuilder() {
QueryBuilder qb = multiMatchQuery("test", "test1", "test2");
System.out.println(qb.toString());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project api-core by ca-cwds.
the class ElasticsearchDaoTest method buildBoolQueryFromTwoSsnBuildsQueryWithTwoSsnClauses.
@Test
public void buildBoolQueryFromTwoSsnBuildsQueryWithTwoSsnClauses() {
BoolQueryBuilder actualQuery = target.buildBoolQueryFromSearchTerms("123456789 111223333 ");
QueryBuilder expectedQuery = QueryBuilders.boolQuery().should(QueryBuilders.prefixQuery(ESColumn.SSN.getCol(), "123456789")).should(QueryBuilders.prefixQuery(ESColumn.SSN.getCol(), "111223333"));
assertThat(actualQuery.toString(), is(equalTo(expectedQuery.toString())));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project alien4cloud by alien4cloud.
the class EsDaoPaginatedSearchTest method facetedSearchPaginatedTest.
// @Ignore
@Test
public void facetedSearchPaginatedTest() throws IndexingServiceException, IOException, InterruptedException {
String searchText = "jndi";
int maxElement = getCount(QueryBuilders.matchPhrasePrefixQuery("_all", searchText).maxExpansions(10));
int size = 7;
// simple faceted pagination
assertTrue(maxElement > 0);
testFacetedSearchWellPaginated(maxElement, size, searchText, null, null);
// faceted search with filters
FilterBuilder filter = FilterBuilders.termFilter("capabilities.type", "jndi");
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
queryBuilder = QueryBuilders.filteredQuery(queryBuilder, filter);
maxElement = getCount(queryBuilder);
Map<String, String[]> filters = new HashMap<String, String[]>();
filters.put("capabilities.type", new String[] { "jndi" });
assertTrue(maxElement > 0);
testFacetedSearchWellPaginated(maxElement, size, searchText, filters, FetchContext.SUMMARY);
// test nothing found
// test when nothing found
searchText = "pacpac";
maxElement = getCount(QueryBuilders.matchPhrasePrefixQuery("_all", searchText).maxExpansions(10));
assertEquals(0, maxElement);
GetMultipleDataResult<NodeType> searchResp = dao.facetedSearch(NodeType.class, searchText, null, null, 0, size);
assertNotNull(searchResp);
assertNotNull(searchResp.getData());
assertNotNull(searchResp.getTypes());
assertEquals(0, searchResp.getData().length);
assertEquals(0, searchResp.getTypes().length);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project alien4cloud by alien4cloud.
the class EsDaoPaginatedSearchTest method simpleFindPaginatedTest.
@Test
public void simpleFindPaginatedTest() throws IOException {
int maxElement;
int size;
// test simple find all search
maxElement = getCount(QueryBuilders.matchAllQuery());
size = 11;
assertTrue(maxElement > 0);
testSimpleSearchWellPaginated(maxElement, size, null);
// test simple find with filters
FilterBuilder filter = FilterBuilders.termFilter("capabilities.type", "jndi");
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
queryBuilder = QueryBuilders.filteredQuery(queryBuilder, filter);
maxElement = getCount(queryBuilder);
size = 4;
assertTrue(maxElement > 0);
Map<String, String[]> filters = new HashMap<String, String[]>();
filters.put("capabilities.type", new String[] { "jndi" });
testSimpleSearchWellPaginated(maxElement, size, filters);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder in project alien4cloud by alien4cloud.
the class ApplicationController method search.
/**
* Search for an application.
*
* @param searchRequest The element that contains criterias for search operation.
* @return A rest response that contains a {@link FacetedSearchResult} containing applications.
*/
@ApiOperation(value = "Search for applications", notes = "Returns a search result with that contains applications matching the request. A application is returned only if the connected user has at least one application role in [ APPLICATION_MANAGER | APPLICATION_USER | APPLICATION_DEVOPS | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/search", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<FacetedSearchResult> search(@RequestBody FilteredSearchRequest searchRequest) {
FilterBuilder authorizationFilter = AuthorizationUtil.getResourceAuthorizationFilters();
// We want to sort applications by deployed/undeployed and then application name.
// Query all application ids and name.
QueryBuilder queryBuilder = alienDAO.buildSearchQuery(Application.class, searchRequest.getQuery()).setFilters(searchRequest.getFilters(), authorizationFilter).queryBuilder();
SearchResponse response = alienDAO.getClient().prepareSearch(alienDAO.getIndexForType(Application.class)).setQuery(queryBuilder).setFetchSource(new String[] { "name" }, null).setSize(Integer.MAX_VALUE).get();
// Get their status (deployed vs undeployed)
List<DeployedAppHolder> appHolders = Lists.newLinkedList();
for (SearchHit hit : response.getHits().getHits()) {
String id = hit.getId();
String appName = (String) hit.getSource().get("name");
boolean isDeployed = alienDAO.buildQuery(Deployment.class).setFilters(fromKeyValueCouples("sourceId", id, "endDate", null)).count() > 0;
appHolders.add(new DeployedAppHolder(id, appName, isDeployed));
}
// Sort to have first all deployed apps sorted by name and then all undeployed apps sorted by name.
Collections.sort(appHolders);
// Compute the list of app ids to fetch based on the query pagination parameters
List<String> appIdsToFetch = Lists.newArrayList();
int to = searchRequest.getFrom() + searchRequest.getSize();
for (int i = searchRequest.getFrom(); i < appHolders.size() && i < to; i++) {
appIdsToFetch.add(appHolders.get(i).appId);
}
List<Application> applications;
if (appIdsToFetch.size() == 0) {
applications = Lists.newArrayList();
} else {
applications = alienDAO.findByIds(Application.class, appIdsToFetch.toArray(new String[appIdsToFetch.size()]));
}
return RestResponseBuilder.<FacetedSearchResult>builder().data(new FacetedSearchResult<>(searchRequest.getFrom(), to, response.getTookInMillis(), appHolders.size(), new String[] { Application.class.getSimpleName() }, applications.toArray(new Application[applications.size()]), Maps.newHashMap())).build();
}
Aggregations