Building Enterprise JavaScript Applications
上QQ阅读APP看书,第一时间看更新

Understanding indices, types, documents, and versions

In Elasticsearch, every document is uniquely identified by four attributes: its index, type, ID, and version.

Related documents should be stored under the same index. Although not equivalent, an index is analogous to a database in a relational database. For example, all documents used in our user directory API may be stored in the directory index, or since our platform is called Hobnob, we may also name our index hobnob.

Documents stored within an index must belong to a certain type. For our user directory API, you may have documents that belong to the person and company types. Although not equivalent, type is analogous to a table in a relational database.

Each document must also have an ID and version. Whenever a document is modified in any way, its version increments by a certain amount (usually 1).

Elasticsearch does not store older versions of the document. The version counter is there to allow us to perform concurrent updates and optimistic locking (more on these techniques later).