当前位置: 首页>>代码示例>>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;未经允许,请勿转载。