use of org.elasticsearch.index.query.RangeFilterBuilder in project bw-calendar-engine by Bedework.
the class ESQueryFilter method range.
private RangeFilterBuilder range(final String fld, final String start, final String end) {
if ((start == null) && (end == null)) {
return null;
}
final RangeFilterBuilder rfb = FilterBuilders.rangeFilter(fld);
if (end == null) {
rfb.gte(start);
} else if (start == null) {
rfb.lt(end);
} else {
rfb.from(start);
rfb.to(end);
}
rfb.includeLower(true);
rfb.includeUpper(false);
adjustTimeLimits(start, end);
return rfb;
}
use of org.elasticsearch.index.query.RangeFilterBuilder in project alien4cloud by alien4cloud.
the class DeploymentEventsController method get.
/**
* Batch processing oriented API to retrieve deployment status events. This API is not intended for frequent requests but can retrieve lot of data.
*
* @return
*/
@ApiOperation(value = "Get deployment status events from a given date.", notes = "Batch processing oriented API to retrieve deployment status events. This API is not intended for frequent requests but can retrieve lot of data.", authorizations = { @Authorization("ADMIN"), @Authorization("APPLICATION_MANAGER") })
@RequestMapping(value = "/status", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public GetMultipleJsonResult get(@RequestBody @Valid TimedRequest timedRequest) {
RangeFilterBuilder dateFilter = FilterBuilders.rangeFilter("date").gte(timedRequest.getIntervalStart());
if (timedRequest.getIntervalEnd() != null) {
dateFilter.lt(timedRequest.getIntervalEnd());
}
SearchResponse response = monitorDao.getClient().prepareSearch(monitorDao.getIndexForType(PaaSDeploymentStatusMonitorEvent.class)).setTypes(MappingBuilder.indexTypeFromClass(PaaSDeploymentStatusMonitorEvent.class)).setQuery(QueryBuilders.constantScoreQuery(dateFilter)).setFrom(timedRequest.getFrom()).setSize(timedRequest.getSize()).get();
GetMultipleJsonResult result = new GetMultipleJsonResult();
result.setData(ResponseUtil.rawMultipleData(response));
result.setTotalResults(response.getHits().getTotalHits());
result.setQueryDuration(response.getTookInMillis());
return result;
}
use of org.elasticsearch.index.query.RangeFilterBuilder in project alien4cloud by alien4cloud.
the class DeploymentEventsController method get.
/**
* Batch processing oriented API to retrieve deployment status events. This API is not intended for frequent requests but can retrieve lot of data.
*
* @return
*/
@ApiOperation(value = "Get deployment status events from a given date.", notes = "Batch processing oriented API to retrieve deployment status events. This API is not intended for frequent requests but can retrieve lot of data.", authorizations = { @Authorization("ADMIN"), @Authorization("APPLICATION_MANAGER") })
@RequestMapping(value = "/status/scroll", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
public ScrollJsonResult get(@RequestBody @Valid ScrollTimedRequest timedRequest) {
RangeFilterBuilder dateFilter = FilterBuilders.rangeFilter("date").gte(timedRequest.getIntervalStart());
if (timedRequest.getIntervalEnd() != null) {
dateFilter.lt(timedRequest.getIntervalEnd());
}
SearchResponse response = monitorDao.getClient().prepareSearch(monitorDao.getIndexForType(PaaSDeploymentStatusMonitorEvent.class)).setTypes(MappingBuilder.indexTypeFromClass(PaaSDeploymentStatusMonitorEvent.class)).setQuery(QueryBuilders.constantScoreQuery(dateFilter)).setScroll(TimeValue.timeValueMinutes(5)).setSize(timedRequest.getSize()).get();
return convert(response);
}
use of org.elasticsearch.index.query.RangeFilterBuilder in project bw-calendar-engine by Bedework.
the class ESQueryFilter method addDateRangeFilter.
/**
* Add date range terms to filter. The actual terms depend on
* how we want recurring events returned - expanded or as master
* and overrides.
*
* <p>For expanded we just search on the actual dtstart and
* end. This will find all the entities that fall in the desired
* range</p>
*
* <p>For master + overrides we need to return any override that
* overrides an instance in the range but itself is outside the
* range. For these we search on the index start/end</p>
*
* @param filter
* @param entityType
* @param start
* @param end
* @return the filter or a filter with anded date range
* @throws CalFacadeException on error
*/
public FilterBuilder addDateRangeFilter(final FilterBuilder filter, final int entityType, final String start, final String end) throws CalFacadeException {
if ((start == null) && (end == null)) {
return filter;
}
queryFiltered = true;
final String startRef;
final String endRef;
if (entityType == IcalDefs.entityTypeAlarm) {
return and(filter, range(nextTriggerRef, start, end), null);
}
if (recurRetrieval.mode == Rmode.expanded) {
startRef = dtStartUTCRef;
endRef = dtEndUTCRef;
} else {
startRef = indexStartUTCRef;
endRef = indexEndUTCRef;
}
FilterBuilder fb = filter;
if (end != null) {
// Start of events must be before the end of the range
final RangeFilterBuilder rfb = new RangeFilterBuilder(startRef);
rfb.lt(dateTimeUTC(end));
fb = and(fb, rfb, null);
}
if (start != null) {
// End of events must be before the end of the range
final RangeFilterBuilder rfb = new RangeFilterBuilder(endRef);
rfb.gte(dateTimeUTC(start));
rfb.includeLower(false);
fb = and(fb, rfb, null);
}
adjustTimeLimits(start, end);
return fb;
}
use of org.elasticsearch.index.query.RangeFilterBuilder in project bw-calendar-engine by Bedework.
the class ESQueryFilter method makeFilter.
private FilterBuilder makeFilter(final PropertyInfoIndex pii, final String path, final Object val, final OperationType opType) throws CalFacadeException {
final BwIcalPropertyInfoEntry bwPie = BwIcalPropertyInfo.getPinfo(pii);
switch(opType) {
case compare:
if (bwPie.getAnalyzed()) {
if (val instanceof Collection) {
final String[] vals;
try {
final Collection valsC = (Collection) val;
vals = (String[]) (valsC).toArray(new String[valsC.size()]);
} catch (final Throwable t) {
throw new CalFacadeException(CalFacadeException.filterBadOperator, "Invalid query. Multi match only allowed on strings");
}
final MultiMatchQueryBuilder mmqb = new MultiMatchQueryBuilder(path, vals);
return new QueryFilterBuilder(mmqb);
}
return new QueryFilterBuilder(new MatchQueryBuilder(path, val));
}
if (val instanceof Collection) {
final TermsFilterBuilder tfb = FilterBuilders.termsFilter(path, (Collection) val);
tfb.execution("or");
return tfb;
}
return new TermFilterBuilder(path, val);
case timeRange:
final RangeFilterBuilder rfb = FilterBuilders.rangeFilter(path);
final TimeRange tr = (TimeRange) val;
if (tr.getEnd() == null) {
rfb.gte(tr.getStart().toString());
return rfb;
}
if (tr.getStart() == null) {
rfb.lt(tr.getEnd().toString());
return rfb;
}
rfb.from(tr.getStart().toString());
rfb.to(tr.getEnd().toString());
rfb.includeLower(true);
rfb.includeUpper(false);
return rfb;
case absence:
return FilterBuilders.missingFilter(path);
case presence:
return FilterBuilders.existsFilter(path);
case prefix:
return FilterBuilders.prefixFilter(path, (String) val);
default:
throw new CalFacadeException(CalFacadeException.filterBadOperator, opType.toString());
}
}
Aggregations