Package org.elasticsearch.index.query

Examples of org.elasticsearch.index.query.QueryBuilder


  public <P extends ParaObject> List<P> findTermInList(String appid, String type,
      String field, List<?> terms, Pager... pager) {
    if (StringUtils.isBlank(field) || terms == null) {
      return new ArrayList<P>();
    }
    QueryBuilder qb = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
        FilterBuilders.termsFilter(field, terms));
    return searchQuery(appid, type, qb, pager);
  }
View Full Code Here


  public <P extends ParaObject> List<P> findQuery(String appid, String type,
      String query, Pager... pager) {
    if (StringUtils.isBlank(query)) {
      return new ArrayList<P>();
    }
    QueryBuilder qb = QueryBuilders.queryString(query).allowLeadingWildcard(false);
    return searchQuery(appid, type, qb, pager);
  }
View Full Code Here

  public <P extends ParaObject> List<P> findWildcard(String appid, String type,
      String field, String wildcard, Pager... pager) {
    if (StringUtils.isBlank(field) || StringUtils.isBlank(wildcard)) {
      return new ArrayList<P>();
    }
    QueryBuilder qb = QueryBuilders.wildcardQuery(field, wildcard);
    return searchQuery(appid, type, qb, pager);
  }
View Full Code Here

    BoolFilterBuilder tagFilter = FilterBuilders.boolFilter();
    //assuming clean & safe tags here
    for (String tag : tags) {
      tagFilter.must(FilterBuilders.termFilter(Config._TAGS, tag));
    }
    QueryBuilder qb = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), tagFilter);
    // The filter looks like this: ("tag1" OR "tag2" OR "tag3") AND "type"
    return searchQuery(appid, type, qb, pager);
  }
View Full Code Here

      }
    }
    if (noop) {
      return new ArrayList<P>();
    } else {
      QueryBuilder qb = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), fb);
      return searchQuery(appid, type, qb, pager);
    }
  }
View Full Code Here

  public <P extends ParaObject> List<P> findSimilar(String appid, String type, String filterKey,
      String[] fields, String liketext, Pager... pager) {
    if (StringUtils.isBlank(liketext)) {
      return new ArrayList<P>();
    }
    QueryBuilder qb;
    FilterBuilder fb;

    if (fields == null || fields.length == 0) {
      qb = QueryBuilders.moreLikeThisQuery().likeText(liketext).minDocFreq(1).minTermFreq(1);
    } else {
View Full Code Here

  @Override
  public <P extends ParaObject> List<P> findTags(String appid, String keyword, Pager... pager) {
    if (StringUtils.isBlank(keyword)) {
      return new ArrayList<P>();
    }
    QueryBuilder qb = QueryBuilders.wildcardQuery("tag", keyword.concat("*"));
//    SortBuilder sb = SortBuilders.fieldSort("count").order(SortOrder.DESC);
    return searchQuery(appid, Utils.type(Tag.class), qb, pager);
  }
View Full Code Here

    }
    if (StringUtils.isBlank(query)) {
      query = "*";
    }
    // find nearby Address objects
    QueryBuilder qb1 = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
        FilterBuilders.geoDistanceFilter("latlng").point(lat, lng).
        distance(radius, DistanceUnit.KILOMETERS));

    SearchHits hits1 = searchQueryRaw(appid, Utils.type(Address.class), qb1, pager);

    if (hits1 == null) {
      return new ArrayList<P>();
    }

    // then find their parent objects
    String[] ridsarr = new String[(int) hits1.getTotalHits()];
    for (int i = 0; i < hits1.getTotalHits(); i++) {
      Object pid = hits1.getAt(i).getSource().get(Config._PARENTID);
      if (pid != null) {
        ridsarr[i] = pid.toString();
      }
    }

    QueryBuilder qb2 = QueryBuilders.filteredQuery(QueryBuilders.queryString(query),
        FilterBuilders.idsFilter(type).ids(ridsarr));
    SearchHits hits2 = searchQueryRaw(appid, type, qb2, pager);

    return searchQuery(appid, hits2);
  }
View Full Code Here

      fb = FilterBuilders.andFilter();
      for (Map.Entry<String, ?> term : terms.entrySet()) {
        ((AndFilterBuilder) fb).add(FilterBuilders.termFilter(term.getKey(), term.getValue()));
      }
    }
    QueryBuilder qb = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), fb);
    CountRequestBuilder crb = client().prepareCount(stripRouting(appid)).
        setQuery(qb).setRouting(getRouting(appid, null));

    if (type != null) {
      crb.setTypes(type);
View Full Code Here

            logger.trace("bulkDeleteRequest - objectId: {} - index: {} - type: {} - routing: {} - parent: {}", objectId, index, type,
                    routing, parent);
        }

        if (definition.getParentTypes() != null && definition.getParentTypes().contains(type)) {
            QueryBuilder builder = QueryBuilders.hasParentQuery(type, QueryBuilders.termQuery(MongoDBRiver.MONGODB_ID_FIELD, objectId));
            SearchResponse response = esClient.prepareSearch(index).setQuery(builder).setRouting(routing)
                    .addField(MongoDBRiver.MONGODB_ID_FIELD).execute().actionGet();
            for (SearchHit hit : response.getHits().getHits()) {
                getBulkProcessor(index, hit.getType()).deleteBulkRequest(hit.getId(), routing, objectId);
            }
View Full Code Here

TOP

Related Classes of org.elasticsearch.index.query.QueryBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.