Package org.elasticsearch.index.query

Examples of org.elasticsearch.index.query.BoolQueryBuilder


  private static Pattern _logicTidyUp = Pattern.compile("qt\\[\\d+\\]", Pattern.CASE_INSENSITIVE);
 
  private BoolQueryBuilder parseLogic(String logic, BaseQueryBuilder qt[], StringBuffer qtRead[], StringBuffer query)
  {
    BoolQueryBuilder bq = QueryBuilders.boolQuery();
    int nQueryElements = qt.length;
   
    if (null == logic) { // No logic specified, just and them all together
      for (int i = 0; i < nQueryElements; ++i) {
        if (null != qt[i]) {
          bq = bq.must(qt[i]);
          if (0 != i) {
            query.append(" and ");
          }
          query.append(qtRead[i]);
        }
View Full Code Here


          }         
        }       
      } // actual term, not a node
      else { // (null != child.terms)
        // The term is a node, recurse!
        BoolQueryBuilder newLevel = QueryBuilders.boolQuery();
        if ('&' == node.op) {
          if (child.bNegated) {
            levelUp.mustNot(newLevel);
            if (!bFirstPass) {
              query.append(" and ");
View Full Code Here

    String parserres = SimpleBooleanParser.traverse(tree, false);
    String parserans = "$0: & (3 2 1 ) ";
    if (!parserans.equals(parserres)) {
      System.out.println("Fail p1"); System.out.println(parser1); System.out.println(parserres);
    }
    BoolQueryBuilder bq = QueryBuilders.boolQuery(); result.setLength(0);
    this.parseLogicRecursive(tree, bq, qtTerms.toArray(new BaseQueryBuilder[6]), qtReadTerms.toArray(new StringBuffer[6]), result);
    String parseransQ = "((etext\\ test) AND (entities.index:\"entity/type\")) and ((ftext) AND (etext\\ \\+test)) and ((ftext +test))";
    if (!parseransQ.equals(result.toString())) {
      System.out.println("Fail p1"); System.out.println(parseransQ); System.out.println(result.toString());     
    }
View Full Code Here

       
        List<SearchResult> results = new ArrayList<SearchResult>();
        Timer.Context searchTimerCtx = searchTimer.time();
       
        // todo: we'll want to change this once we decide and use a query syntax in the query string.
        BoolQueryBuilder qb = boolQuery()
                .must(termQuery(tenantId.toString(), tenant))
                .must(
                        query.contains("*") ?
                                wildcardQuery(metric_name.name(), query) :
                                termQuery(metric_name.name(), query)
View Full Code Here

     * @param searchFields the searchfields
     * @param where the where
     * @return the builder
     */
    private BoolQueryBuilder buildQueryBuilder(String search, String searchFields, String where) {
      BoolQueryBuilder qb = boolQuery();

      if(search == null || search.isEmpty()) {
        qb.must(QueryBuilders.matchAllQuery());
      } else {
        // FIXME Currently we search in all fields and ignore searchFields
        qb.must(wildcardQuery("_all", "*" + search + "*"));
      }
     
      return qb;
    }
View Full Code Here

     * @param searchFields the search fields
     * @param where the where
     * @return the long
     */
    public Long count(String search, String searchFields, String where) {
      BoolQueryBuilder qb = buildQueryBuilder(search, searchFields, where);     
      Query<?> query = ElasticSearch.query(qb, entityClass);
      query.from(0).size(0);
      SearchResults<?> result = query.fetch();
     
      return result.totalCount;
View Full Code Here

     * @param where the where
     * @return the list
     */
    @SuppressWarnings("unchecked")
    public <M extends Model> SearchResults<M> findPage(int page, String search, String searchFields, String orderBy, String order, String where) {
      BoolQueryBuilder qb = buildQueryBuilder(search, searchFields, where);     
      Query<M> query = (Query<M>) ElasticSearch.query(qb, entityClass);
      // FIXME Currently we ignore the orderBy and order fields
      query.from((page - 1) * getPageSize()).size(getPageSize());
      query.hydrate(true);
     
 
View Full Code Here

        byte[] data = json.writeValueAsBytes(article);
        node.client().prepareIndex(INDEX, TYPE, article.getSlug()).setSource(data).execute().actionGet();
    }

    public List<Article> findBySlugAndText(String slug, String text) {
        BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
        boolQuery.should(QueryBuilders.textQuery("slug", slug));
        boolQuery.should(QueryBuilders.textQuery("text", text));

        SearchResponse searchResponse = node.client().prepareSearch(INDEX).setTypes(TYPE).
            addSort("dateCreated", SortOrder.DESC).
            setFilter(getNowDateFilter()).
            setQuery(boolQuery).execute().actionGet();
View Full Code Here

    elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
    elasticsearchTemplate.bulkIndex(indexQueries);
    elasticsearchTemplate.refresh(PersonMultipleLevelNested.class, true);

    //then
    BoolQueryBuilder builder = boolQuery();
    builder.must(nestedQuery("girlFriends", termQuery("girlFriends.type", "temp")))
        .must(nestedQuery("girlFriends.cars", termQuery("girlFriends.cars.name", "Ford".toLowerCase())));

    SearchQuery searchQuery = new NativeSearchQueryBuilder()
        .withQuery(builder)
        .build();
View Full Code Here

          mustQueryBuilderList.add(queryFragmentForCriteria);
        }
      }
    }

    BoolQueryBuilder query = null;

    if (!shouldQueryBuilderList.isEmpty() || !mustNotQueryBuilderList.isEmpty() || !mustQueryBuilderList.isEmpty()) {

      query = boolQuery();

      for (QueryBuilder qb : shouldQueryBuilderList) {
        query.should(qb);
      }
      for (QueryBuilder qb : mustNotQueryBuilderList) {
        query.mustNot(qb);
      }
      for (QueryBuilder qb : mustQueryBuilderList) {
        query.must(qb);
      }
    }

    return query;
  }
View Full Code Here

TOP

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

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.