Now that we have the index created, we can indexed a document into the index. The only requirement for a document to be indexed is that it should be a JSON document as Elasticsearch is schema-less and derives the storage schema based on the document structure indexed.
As shown in the following figure, the command to index a document is PUT {index-name}/{type}/{id}:
PUT datalake/contacts/101
{
"id":101,
"cell":"(478) 531-2026",
"work":”1-906-774-1226",
"email":"[email protected]"
}
Figure 24: Document Creation Query
As the document is indexed, Elasticsearch internally creates document mapping based on the data in the initial document. This mapping can be accessed as shown here:
GET datalake/_mapping/contacts
Figure 25: Retrieving Document Mapping via Query
A few observations from the preceding screenshot:
- Keyword analyzer is the default analyzer used for schema-less indexing
- Based on the input type, the type information in the schema has been derived
- Certain default validations have been put in place for text fields
These are very powerful features for a flexible indexing capability of a semi-structured or unstructured information.