Package org.elasticsearch.index.query

Examples of org.elasticsearch.index.query.QueryBuilder


        this.c = node.client();
        this.configuration = configuration;
    }

    public void move(String source, String target) {
        QueryBuilder qb = matchAllQuery();

        SearchResponse scrollResp = c.prepareSearch(source)
                .setSearchType(SearchType.SCAN)
                .setScroll(new TimeValue(10000))
                .setQuery(qb)
View Full Code Here


    boolean fqDsl = request.paramAsBoolean("fq.dsl", false);

    // build the query
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    if (q != null) {
      QueryBuilder queryBuilder;
      if (qDsl) {
        queryBuilder = QueryBuilders.wrapperQuery(q);
      } else {
        queryBuilder = QueryBuilders.queryString(q);
      }
      searchSourceBuilder.query(queryBuilder);
    }

    searchSourceBuilder.from(start);
    searchSourceBuilder.size(rows);

    // parse fl into individual fields
    // solr supports separating by comma or spaces
    if (fl != null) {
      if (!Strings.hasText(fl)) {
        searchSourceBuilder.noFields();
      } else {
        searchSourceBuilder.fields(fl.split("\\s|,"));
      }
    }

    // handle sorting
    if (sort != null) {
      String[] sorts = Strings.splitStringByCommaToArray(sort);
      for (int i = 0; i < sorts.length; i++) {
        String sortStr = sorts[i].trim();
        int delimiter = sortStr.lastIndexOf(" ");
        if (delimiter != -1) {
          String sortField = sortStr.substring(0, delimiter);
          if ("score".equals(sortField)) {
            sortField = "_score";
          }
          String reverse = sortStr.substring(delimiter + 1);
          if ("asc".equals(reverse)) {
            searchSourceBuilder.sort(sortField, SortOrder.ASC);
          } else if ("desc".equals(reverse)) {
            searchSourceBuilder.sort(sortField, SortOrder.DESC);
          }
        } else {
          searchSourceBuilder.sort(sortStr);
        }
      }
    } else {
      // default sort by descending score
      searchSourceBuilder.sort("_score", SortOrder.DESC);
    }

    // handler filters
    if (fqs != null && !fqs.isEmpty()) {
      FilterBuilder filterBuilder = null;

      // if there is more than one filter specified build
      // an and filter of query filters, otherwise just
      // build a single query filter.
      if (fqs.size() > 1) {
        AndFilterBuilder fqAnd = andFilter();
        for (String fq : fqs) {
          QueryBuilder queryBuilder = fqDsl ? QueryBuilders.wrapperQuery(fq) : QueryBuilders.queryString(fq);
          fqAnd.add(queryFilter(queryBuilder));
        }
        filterBuilder = fqAnd;
      } else {
        QueryBuilder queryBuilder = fqDsl ? QueryBuilders.wrapperQuery(fqs.get(0)) : QueryBuilders.queryString(fqs.get(0));
        filterBuilder = queryFilter(queryBuilder);
      }

      searchSourceBuilder.filter(filterBuilder);
    }
View Full Code Here

            try {
                barrier1.await();
                barrier2.await();
                for (; counter < max; counter++) {
                    Client client = client(counter);
                    QueryBuilder query = termQuery("num", counter % fieldNumLimit);
                    query = constantScoreQuery(queryFilter(query));

                    SearchResponse search = client.search(searchRequest()
                            .source(searchSource().query(query)))
                            .actionGet();
View Full Code Here

  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

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.