Documents

As we mentioned earlier, JSON documents are first-class citizens in Elasticsearch. A document consists of multiple fields and is the basic unit of information that's stored in Elasticsearch. For example, you may have a document representing a single product, a single customer, or a single order line item.

As depicted in the preceding diagram, which shows the relationship between indexes, types, and documents, documents are contained within indexes and types.

Documents contain multiple fields. Each field in the JSON document is of a particular type. In the product catalog example that we saw earlier, these fields were sku, title, description, and price. Each field and its value can be seen as a key-value pair in the document, where key is the field name and value is the field value. The field name is similar to a column name in a relational database. The field value can be thought of as a value of the column for a given row, that is, the value of a given cell in the table.

In addition to the fields that are sent by the user in the document, Elasticsearch maintains internal metafields. These fields are as follows:

  • _id: This is the unique identifier of the document within the type, just like a primary key in a database table. It can be autogenerated or specified by the user.
  • _type: This field contains the type of the document. 
  • _index: This field contains the index name of the document.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset