Java Code Examples for org.elasticsearch.action.support.WriteRequest#RefreshPolicy

The following examples show how to use org.elasticsearch.action.support.WriteRequest#RefreshPolicy . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexAnomalyDetectorJobActionHandler.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor function.
 *
 * @param clusterService          ClusterService
 * @param client                  ES node client that executes actions on the local node
 * @param channel                 ES channel used to construct bytes / builder based outputs, and send responses
 * @param anomalyDetectionIndices anomaly detector index manager
 * @param detectorId              detector identifier
 * @param seqNo                   sequence number of last modification
 * @param primaryTerm             primary term of last modification
 * @param refreshPolicy           refresh policy
 * @param requestTimeout          request time out configuration
 */
public IndexAnomalyDetectorJobActionHandler(
    ClusterService clusterService,
    NodeClient client,
    RestChannel channel,
    AnomalyDetectionIndices anomalyDetectionIndices,
    String detectorId,
    Long seqNo,
    Long primaryTerm,
    WriteRequest.RefreshPolicy refreshPolicy,
    TimeValue requestTimeout
) {
    super(client, channel);
    this.clusterService = clusterService;
    this.anomalyDetectionIndices = anomalyDetectionIndices;
    this.detectorId = detectorId;
    this.seqNo = seqNo;
    this.primaryTerm = primaryTerm;
    this.refreshPolicy = refreshPolicy;
    this.requestTimeout = requestTimeout;
}
 
Example 2
Source File: RestAnomalyDetectorJobAction.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    if (!EnabledSetting.isADPluginEnabled()) {
        throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
    }

    String detectorId = request.param(DETECTOR_ID);

    return channel -> {
        long seqNo = request.paramAsLong(IF_SEQ_NO, SequenceNumbers.UNASSIGNED_SEQ_NO);
        long primaryTerm = request.paramAsLong(IF_PRIMARY_TERM, SequenceNumbers.UNASSIGNED_PRIMARY_TERM);
        WriteRequest.RefreshPolicy refreshPolicy = request.hasParam(REFRESH)
            ? WriteRequest.RefreshPolicy.parse(request.param(REFRESH))
            : WriteRequest.RefreshPolicy.IMMEDIATE;

        IndexAnomalyDetectorJobActionHandler handler = new IndexAnomalyDetectorJobActionHandler(
            clusterService,
            client,
            channel,
            anomalyDetectionIndices,
            detectorId,
            seqNo,
            primaryTerm,
            refreshPolicy,
            requestTimeout
        );

        String rawPath = request.rawPath();

        if (rawPath.endsWith(START_JOB)) {
            handler.startAnomalyDetectorJob();
        } else if (rawPath.endsWith(STOP_JOB)) {
            handler.stopAnomalyDetectorJob(detectorId);
        }
    };
}
 
Example 3
Source File: RestIndexAnomalyDetectorAction.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    if (!EnabledSetting.isADPluginEnabled()) {
        throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
    }

    String detectorId = request.param(DETECTOR_ID, AnomalyDetector.NO_ID);
    logger.info("AnomalyDetector {} action for detectorId {}", request.method(), detectorId);

    XContentParser parser = request.contentParser();
    ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
    // TODO: check detection interval < modelTTL
    AnomalyDetector detector = AnomalyDetector.parse(parser, detectorId, null, detectionInterval, detectionWindowDelay);

    long seqNo = request.paramAsLong(IF_SEQ_NO, SequenceNumbers.UNASSIGNED_SEQ_NO);
    long primaryTerm = request.paramAsLong(IF_PRIMARY_TERM, SequenceNumbers.UNASSIGNED_PRIMARY_TERM);
    WriteRequest.RefreshPolicy refreshPolicy = request.hasParam(REFRESH)
        ? WriteRequest.RefreshPolicy.parse(request.param(REFRESH))
        : WriteRequest.RefreshPolicy.IMMEDIATE;

    return channel -> new IndexAnomalyDetectorActionHandler(
        settings,
        clusterService,
        client,
        channel,
        anomalyDetectionIndices,
        detectorId,
        seqNo,
        primaryTerm,
        refreshPolicy,
        detector,
        requestTimeout,
        maxAnomalyDetectors,
        maxAnomalyFeatures
    ).start();
}
 
