Class Metadata

java.lang.Object
org.elasticsearch.script.Metadata
Direct Known Subclasses:
ReindexMetadata, UpdateByQueryMetadata, UpdateMetadata

public class Metadata extends Object
Ingest and update metadata available to write scripts. Provides a map-like interface for backwards compatibility with the ctx map. - put(String, Object) - get(String) - remove(String) - containsKey(String) - containsValue(Object) - keySet() for iteration - size() - isAvailable(String) for determining if a key is a metadata key Provides getters and setters for script usage. Validates all updates whether originating in map-like interface or setters.
  • Field Details

  • Constructor Details

    • Metadata

      protected Metadata(Map<String,Object> map, Map<String,Metadata.FieldProperty<?>> properties)
      Constructs a new Metadata object represented by the given map and properties.

      The passed-in map is used directly -- subsequent modifications to it outside the methods of this class may result in undefined behavior. Note also that mutation-like methods (e.g. setters, etc) on this class rely on the map being mutable, which is the expected use for this class.

      The properties map is used directly as well, but we verify at runtime that it must be an immutable map (i.e. constructed via a call to Map.of() (or similar) in production, or via Map.copyOf(Map)} in tests). Since it must be an immutable map, subsequent modifications are not possible.

      Parameters:
      map - the backing map for this metadata instance
      properties - the immutable map of defined properties for the type of metadata represented by this instance
  • Method Details

    • validateMetadata

      protected void validateMetadata()
      Check that all metadata map contains only valid metadata and no extraneous keys
    • getIndex

      public String getIndex()
    • setIndex

      public void setIndex(String index)
    • getId

      public String getId()
    • setId

      public void setId(String id)
    • getRouting

      public String getRouting()
    • setRouting

      public void setRouting(String routing)
    • getVersionType

      public String getVersionType()
    • setVersionType

      public void setVersionType(String versionType)
    • getVersion

      public long getVersion()
    • setVersion

      public void setVersion(long version)
    • getNow

      public ZonedDateTime getNow()
    • getOp

      public String getOp()
    • setOp

      public void setOp(String op)
    • getIfSeqNo

      public Number getIfSeqNo()
    • getIfPrimaryTerm

      public Number getIfPrimaryTerm()
    • getDynamicTemplates

      public Map<String,String> getDynamicTemplates()
    • getString

      protected String getString(String key)
      Get the String version of the value associated with key, or null
    • getNumber

      protected Number getNumber(String key)
      Get the Number associated with key, or null
      Throws:
      IllegalArgumentException - if the value is not a Number
    • isAvailable

      public boolean isAvailable(String key)
      Is this key a Metadata key? A remove(java.lang.String)d key would return false for containsKey(String) but true for this call.
    • put

      public Object put(String key, Object value)
      Create the mapping from key to value.
      Throws:
      IllegalArgumentException - if isAvailable(String) is false or the key cannot be updated to the value.
    • containsKey

      public boolean containsKey(String key)
      Does the metadata contain the key?
    • containsValue

      public boolean containsValue(Object value)
      Does the metadata contain the value.
    • get

      public Object get(String key)
      Get the value associated with
    • getOrDefault

      public Object getOrDefault(String key, Object defaultValue)
      Get the value associated with , otherwise return
    • remove

      public Object remove(String key)
      Remove the mapping associated with
      Throws:
      IllegalArgumentException - if isAvailable(String) is false or the key cannot be removed.
    • keySet

      public Set<String> keySet()
      Return the list of keys with mappings
    • size

      public int size()
      The number of metadata keys currently mapped.
    • clone

      public Metadata clone()
      Overrides:
      clone in class Object
    • getMap

      public Map<String,Object> getMap()
      Get the backing map, if modified then the guarantees of this class may not hold
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public static BiConsumer<String,String> stringSetValidator(Set<String> valid)