當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryBuilders.rangeQuery方法代碼示例

本文整理匯總了Java中org.elasticsearch.index.query.QueryBuilders.rangeQuery方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryBuilders.rangeQuery方法的具體用法?Java QueryBuilders.rangeQuery怎麽用?Java QueryBuilders.rangeQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.index.query.QueryBuilders的用法示例。


在下文中一共展示了QueryBuilders.rangeQuery方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createRangeQuery

import org.elasticsearch.index.query.QueryBuilders; //導入方法依賴的package包/類
private static RangeQueryBuilder createRangeQuery(String name, Map<String, Object> rangeOperation,
    Float boost) {

  RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(name+RAW_APPEND);
  for (Map.Entry<String, Object> it : rangeOperation.entrySet()) {
    if (it.getKey().equalsIgnoreCase(LTE)) {
      rangeQueryBuilder.lte(it.getValue());
    } else if (it.getKey().equalsIgnoreCase(LT)) {
      rangeQueryBuilder.lt(it.getValue());
    } else if (it.getKey().equalsIgnoreCase(GTE)) {
      rangeQueryBuilder.gte(it.getValue());
    } else if (it.getKey().equalsIgnoreCase(GT)) {
      rangeQueryBuilder.gt(it.getValue());
    }
  }
  if (isNotNull(boost)) {
    return rangeQueryBuilder.boost(boost);
  }
  return rangeQueryBuilder;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:21,代碼來源:ElasticSearchUtil.java

示例2: randomRangeQuery

import org.elasticsearch.index.query.QueryBuilders; //導入方法依賴的package包/類
private static QueryBuilder randomRangeQuery(List<String> fields, int numDocs) {
    QueryBuilder q =  QueryBuilders.rangeQuery(randomField(fields));

    if (randomBoolean()) {
        ((RangeQueryBuilder)q).from(randomIntBetween(0, numDocs / 2 - 1));
    }
    if (randomBoolean()) {
        ((RangeQueryBuilder)q).to(randomIntBetween(numDocs / 2, numDocs));
    }

    return q;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:RandomQueryGenerator.java

示例3: query

import org.elasticsearch.index.query.QueryBuilders; //導入方法依賴的package包/類
@Override
    public Object query(Person person) {
        List<Map<String, Object>> result = new ArrayList<>();
        try {
            BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
            if (person.getName() != null) {
//	            boolBuilder.must(QueryBuilders.matchQuery("name", person.getName()));
                boolBuilder.should(QueryBuilders.matchQuery("name", person.getName()));
            }
            if (person.getIntroduce() != null) {
//	            boolBuilder.must(QueryBuilders.matchQuery("introduce", person.getIntroduce()));
                boolBuilder.should(QueryBuilders.matchQuery("introduce", person.getIntroduce()));
            }

            //大於age,小於age+10
            if (person.getAge() > 0) {
                RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("age");
                rangeQuery.from(person.getAge());
                rangeQuery.to(person.getAge() + 10);
                boolBuilder.filter(rangeQuery);
            }
            SearchRequestBuilder builder = transportClient.prepareSearch(index)
                    .setTypes(type)
                    .setSearchType(SearchType.QUERY_THEN_FETCH)
                    .setQuery(boolBuilder)
                    .setFrom(0)
                    .setSize(10);
            log.info(String.valueOf(builder));
            SearchResponse response = builder.get();
            response.getHits().forEach((s) -> result.add(s.getSource()));
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage(), e);
        }
        return result;
    }
 
開發者ID:jeikerxiao,項目名稱:SpringBootStudy,代碼行數:37,代碼來源:PersonDaoImpl.java


注:本文中的org.elasticsearch.index.query.QueryBuilders.rangeQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。