Class ElasticsearchCommitter
- All Implemented Interfaces:
BatchConsumer,Committer,Configurable<ElasticsearchCommitterConfig>,AutoCloseable
Commits documents to Elasticsearch. This committer relies on Elasticsearch REST API.
"_id" field
Elasticsearch expects a field named "_id" that uniquely identifies each documents. You can provide that field yourself in documents you submit. If you do not specify an "_id" field, this committer will create one for you, using the document reference as the identifier value.
"content" field
By default the "body" of a document is read as an input stream
and stored in a "content" field. You can change that target field name
with ElasticsearchCommitterConfig.setTargetContentField(String).
If you set the target content field to null, it will
effectively skip storing the content stream.
Dots (.) in field names
Your Elasticsearch installation may consider dots in field names
to be representing "objects", which may not always be what you want.
If having dots is causing you issues, make sure not to submit fields
with dots, or use
ElasticsearchCommitterConfig.setDotReplacement(String) to replace
dots with a character of your choice (e.g., underscore).
If your dot represents a nested object, keep reading.
JSON Objects
It is possible to provide a regular expression
that will identify one or more fields containing a JSON object rather
than a regular string
(ElasticsearchCommitterConfig.setJsonFieldsPattern(String)).
For example, this is a useful way to store nested objects. While very
flexible, it can be challenging to come up with the JSON structure. You may
want to consider custom code.
For this to work properly, make sure you define your Elasticsearch
field mappings on your index beforehand.
Elasticsearch ID limitations:
As of this writing, Elasticsearch 5 or higher have a 512 bytes
limitation on its "_id" field.
By default, an error (from Elasticsearch) will result from trying to submit
documents with an invalid ID. You can get around this by
setting ElasticsearchCommitterConfig.setFixBadIds(boolean) to
true. It will truncate references that are too long and
append a hash code to it
representing the truncated part. This approach is not 100%
collision-free (uniqueness), but it should safely cover the vast
majority of cases.
Type Name
As of Elasticsearch 7.0, the index type has been deprecated.
If you are using Elasticsearch 7.0 or higher, do not configure the
typeName. Doing so may cause errors.
The typeName is available only for backward compatibility
for those using this Committer with older versions of Elasticsearch.
Authentication
Basic authentication is supported for password-protected clusters.
Alternatively, API Key authentication can be used by providing the
encoded API key value via
ElasticsearchCommitterConfig.setApiKey(String).
When an API key is set, it takes precedence over basic credentials.
The API key value should be the Base64-encoded string as provided
by Elasticsearch (i.e., the value sent in the
Authorization: ApiKey ... header).
Timeouts
You can specify timeout values for when this committer sends documents to Elasticsearch.
- Author:
- Pascal Essiembre
-
Field Summary
FieldsFields inherited from interface com.norconex.commons.lang.config.Configurable
PROPERTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanprotected voidSubclasses can perform additional closing logic by overriding this method.protected voidCommits the supplied batch.protected org.elasticsearch.client.RestClientprotected org.elasticsearch.client.sniff.SniffercreateSniffer(org.elasticsearch.client.RestClient client) booleaninthashCode()protected voidSubclasses can perform additional initialization by overriding this method.toString()Methods inherited from class com.norconex.committer.core.batch.AbstractBatchCommitter
consume, doClean, doClose, doDelete, doInit, doUpsert, getInitializedQueueMethods inherited from class com.norconex.committer.core.AbstractCommitter
accept, applyFieldMappings, clean, close, delete, fireDebug, fireDebug, fireError, fireError, fireInfo, fireInfo, getCommitterContext, init, upsert
-
Field Details
-
ELASTICSEARCH_ID_FIELD
- See Also:
-
-
Constructor Details
-
ElasticsearchCommitter
public ElasticsearchCommitter()
-
-
Method Details
-
initBatchCommitter
Description copied from class:AbstractBatchCommitterSubclasses can perform additional initialization by overriding this method. Default implementation does nothing. The committer context and committer queue will be already initialized when invokingAbstractCommitter.getCommitterContext()andAbstractBatchCommitter.getInitializedQueue(), respectively.- Overrides:
initBatchCommitterin classAbstractBatchCommitter<ElasticsearchCommitterConfig>- Throws:
CommitterException- error initializing
-
commitBatch
Description copied from class:AbstractBatchCommitterCommits the supplied batch.- Specified by:
commitBatchin classAbstractBatchCommitter<ElasticsearchCommitterConfig>- Parameters:
it- the batch to commit- Throws:
CommitterException- could not commit the batch
-
closeBatchCommitter
Description copied from class:AbstractBatchCommitterSubclasses can perform additional closing logic by overriding this method. Default implementation does nothing.- Overrides:
closeBatchCommitterin classAbstractBatchCommitter<ElasticsearchCommitterConfig>- Throws:
CommitterException- error closing committer
-
createRestClient
protected org.elasticsearch.client.RestClient createRestClient() -
createSniffer
protected org.elasticsearch.client.sniff.Sniffer createSniffer(org.elasticsearch.client.RestClient client) -
equals
- Overrides:
equalsin classAbstractBatchCommitter<ElasticsearchCommitterConfig>
-
canEqual
- Overrides:
canEqualin classAbstractBatchCommitter<ElasticsearchCommitterConfig>
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractBatchCommitter<ElasticsearchCommitterConfig>
-
toString
- Overrides:
toStringin classAbstractBatchCommitter<ElasticsearchCommitterConfig>
-
getConfiguration
-