public class Neo4jCommitter extends AbstractMappedCommitter
Commit documents to a Neo4j graph database.
AbstractMappedCommitter.setTargetReferenceField(String)
.
AbstractMappedCommitter.setTargetContentField(String)
.
For databases requiring authentication, the password
can
optionally be encrypted using EncryptionUtil
(or command-line
"encrypt.bat" or "encrypt.sh"). In order for the password to be decrypted
properly, you need to specify the encryption key used to encrypt it. The key
can be stored in a few supported locations and a combination of
passwordKey
and passwordKeySource
must be specified
to properly locate the key. The supported sources are:
passwordKeySource |
passwordKey |
---|---|
key |
The actual encryption key. |
file |
Path to a file containing the encryption key. |
environment |
Name of an environment variable containing the key. |
property |
Name of a JVM system property containing the key. |
<committer class="com.norconex.committer.neo4j.Neo4jCommitter"> <!-- Mandatory settings --> <uri> (Connection Uri like bolt://localhost:7687) </uri> <user> (The Neo4j username) </user> <password> (The Neo4j password) </password> <authentType> (Only BASIC is supported for now) </authentType> <multiValuesJoiner> (One or more characters to join multi-value fields. Default is "|".) </multiValuesJoiner> <!-- Other settings --> <nodeTopology> <!-- The structure of a node for a committed document. Possible values: ONE_NODE: Default. Creates a node with metadata and content. NO_CONTENT: Creates a node without content. SPLITTED: Creates three nodes, one main node with the ID for the committed document, one with the content (linked to the main node) and another with metadata also linked to the main node.) --> [ONE_NODE|NO_CONTENT|SPLITTED] </nodeTopology> <primaryLabel> (Primary label name used for all created nodes) </primaryLabel> <relationships> <!-- Relationships are used to create relationships between nodes. If a source or target does not exist, it will be created automatically. --> <relationship type="(type of the relationship)" direction="[NONE|INCOMING|OUTGOING|BOTH]"> <sourcePropertyKey> (a metadata field) </sourcePropertyKey> <targetPropertyKey> (a metadata field) </targetPropertyKey> </relationship> </relationships> <additionalLabels> <!-- It is possible to add labels on a new created node. To do that, specify a metadata field or many by adding sourceField elements. --> <sourceField keep="[false|true]"> (metadata field) </sourceField> </additionalLabels> <!-- Use the following if password is encrypted. --> <passwordKey> (the encryption key or a reference to it) </passwordKey> <passwordKeySource> [key|file|environment|property] </passwordKeySource> <sourceReferenceField keep="[false|true]"> (Optional name of field that contains the document reference, when the default document reference is not used. Once re-mapped, this metadata source field is deleted, unless "keep" is set totrue
.) </sourceReferenceField> <targetReferenceField> (Name of the database target field where the store a document unique identifier (sourceReferenceField). If not specified, default is "id". Typically is a tableName primary key.) </targetReferenceField> <sourceContentField keep="[false|true]"> (If you wish to use a metadata field to act as the document "content", you can specify that field here. Default does not take a metadata field but rather the document content. Once re-mapped, the metadata source field is deleted, unless "keep" is set totrue
.) </sourceContentField> <targetContentField> (Target field name for a document content/body. Default is "content".) </targetContentField> <queueDir>(optional path where to queue files)</queueDir> <queueSize>(max queue size before committing)</queueSize> <commitBatchSize> (Max number of documents to send to the database at once.) </commitBatchSize> <maxRetries>(max retries upon commit failures)</maxRetries> <maxRetryWait> (max delay in milliseconds between retries) </maxRetryWait> </committer>
The following example creates a graph of crawl in combination with HttpCollector. It will also add an addtional label taking its source from a sample "TYPE" field.
<committer class="com.norconex.committer.neo4j.Neo4jCommitter"> <uri>bolt://localhost:7687</uri> <user>neo4j</user> <password> AcwFJPHITfk6LrRp7HW7Ag6hvDZotXcvWt2WvDMcGIo= </password> <authentType>BASIC</authentType> <passwordKey>key.txt</passwordKey> <passwordKeySource>file</passwordKeySource> <multiValuesJoiner>|</multiValuesJoiner> <nodeTopology>NO_CONTENT</nodeTopology> <primaryLabel>WINEDB</primaryLabel> <relationships> <relationship type="LINKED_TO" direction="OUTGOING"> <sourcePropertyKey> collector.referenced-urls </sourcePropertyKey> <targetPropertyKey>document.reference</targetPropertyKey> </relationship> </relationships> <additionalLabels> <sourceField keep="false">TYPE</sourceField> </additionalLabels> </committer>
Modifier and Type | Class and Description |
---|---|
static class |
Neo4jCommitter.AuthType
Neo4j Authent type, only BASIC is supported for now.
|
static class |
Neo4jCommitter.TopologyType
This enumeration specify how the nodes must be built.
|
Modifier and Type | Field and Description |
---|---|
static String |
ATTRIBUTE_KEY_DIRECTION |
static String |
ATTRIBUTE_KEY_KEEP |
static String |
ATTRIBUTE_KEY_TARGET_FIND_SYNTAX |
static String |
ATTRIBUTE_KEY_TYPE |
static String |
CONFIG_KEY_MULTI_VALUES_JOINER
XML element name for multi values joiner
|
static String |
CONFIG_KEY_NODE_TOPOLOGY
XML element name for node topology
|
static String |
CONFIG_KEY_PASSWORD
XML element name for Neo4j password
|
static String |
CONFIG_KEY_PRIMARY_LABEL
XML element name for primary label
|
static String |
CONFIG_KEY_SOURCE_PROPERTY_KEY
XML element name for relationship source property key
|
static String |
CONFIG_KEY_TARGET_PROPERTY_KEY
XML element name for relationship target property key
|
static String |
CONFIG_KEY_URI
XML element name for Neo4j uri
|
static String |
CONFIG_KEY_USER
XML element name for Neo4j user
|
static String |
DEFAULT_MULTI_VALUES_JOINER
Default separator for multi-values in a Neo4j property
|
static String |
DEFAULT_NEO4J_CONTENT_FIELD
Default content property name for Neo4j nodes
|
static String |
DEFAULT_NEO4J_ID_FIELD
Default Identifier property name for Neo4j nodes
|
static String |
DEFAULT_NEO4J_PARENT_LINK
Default relationship type for relationships
|
static String |
DEFAULT_NEO4J_PRIMARY_LABEL
Default primary label name for Neo4j nodes
|
static Relationship.Direction |
DEFAULT_NEO4J_RELS_DIRECTION
Default relationship direction
|
static String |
DEFAULT_NEO4J_SOURCE_PROPERTY_KEY
Default property name for source in relationships
|
static String |
DEFAULT_NEO4J_TARGET_FIND_SYNTAX
Default property name for target in relationships
|
static String |
DEFAULT_NEO4J_TARGET_PROPERTY_KEY
Default property name for target in relationships
|
static String |
DEFAULT_SOURCE_REFERENCE_FIELD |
DEFAULT_COMMIT_BATCH_SIZE
DEFAULT_QUEUE_DIR, filesCommitting
DEFAULT_QUEUE_SIZE, queueSize
Constructor and Description |
---|
Neo4jCommitter() |
Modifier and Type | Method and Description |
---|---|
void |
addAdditionalLabel(AdditionalLabel additionalLabel)
Adds additional label.
|
void |
addRelationship(Relationship relationship) |
protected void |
close() |
void |
commit() |
protected void |
commitBatch(List<ICommitOperation> batch) |
List<AdditionalLabel> |
getAdditionalLabels()
Gets additional labels.
|
String |
getMultiValuesJoiner() |
org.neo4j.driver.v1.Driver |
getNeo4jDriver() |
String |
getPassword() |
EncryptionKey |
getPasswordKey() |
String |
getPrimaryLabel()
Returns the label used for all nodes imported into Neo4j with the committer
|
List<Relationship> |
getRelationships() |
Neo4jCommitter.TopologyType |
getTopologyType() |
String |
getUri() |
String |
getUser() |
protected void |
loadFromXml(XMLConfiguration xml) |
protected void |
saveToXML(XMLStreamWriter writer) |
void |
setAdditionalLabels(List<AdditionalLabel> additionalLabels)
Sets additional labels.
|
void |
setMultiValuesJoiner(String multiValuesJoiner) |
void |
setPassword(String password) |
void |
setPasswordKey(EncryptionKey passwordKey) |
void |
setPrimaryLabel(String primaryLabel)
Sets the label used for all nodes imported into Neo4j with the committer
|
void |
setRelationships(List<Relationship> relationships) |
void |
setTopologyType(Neo4jCommitter.TopologyType typology) |
void |
setUri(String uri) |
void |
setUser(String user) |
equals, getSourceContentField, getSourceReferenceField, getTargetContentField, getTargetReferenceField, hashCode, isKeepSourceContentField, isKeepSourceReferenceField, loadFromXML, prepareCommitAddition, saveToXML, setKeepSourceContentField, setKeepSourceReferenceField, setSourceContentField, setSourceReferenceField, setTargetContentField, setTargetReferenceField, toString
commitAddition, commitComplete, commitDeletion, getCommitBatchSize, getMaxRetries, getMaxRetryWait, setCommitBatchSize, setMaxRetries, setMaxRetryWait
getInitialQueueDocCount, getQueueDir, prepareCommitDeletion, queueAddition, queueRemoval, setQueueDir
add, getQueueSize, remove, setQueueSize
public static final String CONFIG_KEY_MULTI_VALUES_JOINER
public static final String CONFIG_KEY_PRIMARY_LABEL
public static final String CONFIG_KEY_NODE_TOPOLOGY
public static final String CONFIG_KEY_URI
public static final String CONFIG_KEY_PASSWORD
public static final String CONFIG_KEY_USER
public static final String CONFIG_KEY_TARGET_PROPERTY_KEY
public static final String CONFIG_KEY_SOURCE_PROPERTY_KEY
public static final String ATTRIBUTE_KEY_DIRECTION
public static final String ATTRIBUTE_KEY_TYPE
public static final String ATTRIBUTE_KEY_KEEP
public static final String ATTRIBUTE_KEY_TARGET_FIND_SYNTAX
public static final String DEFAULT_NEO4J_ID_FIELD
public static final String DEFAULT_NEO4J_CONTENT_FIELD
public static final String DEFAULT_NEO4J_PARENT_LINK
public static final String DEFAULT_NEO4J_PRIMARY_LABEL
public static final String DEFAULT_NEO4J_TARGET_FIND_SYNTAX
public static final Relationship.Direction DEFAULT_NEO4J_RELS_DIRECTION
public static final String DEFAULT_MULTI_VALUES_JOINER
public static final String DEFAULT_NEO4J_SOURCE_PROPERTY_KEY
public static final String DEFAULT_NEO4J_TARGET_PROPERTY_KEY
public static final String DEFAULT_SOURCE_REFERENCE_FIELD
public String getPrimaryLabel()
public void setPrimaryLabel(String primaryLabel)
primaryLabel
- primary labelpublic org.neo4j.driver.v1.Driver getNeo4jDriver()
public String getUser()
public void setUser(String user)
public String getPassword()
public void setPassword(String password)
public String getUri()
public void setUri(String uri)
public Neo4jCommitter.TopologyType getTopologyType()
public void setTopologyType(Neo4jCommitter.TopologyType typology)
public EncryptionKey getPasswordKey()
public void setPasswordKey(EncryptionKey passwordKey)
public String getMultiValuesJoiner()
public void setMultiValuesJoiner(String multiValuesJoiner)
public List<AdditionalLabel> getAdditionalLabels()
public void setAdditionalLabels(List<AdditionalLabel> additionalLabels)
additionalLabels
- additional labelspublic void addAdditionalLabel(AdditionalLabel additionalLabel)
additionalLabel
- additional labelpublic List<Relationship> getRelationships()
public void setRelationships(List<Relationship> relationships)
public void addRelationship(Relationship relationship)
protected void saveToXML(XMLStreamWriter writer) throws XMLStreamException
saveToXML
in class AbstractMappedCommitter
XMLStreamException
protected void loadFromXml(XMLConfiguration xml)
loadFromXml
in class AbstractMappedCommitter
protected void commitBatch(List<ICommitOperation> batch)
commitBatch
in class AbstractBatchCommitter
public void commit()
commit
in interface ICommitter
commit
in class AbstractFileQueueCommitter
protected void close()
Copyright © 2018–2020 Norconex Inc.. All rights reserved.