Class CloudSearchCommitter
- All Implemented Interfaces:
IBatchConsumer,ICommitter,IXMLConfigurable,AutoCloseable
Commits documents to Amazon CloudSearch.
Authentication:
An access key and security key are required to connect to and interact with
CloudSearch. For enhanced security, it is best to use one of the methods
described in DefaultAWSCredentialsProviderChain for setting them
(environment variables, system properties, profile file, etc).
Do not explicitly set "accessKey" and "secretKey" on this class if you
want to rely on safer methods.
CloudSearch ID limitations:
As of this writing, CloudSearch has a 128 characters length limitation
on its "id" field. In addition, certain characters are not allowed.
By default, an error will result from trying to submit
documents with an invalid ID. You can get around this by
setting setFixBadIds(boolean) to true. It will
truncate references that are too long and append a hash code to it
to keep uniqueness. It will also convert invalid
characters to underscore. This approach is not 100%
collision-free (uniqueness), but it should safely cover the vast
majority of cases.
XML configuration usage:
<committer
class="com.norconex.committer.cloudsearch.CloudSearchCommitter">
<!-- Mandatory: -->
<serviceEndpoint>(CloudSearch service endpoint)</serviceEndpoint>
<!-- Mandatory if not configured elsewhere: -->
<accessKey>
(Optional CloudSearch access key. Will be taken from environment
when blank.)
</accessKey>
<secretKey>
(Optional CloudSearch secret key. Will be taken from environment
when blank.)
</secretKey>
<!-- Optional settings: -->
<fixBadIds>
[false|true](Forces references to fit into a CloudSearch id field.)
</fixBadIds>
<signingRegion>(CloudSearch signing region)</signingRegion>
<proxySettings/>
<sourceIdField>
(Optional document field name containing the value that will be stored
in CloudSearch "id" field. Default is the document reference.)
</sourceIdField>
<targetContentField>
(Optional CloudSearch field name to store the document
content/body. Default is "content".)
</targetContentField>
</committer>
XML configuration entries expecting millisecond durations
can be provided in human-readable format (English only), as per
DurationParser (e.g., "5 minutes and 30 seconds" or "5m30s").
XML usage example:
<committer
class="com.norconex.committer.cloudsearch.CloudSearchCommitter">
<serviceEndpoint>
search-example-xyz.some-region.cloudsearch.amazonaws.com
</serviceEndpoint>
</committer>
The above example uses the minimum required settings (relying on environment variables for AWS keys).
- Author:
- Pascal Essiembre
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new CloudSearch committer with no configuration.CloudSearchCommitter(String serviceEndpoint) Creates a new CloudSearch committer with the given service endpoint.CloudSearchCommitter(String serviceEndpoint, String signingRegion) Creates a new CloudSearch committer with the given service endpoint and signing region. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidbooleanGets the CloudSearch access key.Gets the proxy settings.Gets the CloudSearch secret key.Gets AWS service endpoint.Gets the AWS signing region.Gets the document field name containing the value to be stored in CloudSearch "id" field.Gets the name of the CloudSearch field where content will be stored.inthashCode()protected voidbooleanGets whether to fix IDs that are too long for CloudSearch ID limitation (128 characters max).protected voidprotected voidvoidsetAccessKey(String accessKey) Sets the CloudSearch access key.voidsetFixBadIds(boolean fixBadIds) Sets whether to fix IDs that are too long for CloudSearch ID limitation (128 characters max).voidsetProxySettings(ProxySettings proxy) Sets the proxy settings.voidsetSecretKey(String secretKey) Sets the CloudSearch secret key.voidsetServiceEndpoint(String serviceEndpoint) Sets AWS service endpoint.voidsetSigningRegion(String signingRegion) Gets the AWS signing region.voidsetSourceIdField(String sourceIdField) Sets the document field name containing the value to be stored in CloudSearch "id" field.voidsetTargetContentField(String targetContentField) Sets the name of the CloudSearch field where content will be stored.toString()Methods inherited from class com.norconex.committer.core3.batch.AbstractBatchCommitter
consume, doClean, doClose, doDelete, doInit, doUpsert, getCommitterQueue, loadCommitterFromXML, saveCommitterToXML, setCommitterQueueMethods inherited from class com.norconex.committer.core3.AbstractCommitter
accept, addRestriction, addRestrictions, applyFieldMappings, clean, clearFieldMappings, clearRestrictions, close, delete, fireDebug, fireDebug, fireError, fireError, fireInfo, fireInfo, getCommitterContext, getFieldMappings, getRestrictions, init, loadFromXML, removeFieldMapping, removeRestriction, removeRestriction, saveToXML, setFieldMapping, setFieldMappings, upsertMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.norconex.commons.lang.xml.IXMLConfigurable
loadFromXML, saveToXML
-
Field Details
-
FIELD_PATTERN
CouldSearch mandatory field pattern. Characters not matching the pattern will be replaced by an underscore. -
COULDSEARCH_ID_FIELD
CloudSearch mandatory ID field- See Also:
-
DEFAULT_COULDSEARCH_CONTENT_FIELD
Default CloudSearch content field- See Also:
-
-
Constructor Details
-
CloudSearchCommitter
public CloudSearchCommitter()Creates a new CloudSearch committer with no configuration. -
CloudSearchCommitter
Creates a new CloudSearch committer with the given service endpoint.- Parameters:
serviceEndpoint- CloudSearch service endpoint
-
CloudSearchCommitter
Creates a new CloudSearch committer with the given service endpoint and signing region.- Parameters:
serviceEndpoint- CloudSearch service endpointsigningRegion- AWS signing region
-
-
Method Details
-
getServiceEndpoint
Gets AWS service endpoint.- Returns:
- AWS service endpoint
-
setServiceEndpoint
Sets AWS service endpoint.- Parameters:
serviceEndpoint- AWS service endpoint
-
getSigningRegion
Gets the AWS signing region.- Returns:
- the AWS signing region
-
setSigningRegion
Gets the AWS signing region.- Parameters:
signingRegion- the AWS signing region
-
getAccessKey
Gets the CloudSearch access key. Ifnull, the access key will be obtained from the environment, as detailed inDefaultAWSCredentialsProviderChain.- Returns:
- the access key
-
setAccessKey
Sets the CloudSearch access key. Ifnull, the access key will be obtained from the environment, as detailed inDefaultAWSCredentialsProviderChain.- Parameters:
accessKey- the access key
-
getSecretKey
Gets the CloudSearch secret key. Ifnull, the secret key will be obtained from the environment, as detailed inDefaultAWSCredentialsProviderChain.- Returns:
- the secret key
-
setSecretKey
Sets the CloudSearch secret key. Ifnull, the secret key will be obtained from the environment, as detailed inDefaultAWSCredentialsProviderChain.- Parameters:
secretKey- the secret key
-
getTargetContentField
Gets the name of the CloudSearch field where content will be stored. Default is "content".- Returns:
- field name
-
setTargetContentField
Sets the name of the CloudSearch field where content will be stored. Specifying anullvalue will disable storing the content.- Parameters:
targetContentField- field name
-
getSourceIdField
Gets the document field name containing the value to be stored in CloudSearch "id" field. Default is not a field, but rather the document reference.- Returns:
- name of field containing id value
-
setSourceIdField
Sets the document field name containing the value to be stored in CloudSearch "id" field. Setnullto use the document reference instead of a field (default).- Parameters:
sourceIdField- name of field containing id value, ornull
-
isFixBadIds
public boolean isFixBadIds()Gets whether to fix IDs that are too long for CloudSearch ID limitation (128 characters max). Iftrue, long IDs will be truncated and a hash code representing the truncated part will be appended.- Returns:
trueto fix IDs that are too long
-
setFixBadIds
public void setFixBadIds(boolean fixBadIds) Sets whether to fix IDs that are too long for CloudSearch ID limitation (128 characters max). Iftrue, long IDs will be truncated and a hash code representing the truncated part will be appended.- Parameters:
fixBadIds-trueto fix IDs that are too long
-
getProxySettings
Gets the proxy settings.- Returns:
- proxy settings
-
setProxySettings
Sets the proxy settings.- Parameters:
proxy- proxy settings
-
initBatchCommitter
- Overrides:
initBatchCommitterin classAbstractBatchCommitter- Throws:
CommitterException
-
commitBatch
- Specified by:
commitBatchin classAbstractBatchCommitter- Throws:
CommitterException
-
closeBatchCommitter
- Overrides:
closeBatchCommitterin classAbstractBatchCommitter- Throws:
CommitterException
-
saveBatchCommitterToXML
- Specified by:
saveBatchCommitterToXMLin classAbstractBatchCommitter
-
loadBatchCommitterFromXML
- Specified by:
loadBatchCommitterFromXMLin classAbstractBatchCommitter
-
equals
- Overrides:
equalsin classAbstractBatchCommitter
-
hashCode
public int hashCode()- Overrides:
hashCodein classAbstractBatchCommitter
-
toString
- Overrides:
toStringin classAbstractBatchCommitter
-