Package org.elasticsearch.index.query

Examples of org.elasticsearch.index.query.QueryBuilder


    }
    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(appid).setQuery(qb);

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

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

    QueryBuilder builder = nestedQuery("car", boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")));

    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
    List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);

    assertThat(persons.size(), is(1));
View Full Code Here

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

    QueryBuilder builder = nestedQuery("books", boolQuery().must(termQuery("books.name", "java")));

    SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
    List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);

    assertThat(persons.size(), is(1));
View Full Code Here

    elasticsearchTemplate.refresh(ParentEntity.class, true);
    elasticsearchTemplate.refresh(ChildEntity.class, true);

    // find all parents that have the first child
    QueryBuilder query = hasChildQuery(ParentEntity.CHILD_TYPE, QueryBuilders.termQuery("name", child1name.toLowerCase()));
    List<ParentEntity> parents = elasticsearchTemplate.queryForList(new NativeSearchQuery(query), ParentEntity.class);

    // we're expecting only the first parent as result
    assertThat("parents", parents, contains(hasProperty("id", is(parent1.getId()))));
  }
View Full Code Here

    elasticsearchTemplate.refresh(ParentEntity.class, true);
    elasticsearchTemplate.refresh(ChildEntity.class, true);

    // find all parents that have the first child using topChildren Query
    QueryBuilder query = topChildrenQuery(ParentEntity.CHILD_TYPE, QueryBuilders.termQuery("name", child1name.toLowerCase()));
    List<ParentEntity> parents = elasticsearchTemplate.queryForList(new NativeSearchQuery(query), ParentEntity.class);

    // we're expecting only the first parent as result
    assertThat("parents", parents, contains(hasProperty("id", is(parent1.getId()))));
  }
View Full Code Here

    List<QueryBuilder> mustQueryBuilderList = new LinkedList<QueryBuilder>();

    ListIterator<Criteria> chainIterator = criteria.getCriteriaChain().listIterator();
    while (chainIterator.hasNext()) {
      Criteria chainedCriteria = chainIterator.next();
      QueryBuilder queryFragmentForCriteria = createQueryFragmentForCriteria(chainedCriteria);

      if (queryFragmentForCriteria != null) {
        if (chainedCriteria.isOr()) {
          shouldQueryBuilderList.add(queryFragmentForCriteria);
        } else if (chainedCriteria.isNegating()) {
View Full Code Here

    Iterator<Criteria.CriteriaEntry> it = chainedCriteria.getQueryCriteriaEntries().iterator();
    boolean singeEntryCriteria = (chainedCriteria.getQueryCriteriaEntries().size() == 1);

    String fieldName = chainedCriteria.getField().getName();
    Assert.notNull(fieldName, "Unknown field");
    QueryBuilder query = null;

    if (singeEntryCriteria) {
      Criteria.CriteriaEntry entry = it.next();
      query = processCriteriaEntry(entry.getKey(), entry.getValue(), fieldName);
    } else {
View Full Code Here

  private QueryBuilder processCriteriaEntry(OperationKey key, Object value, String fieldName) {
    if (value == null) {
      return null;
    }
    QueryBuilder query = null;

    String searchText = StringUtils.toString(value);

    switch (key) {
      case EQUALS:
View Full Code Here

    return extractIds(response);
  }

  @Override
  public <T> Page<T> queryForPage(CriteriaQuery criteriaQuery, Class<T> clazz) {
    QueryBuilder elasticsearchQuery = new CriteriaQueryProcessor().createQueryFromCriteria(criteriaQuery.getCriteria());
    FilterBuilder elasticsearchFilter = new CriteriaFilterProcessor().createFilterFromCriteria(criteriaQuery.getCriteria());
    SearchRequestBuilder searchRequestBuilder = prepareSearch(criteriaQuery, clazz);

    if (elasticsearchQuery != null) {
      searchRequestBuilder.setQuery(elasticsearchQuery);
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.