Exemplo n.º 1
0
 private SearchRequestBuilder criteria2builder(ElasticSearchCriteria criteria) {
   String[] indices = criteria.getIndices();
   if (indices == null || indices.length == 0)
     indices = new String[] {indexManager.getIndexName()};
   SearchRequestBuilder srb = client.prepareSearch(indices);
   srb.setTimeout(new TimeValue(10, TimeUnit.SECONDS));
   String[] types = criteria.getTypes();
   if (types != null && types.length > 0) srb.setTypes(types);
   QueryBuilder qb = criteria.getQueryBuilder();
   String query = criteria.getQuery();
   if (qb == null && StringUtils.isBlank(query))
     throw new NullPointerException("queryBuilder is null and queryString is blank");
   if (qb == null && StringUtils.isNotBlank(query)) {
     if (wildcardQueryPattern.matcher(query).matches()) {
       String[] arr = query.split(":", 2);
       qb = QueryBuilders.wildcardQuery(arr[0], arr[1]);
     } else {
       QueryStringQueryBuilder qsqb = new QueryStringQueryBuilder(query);
       qsqb.defaultOperator(Operator.AND);
       qb = qsqb;
     }
   }
   srb.setQuery(qb);
   Map<String, Boolean> sorts = criteria.getSorts();
   for (Map.Entry<String, Boolean> entry : sorts.entrySet())
     srb.addSort(entry.getKey(), entry.getValue() ? SortOrder.DESC : SortOrder.ASC);
   return srb;
 }
Exemplo n.º 2
0
 public SearchRequestBuilder prepareSearch() {
   return client.prepareSearch(new String[] {indexManager.getIndexName()});
 }