Search in sources :

Example 1 with RangeFilterBuilder

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;
}
Also used : RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder)

Example 2 with RangeFilterBuilder

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;
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder) GetMultipleJsonResult(alien4cloud.rest.deployment.model.GetMultipleJsonResult) SearchResponse(org.elasticsearch.action.search.SearchResponse) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with RangeFilterBuilder

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);
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with RangeFilterBuilder

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;
}
Also used : RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder) AndFilterBuilder(org.elasticsearch.index.query.AndFilterBuilder) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) OrFilterBuilder(org.elasticsearch.index.query.OrFilterBuilder) RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder) BoolFilterBuilder(org.elasticsearch.index.query.BoolFilterBuilder) QueryFilterBuilder(org.elasticsearch.index.query.QueryFilterBuilder) NotFilterBuilder(org.elasticsearch.index.query.NotFilterBuilder) NestedFilterBuilder(org.elasticsearch.index.query.NestedFilterBuilder) MatchAllFilterBuilder(org.elasticsearch.index.query.MatchAllFilterBuilder) TermsFilterBuilder(org.elasticsearch.index.query.TermsFilterBuilder)

Example 5 with RangeFilterBuilder

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());
    }
}
Also used : RangeFilterBuilder(org.elasticsearch.index.query.RangeFilterBuilder) TermsFilterBuilder(org.elasticsearch.index.query.TermsFilterBuilder) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) QueryFilterBuilder(org.elasticsearch.index.query.QueryFilterBuilder) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) TimeRange(org.bedework.caldav.util.TimeRange) BwIcalPropertyInfoEntry(org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry) TermFilterBuilder(org.elasticsearch.index.query.TermFilterBuilder) Collection(java.util.Collection) MultiMatchQueryBuilder(org.elasticsearch.index.query.MultiMatchQueryBuilder) MatchQueryBuilder(org.elasticsearch.index.query.MatchQueryBuilder)

Aggregations

RangeFilterBuilder (org.elasticsearch.index.query.RangeFilterBuilder)5 PaaSDeploymentStatusMonitorEvent (alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent)2 ApiOperation (io.swagger.annotations.ApiOperation)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 QueryFilterBuilder (org.elasticsearch.index.query.QueryFilterBuilder)2 TermFilterBuilder (org.elasticsearch.index.query.TermFilterBuilder)2 TermsFilterBuilder (org.elasticsearch.index.query.TermsFilterBuilder)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 GetMultipleJsonResult (alien4cloud.rest.deployment.model.GetMultipleJsonResult)1 Collection (java.util.Collection)1 TimeRange (org.bedework.caldav.util.TimeRange)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 BwIcalPropertyInfoEntry (org.bedework.calfacade.ical.BwIcalPropertyInfo.BwIcalPropertyInfoEntry)1 AndFilterBuilder (org.elasticsearch.index.query.AndFilterBuilder)1 BoolFilterBuilder (org.elasticsearch.index.query.BoolFilterBuilder)1 FilterBuilder (org.elasticsearch.index.query.FilterBuilder)1 MatchAllFilterBuilder (org.elasticsearch.index.query.MatchAllFilterBuilder)1 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)1 MultiMatchQueryBuilder (org.elasticsearch.index.query.MultiMatchQueryBuilder)1