java.lang.Object
org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig
All Implemented Interfaces:
Closeable, AutoCloseable, Diffable<DatafeedConfig>, SimpleDiffable<DatafeedConfig>, Writeable, Releasable, ToXContent, ToXContentObject

public class DatafeedConfig extends Object implements SimpleDiffable<DatafeedConfig>, ToXContentObject, Releasable
Datafeed configuration options. Describes where to proactively pull input data from.

If a value has not been set it will be null. Object wrappers are used around integral types and booleans so they can take null values.

  • Field Details

  • Constructor Details

  • Method Details

    • isCPSAllowed

      public static boolean isCPSAllowed(CrossProjectModeDecider crossProjectModeDecider)
      Returns whether ML cross-project search (CPS) is allowed for datafeeds in the current environment.

      Both the cluster-level serverless.cross_project.enabled setting and the ML CPS feature flag (CloudCredentialsExtension.ML_CROSS_PROJECT) must be enabled. Without this combined gate, every datafeed start on a CPS-enabled cluster — including ones targeting only local indices — would be promoted to cross-project mode, which violates the "off by default on main" contract of the ML CPS scaffolding.

    • projectRoutingRequiresCpsException

      public static ElasticsearchStatusException projectRoutingRequiresCpsException()
    • validateAggregations

      public static void validateAggregations(AggregatorFactories.Builder aggregations)
    • validateNoCrossProjectWhenCrossProjectIsDisabled

      public ElasticsearchException validateNoCrossProjectWhenCrossProjectIsDisabled(CrossProjectModeDecider crossProjectModeDecider, ElasticsearchException validationException)
    • withCrossProjectModeIfEnabled

      public static DatafeedConfig withCrossProjectModeIfEnabled(DatafeedConfig datafeed, CrossProjectModeDecider crossProjectModeDecider)
    • documentId

      public static String documentId(String datafeedId)
      The name of datafeed configuration document name from the datafeed ID.
      Parameters:
      datafeedId - The datafeed ID
      Returns:
      The ID of document the datafeed config is persisted in
    • validateNoCrossProjectWhenCrossProjectIsDisabled

      public ActionRequestValidationException validateNoCrossProjectWhenCrossProjectIsDisabled(CrossProjectModeDecider crossProjectModeDecider, ActionRequestValidationException validationException)
    • getId

      public String getId()
    • getJobId

      public String getJobId()
    • getConfigType

      public String getConfigType()
    • getQueryDelay

      public TimeValue getQueryDelay()
    • getFrequency

      public TimeValue getFrequency()
    • getIndices

      public List<String> getIndices()
    • getScrollSize

      public Integer getScrollSize()
    • minRequiredTransportVersion

      public Optional<Tuple<TransportVersion,String>> minRequiredTransportVersion()
    • getParsedQuery

      public QueryBuilder getParsedQuery(NamedXContentRegistry namedXContentRegistry)
      Get the fully parsed query from the semi-parsed stored Map<String, Object>
      Parameters:
      namedXContentRegistry - XContent registry to transform the lazily parsed query
      Returns:
      Fully parsed query
    • getQueryDeprecations

      public List<String> getQueryDeprecations(NamedXContentRegistry namedXContentRegistry)
      Calls the parser and returns any gathered deprecations
      Parameters:
      namedXContentRegistry - XContent registry to transform the lazily parsed query
      Returns:
      The deprecations from parsing the query
    • getQuery

      public Map<String,Object> getQuery()
    • getParsedAggregations

      public AggregatorFactories.Builder getParsedAggregations(NamedXContentRegistry namedXContentRegistry)
      Fully parses the semi-parsed Map<String, Object> aggregations
      Parameters:
      namedXContentRegistry - XContent registry to transform the lazily parsed aggregations
      Returns:
      The fully parsed aggregations
    • getAggDeprecations

      public List<String> getAggDeprecations(NamedXContentRegistry namedXContentRegistry)
      Calls the parser and returns any gathered deprecations
      Parameters:
      namedXContentRegistry - XContent registry to transform the lazily parsed aggregations
      Returns:
      The deprecations from parsing the aggregations
    • getAggregations

      public Map<String,Object> getAggregations()
    • getHistogramIntervalMillis

      public long getHistogramIntervalMillis(NamedXContentRegistry namedXContentRegistry)
      Returns the histogram's interval as epoch millis.
      Parameters:
      namedXContentRegistry - XContent registry to transform the lazily parsed aggregations
    • hasCompositeAgg

      public boolean hasCompositeAgg(NamedXContentRegistry namedXContentRegistry)
      Indicates if the datafeed is using composite aggs.
      Parameters:
      namedXContentRegistry - XContent registry to transform the lazily parsed aggregations
      Returns:
      If the datafeed utilizes composite aggs or not
    • hasAggregations

      public boolean hasAggregations()
      Returns:
      true when there are non-empty aggregations, false otherwise
    • aggsRewritten

      public boolean aggsRewritten()
    • getAggProvider

      public org.elasticsearch.xpack.core.ml.datafeed.AggProvider getAggProvider()
    • getScriptFields

      public List<SearchSourceBuilder.ScriptField> getScriptFields()
    • getChunkingConfig

      public ChunkingConfig getChunkingConfig()
    • getHeaders

      public Map<String,String> getHeaders()
    • setHeaders

      public DatafeedConfig setHeaders(Map<String,String> headers)
    • getDelayedDataCheckConfig

      public DelayedDataCheckConfig getDelayedDataCheckConfig()
    • getMaxEmptySearches

      public Integer getMaxEmptySearches()
    • getIndicesOptions

      public IndicesOptions getIndicesOptions()
    • getRuntimeMappings

      public Map<String,Object> getRuntimeMappings()
    • getProjectRouting

      @Nullable public String getProjectRouting()
    • getCloudInternalCredential

      @Nullable public PersistedCloudCredential getCloudInternalCredential()
    • close

      public void close()
      Releases the underlying PersistedCloudCredential and its SecureString, if present. Idempotent: safe to call more than once.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Releasable
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • toXContent

      public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
      Specified by:
      toXContent in interface ToXContent
      Throws:
      IOException
    • equals

      public boolean equals(Object other)
      The lists of indices and types are compared for equality but they are not sorted first so this test could fail simply because the indices and types lists are in different orders.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • defaultFrequency

      public TimeValue defaultFrequency(TimeValue bucketSpan, NamedXContentRegistry xContentRegistry)
      Calculates a sensible default frequency for a given bucket span.

      The default depends on the bucket span:

      • <= 2 mins -> 1 min
      • <= 20 mins -> bucket span / 2
      • <= 12 hours -> 10 mins
      • > 12 hours -> 1 hour
      If the datafeed has aggregations, the default frequency is the closest multiple of the histogram interval based on the rules above.
      Parameters:
      bucketSpan - the bucket span
      Returns:
      the default frequency