@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = ElementType.TYPE)
annotation Document


Marks a class as an entity known to AppSearch containing a data record.

Each field annotated with one of the Property annotations will become an AppSearch searchable property. Fields annotated with other annotations included here (like @Id) will have the special behaviour described in that annotation. All other members (those which do not have any of these annotations) will be ignored by AppSearch and will not be persisted or set.

Each AppSearch annotated field must meet at least one the following conditions:

  1. There must be a getter named get in the class (with package-private visibility or greater), or
  2. The field itself must have package-private visibility or greater.

The field must also meet at least one of the following conditions:

  1. There must be a setter named set<FieldName>(arg) in the class (with package-private visibility or greater), or
  2. There must be a setter named fieldname(arg) in the class (with package-private visibility or greater), or
  3. The field itself must be mutable (non-final) and have package-private visibility or greater, or
  4. There must be a constructor that accepts all fields not meeting condition 1. and 2. as parameters. That constructor must have package-private visibility or greater. It may also accept fields that do meet conditions 1 and 2, in which case the constructor will be used to populate those fields instead of methods 1 and 2.

Fields may be named according to any of the following conventions:

  • exampleName
  • mExampleName
  • _exampleName
  • exampleName_

In all of the above cases, the default property name will be "exampleName", the allowed getters are getExampleName() or exampleName(), the allowed setters are setExampleName(arg) or exampleName(arg), and the expected constructor parameter for the field is "exampleName".

The class must also have exactly one member annotated with @Id.

Properties contain the document's data. They may be indexed or non-indexed (the default). Only indexed properties can be searched for in queries. There is a limit of getMaxIndexedProperties indexed properties in one document.

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.BooleanProperty

Configures a boolean member field of a class as a property known to AppSearch.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.METHOD, ElementType.TYPE])
annotation Document.BuilderProducer

Marks a static method or a builder class directly as a builder producer.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.BytesProperty

Configures a byte array member field of a class as a property known to AppSearch.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.CreationTimestampMillis

Marks a member field of a document as the document's creation timestamp.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.DocumentProperty

Configures a member field of a class as a property known to AppSearch.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.DoubleProperty

Configures a double-precision decimal number field of a class as a property known to AppSearch.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.EmbeddingProperty

Configures an EmbeddingVector field of a class as a property known to AppSearch.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.Id

Marks a member field of a document as the document's unique identifier (ID).

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.LongProperty

Configures a 64-bit integer field of a class as a property known to AppSearch.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.Namespace

Marks a member field of a document as the document's namespace.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.Score

Marks a member field of a document as the document's query-independent score.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.StringProperty

Configures a string member field of a class as a property known to AppSearch.

@Documented
@Retention(value = RetentionPolicy.CLASS)
@Target(value = [ElementType.FIELD, ElementType.METHOD])
annotation Document.TtlMillis

Marks a member field of a document as the document's time-to-live (TTL).

Public functions

abstract String!

The schema name of this type.

abstract Array<Class<Any!>!>!

The list of Document annotated classes that this type inherits from, in the context of AppSearch.

Public functions

name

Added in 1.1.0-alpha06
abstract fun name(): String!

The schema name of this type.

This string is the key to which the complete schema definition is associated in the AppSearch database. It can be specified to replace an existing type with a new definition.

If not specified, it will be automatically set to the simple name of the annotated class.

parent

Added in 1.1.0-alpha06
abstract fun parent(): Array<Class<Any!>!>!

The list of Document annotated classes that this type inherits from, in the context of AppSearch.

Please note that the type systems in AppSearch and Java are not necessarily equivalent. Specifically, if Foo and Bar are two classes, Bar can be a parent type of Foo in AppSearch, but the Foo class does not have to extend the Bar class in Java. The converse holds as well. However, the most common use case is to align the two type systems for single parent pattern, given that if Foo extends Bar in Java, Bar's properties will automatically be copied into Foo so that it is not necessary to redefine every property in Foo.

See also
addParentType