本文整理匯總了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;
}