本文整理汇总了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;
}
示例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;
}
示例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;
}