Types

In our example of a product catalog, the document that was indexed was of the product type. Each document stored in the product type represents one product. Since the same index cannot have other types, such as customers, orders, and order line items, and more, types help in logically grouping or organizing the same kind of documents within an index. 

Typically, documents with mostly common sets of fields are grouped under one type. Elasticsearch is schemaless, allowing you to store any JSON document with any set of fields into a type. In practice, we should avoid mixing completely different entities, such as customers and products, into a single type. It makes sense to store them in separate types within separate indexes. 

The following code is for the index for customers:

PUT /customers/_doc/1
{
"firstName": "John",
"lastName": "Smith",
"contact": {
"mobile": "212-xxx-yyyy"
},
...
}

The following code is for the index for products:

PUT /products/_doc/1
{
"title": "Apple iPhone Xs (Gold, 4GB RAM, 64GB Storage, 12 MP Dual Camera, 458 PPI Display)",
"price": 999.99,
...
}

As you can see, different types of documents are better handled in different indexes since they may have different sets of fields/attributes.

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

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