Documents can be added to the Elasticsearch index single or in bulk.
For a larger number of documents, the bulk operation is recommended for efficient processing within Elasticsearch.
A document, which represented by a Map
of field names and values, can be added to the Elasticsearch index as follows:
The DocumentBuilder
can be used to create the documents in an easy and fluent way.
The values are added to the index based on the FieldConfiguration
.
If no FieldConfiguration
exists for a field, the data type is determined by Elasticsearch.
Multiple documents can be added as a List
to the Elasticsearch index as follows:
With bulk indexing, documents are added to the Elasticsearch index internally in chunks (default chunk size: 1000 documents).
The default indexing bulk size can be overridden in elasticsearch.properties
:
elasticsearch.service.indexing_bulk_size=1000
There are two processing modes for adding documents to the index:
This mode allows the application to handle data changes asynchronous in background. When the operation is finished the data might not have been changed down to the search index immediately. The changes might apply immediately, but in general they will apply some seconds later.
Processing data changes in the background or by keeping caches not in sync reduces the load of an application significantly.
Please see the Elasticsearch documentation for further information.
When the operation is finished, all the changes are available in the search index.
Following searches will respect the data changes immediately. Using this mode can trigger additional load and may slow down the current use case and other use cases.
Changing too much data in this mode, or using this mode in too many parallel executions might trigger very heavy additional load, causing the application to pause or block.
Documents can be easily added to the index using the DocumentBuilder
.
The following example is based on a simple FieldConfiguration
of three fields:
The field definition above results in the following Elasticsearch mapping:
Adding three documents with fields id
and title
to the index:
This leads to the following Elasticsearch index:
with by the picturesafe-search community
Code licensed Apache License 2.0 Documentation licensed CC-BY-4.0