本文整理汇总了Java中org.elasticsearch.index.query.RangeQueryBuilder.from方法的典型用法代码示例。如果您正苦于以下问题:Java RangeQueryBuilder.from方法的具体用法?Java RangeQueryBuilder.from怎么用?Java RangeQueryBuilder.from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.index.query.RangeQueryBuilder
的用法示例。
在下文中一共展示了RangeQueryBuilder.from方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAll
import org.elasticsearch.index.query.RangeQueryBuilder; //导入方法依赖的package包/类
public Map<String, List<EborpSample>> getAll(String timeRange) {
//TODO datumrange toevoegen
SearchRequestBuilder search = client.prepareSearch(INDEX_NAME);
RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("epoch");
rangeQuery.from("now-" + timeRange);
SearchRequestBuilder srb = search.setQuery(rangeQuery);
srb.setSize(1000000);
final SearchResponse response = srb.execute().actionGet();
// final Map<String, List<Triplet<Integer, Instant, String>>> results = new HashMap<>();
// System.out.println("response.getHits().hits() = " + response.getHits().hits().length);
return Arrays.asList(response.getHits().hits()).stream()
.map(SearchHit::getSource)
.map(this::mapToEborpSample)
.collect(Collectors.groupingBy(EborpSample::getMac));
}
示例2: mergeQueryParts
import org.elasticsearch.index.query.RangeQueryBuilder; //导入方法依赖的package包/类
/**
* Provides a convenience method to merge two query parts together. Assuming that the value of
* {@link #canMergeQueryParts(QueryBuilder, QueryBuilder, ConditionType)} is {@code true}, this method will attempt
* to take the values out of the current query part and put them into the appropriate fields in the previous query part.
*
* @param previousPart The previous query part to merge into.
* @param part The current query part to merge into the previous.
* @see #canMergeQueryParts(QueryBuilder, QueryBuilder, ConditionType)
*/
void mergeQueryParts(final QueryBuilder previousPart, final QueryBuilder part) {
final RangeQueryBuilder previousRangeQuery = (RangeQueryBuilder) previousPart;
final RangeQueryBuilder currentRangeQuery = (RangeQueryBuilder) part;
// If the "from" field is filled in, we know we're greater than/greater than or equal to.
if (null == currentRangeQuery.to()) {
previousRangeQuery.from(currentRangeQuery.from());
previousRangeQuery.includeLower(currentRangeQuery.includeLower());
} else {
// Otherwise we're less than/less than or equal to.
previousRangeQuery.to(currentRangeQuery.to());
previousRangeQuery.includeUpper(currentRangeQuery.includeUpper());
}
}
示例3: query
import org.elasticsearch.index.query.RangeQueryBuilder; //导入方法依赖的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;
}
示例4: addRangeTerm
import org.elasticsearch.index.query.RangeQueryBuilder; //导入方法依赖的package包/类
@Override
public void addRangeTerm(String field, String startValue, String endValue) {
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(field);
if (!startValue.equals("*")) {
rangeQueryBuilder = rangeQueryBuilder.from(startValue);
}
if (!endValue.equals("*")) {
rangeQueryBuilder = rangeQueryBuilder.to(endValue);
}
_boolQueryBuilder = _boolQueryBuilder.should(rangeQueryBuilder);
}