Example 4
Source File: IndexAnomalyDetectorActionHandler.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor function.
 *
 * @param settings                ES settings
 * @param clusterService          ClusterService
 * @param client                  ES node client that executes actions on the local node
 * @param channel                 ES channel used to construct bytes / builder based outputs, and send responses
 * @param anomalyDetectionIndices anomaly detector index manager
 * @param detectorId              detector identifier
 * @param seqNo                   sequence number of last modification
 * @param primaryTerm             primary term of last modification
 * @param refreshPolicy           refresh policy
 * @param anomalyDetector         anomaly detector instance
 * @param requestTimeout          request time out configuration
 */
public IndexAnomalyDetectorActionHandler(
    Settings settings,
    ClusterService clusterService,
    NodeClient client,
    RestChannel channel,
    AnomalyDetectionIndices anomalyDetectionIndices,
    String detectorId,
    Long seqNo,
    Long primaryTerm,
    WriteRequest.RefreshPolicy refreshPolicy,
    AnomalyDetector anomalyDetector,
    TimeValue requestTimeout,
    Integer maxAnomalyDetectors,
    Integer maxAnomalyFeatures
) {
    super(client, channel);
    this.clusterService = clusterService;
    this.anomalyDetectionIndices = anomalyDetectionIndices;
    this.detectorId = detectorId;
    this.seqNo = seqNo;
    this.primaryTerm = primaryTerm;
    this.refreshPolicy = refreshPolicy;
    this.anomalyDetector = anomalyDetector;
    this.requestTimeout = requestTimeout;
    this.maxAnomalyDetectors = maxAnomalyDetectors;
    this.maxAnomalyFeatures = maxAnomalyFeatures;
}
 
Example 5
Source File: ElasticSearchRepository.java    From elastic-crud with Apache License 2.0 4 votes vote down vote up
@Override
public void refreshPolicy(final WriteRequest.RefreshPolicy refresh) {
  policy.set(refresh);
}
 
Example 6
Source File: ElasticsearchIndexer.java    From datashare with GNU Affero General Public License v3.0 4 votes vote down vote up
public ElasticsearchIndexer withRefresh(WriteRequest.RefreshPolicy refresh) {
    esCfg.withRefresh(refresh);
    return this;
}
 
Example 7
Source File: ElasticsearchConfiguration.java    From datashare with GNU Affero General Public License v3.0 4 votes vote down vote up
ElasticsearchConfiguration withRefresh(WriteRequest.RefreshPolicy refreshPolicy) {
    this.refreshPolicy = refreshPolicy;
    return this;
}
 
Example 8
Source File: ElasticsearchSpewer.java    From datashare with GNU Affero General Public License v3.0 4 votes vote down vote up
public ElasticsearchSpewer withRefresh(WriteRequest.RefreshPolicy refreshPolicy) {
    this.esCfg.withRefresh(refreshPolicy);
    return this;
}
 
Example 9
Source File: ElasticsearchUpdateDao.java    From metron with Apache License 2.0 4 votes vote down vote up
public ElasticsearchUpdateDao withRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy) {
  documentWriter.withRefreshPolicy(refreshPolicy);
  return this;
}
 
Example 10
Source File: ElasticsearchDao.java    From metron with Apache License 2.0 4 votes vote down vote up
public ElasticsearchDao withRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy) {
  this.refreshPolicy = refreshPolicy;
  return this;
}
 
Example 11
Source File: ElasticsearchBulkDocumentWriter.java    From metron with Apache License 2.0 4 votes vote down vote up
public ElasticsearchBulkDocumentWriter<D> withRefreshPolicy(WriteRequest.RefreshPolicy refreshPolicy) {
    this.refreshPolicy = refreshPolicy;
    return this;
}
 
Example 12
Source File: DatabaseRepository.java    From elastic-crud with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the index refresh setting.
 *
 * @param refresh refresh policy
 */
void refreshPolicy(WriteRequest.RefreshPolicy refresh);