# Document

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/annotation/Document.java+class:androidx.appsearch.annotation.Document) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


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

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/androidx/appsearch/annotation/Document.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 `https://developer.android.com/reference/androidx/appsearch/annotation/Document.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 `https://developer.android.com/reference/androidx/appsearch/app/Features#getMaxIndexedProperties()` indexed properties in one document.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) @https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.BlobHandleProperty` Configures an `https://developer.android.com/reference/androidx/appsearch/app/AppSearchBlobHandle` field of a class as a property known to AppSearch. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.BooleanProperty` Configures a boolean member field of a class as a property known to AppSearch. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.BuilderProducer` Marks a static method or a builder class directly as a builder producer. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.BytesProperty` Configures a byte array member field of a class as a property known to AppSearch. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.CreationTimestampMillis` Marks a member field of a document as the document's creation timestamp. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.DocumentProperty` Configures a member field of a class as a property known to AppSearch. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.DoubleProperty` Configures a double-precision decimal number field of a class as a property known to AppSearch. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.EmbeddingProperty` Configures an `https://developer.android.com/reference/androidx/appsearch/app/EmbeddingVector` field of a class as a property known to AppSearch. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.Id` Marks a member field of a document as the document's unique identifier (ID). |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.LongProperty` Configures a 64-bit integer field of a class as a property known to AppSearch. |
| `public final class https://developer.android.com/reference/androidx/appsearch/annotation/Document.LongProperty.DefaultSerializer implements https://developer.android.com/reference/androidx/appsearch/app/LongSerializer<https://developer.android.com/reference/java/lang/Long.html>` |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.Namespace` Marks a member field of a document as the document's namespace. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.Score` Marks a member field of a document as the document's query-independent score. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.StringProperty` Configures a string member field of a class as a property known to AppSearch. |
| `public final class https://developer.android.com/reference/androidx/appsearch/annotation/Document.StringProperty.DefaultSerializer implements https://developer.android.com/reference/androidx/appsearch/app/StringSerializer<https://developer.android.com/reference/java/lang/String.html>` |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#CLASS) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = [https://developer.android.com/reference/java/lang/annotation/ElementType.html#FIELD, https://developer.android.com/reference/java/lang/annotation/ElementType.html#METHOD]) public annotation https://developer.android.com/reference/androidx/appsearch/annotation/Document.TtlMillis` Marks a member field of a document as the document's time-to-live (TTL). |

| ### Public methods |
|---|---|
| `abstract https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/appsearch/annotation/Document#name()()` The schema name of this type. |
| `abstract Class[]` | `https://developer.android.com/reference/androidx/appsearch/annotation/Document#parent()()` The list of `https://developer.android.com/reference/androidx/appsearch/annotation/Document` annotated classes that this type inherits from, in the context of AppSearch. |

## Public methods

### name

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public abstract String name()
```

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](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
public abstract Class[] parent()
```

The list of `https://developer.android.com/reference/androidx/appsearch/annotation/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 |
|---|---|
| `https://developer.android.com/reference/androidx/appsearch/app/AppSearchSchema.Builder#addParentType(java.lang.String)` |   |