- Where the document lives
- The class of object that the document represents
- The unique identifier for the document
Actually, in Elasticsearch, our data is stored and indexed in shards, while an index is just a logical namespace that groups together one or more shards. However, this is an internal detail; our application shouldn’t care about shards at all. As far as our application is concerned, our documents live in an index. Elasticsearch takes care of the details.
We cover how to create and manage indices ourselves in Index Management,
but for now we will let Elasticsearch create the index for us. All we have to
do is choose an index name. This name must be lowercase, cannot begin with an
underscore, and cannot contain commas. Let’s use
website as our index name.
In applications, we use objects to represent things such as a user, a blog
post, a comment, or an email. Each object belongs to a class that defines
the properties or data associated with an object. Objects in the
may have a name, a gender, an age, and an email address.
In a relational database, we usually store objects of the same class in the same table, because they share the same data structure. For the same reason, in Elasticsearch we use the same type for documents that represent the same class of thing, because they share the same data structure.
Every type has its own mapping or schema definition, which defines the data structure for documents of that type, much like the columns in a database table. Documents of all types can be stored in the same index, but the mapping for the type tells Elasticsearch how the data in each document should be indexed.
We show how to specify and manage mappings in Types and Mappings, but for now we will rely on Elasticsearch to detect our document’s data structure automatically.
The ID is a string that,
when combined with the
uniquely identifies a document in Elasticsearch. When creating a new document,
you can either provide your own
_id or let Elasticsearch generate one for