Skip to main content

SqlCommitter

Commit documents to an SQL table.

Notes​

Commits crawled documents to a relational database table using JDBC. Supports dynamic table and field creation, field mappings, field name and value sanitization, and multi-value field joining.

Examples​

Writes documents into a PostgreSQL table, creating it on first use and sanitizing field names that SQL will not accept.

committer:
class: SqlCommitter
connectionUrl: jdbc:postgresql://localhost:5432/crawl
driverClass: org.postgresql.Driver
credentials:
username: crawler
password: changeme
tableName: documents
primaryKey: id
createTableSQL: CREATE TABLE documents (id VARCHAR(2048) NOT NULL PRIMARY KEY, content CLOB)
createFieldSQL: ALTER TABLE documents ADD {{field}} VARCHAR(8000)
fixFieldNames: true

Usage​

Full configuration skeleton, with every option and its default
class: SqlCommitter
acl:
flatPrefix: string
format: NATIVE
partial: REJECT
connectionUrl: string
createFieldSQL: string
createTableSQL: string
credentials:
password: string
passwordKey:
size: 0
source: KEY
value: string
username: string
driverClass: string
driverPath: string
fieldMappings: {}
fixFieldNames: false
fixFieldValues: false
multiValuesJoiner: string
primaryKey: string
properties:
caseInsensitiveKeys: false
queue:
class: FsQueue
batchSize: 0
commitLeftoversOnInit: false
maxPerFolder: 0
onCommitFailure:
ignoreErrors: false
maxRetries: 0
retryDelay: 0
splitBatch: OFF
restrictions:
- fieldMatcher: {}
valueMatcher: {}
tableName: string
targetContentField: string

Properties​

PropertyTypeRequiredDefault
aclAclCommitterConfigNoAclCommitterConfig
connectionUrlstringNo-
createFieldSQLstringNo-
createTableSQLstringNo-
credentialsCredentialsNoCredentials
driverClassstringNo-
driverPathstringNo-
fieldMappingsRecord<string, string>No-
fixFieldNamesbooleanNofalse
fixFieldValuesbooleanNofalse
multiValuesJoinerstringNo|
primaryKeystringNo-
propertiesRecord<string, string[]>No-
queueCommitterQueueNoFsQueue
restrictionsPropertyMatcher[]No-
tableNamestringNo-
targetContentFieldstringNocontent

Property Details​

acl​

How this committer sends the access control list (ACL) a document carries in its crawler.acl field, written by the fetchers that read a source's permissions:

  • format: JSON sends the field as it is; FLAT replaces it with plain fields (below); NATIVE writes it as the destination's own access control, for committers whose destination has one; NONE does not send it. When not set, the committer's default applies (NATIVE where available, otherwise JSON).
  • partial: what to do with a document whose permissions could only be read in part: REJECT (the default) or SEND.
  • flatPrefix: the prefix of the FLAT fields. Default is acl.

A document whose permissions cannot be vouched for is withheld: it is not sent, a version sent before is removed from the destination, and the crawler tries it again on its next run. That is the case when its ACL is partial and partial is REJECT, when its permissions could not be read at all, when the ACL is unreadable or of an unknown version, or when NATIVE cannot express it. A withheld document is never sent as readable by everyone.

With FLAT, acl.levels names the checks a person must pass, in order, and each level has an allow field and a deny field holding principals as kind:dir:id (or special:id):

acl.levels = share, file
acl.share.allow = group:ad:CORP:Sales
acl.file.allow = group:ad:CORP:Sales
acl.file.deny = group:ad:CORP:Interns
acl.owners = user:ad:CORP:pascal

A person may see the document if they match an allow value of every level and no deny value of any.

connectionUrl​

JDBC connection URL.

createFieldSQL​

The ALTER statement used to create missing table fields. Use {tableName} to represent the table name and {fieldName} to represent newly encountered field names.

createTableSQL​

The CREATE statement used to create a table if it does not already exist. If you need fields of specific data types, specify them here. Use {tableName} and {primaryKey} to represent the table name and primary key, respectively.

credentials​

Username and password to a protected database.

driverClass​

Class name of the JDBC driver to use.

driverPath​

Path to JDBC driver .jar file. Not required if already in classpath (i.e., crawler's lib folder).

fieldMappings​

Mapping of source fields to target ones (table field names).

fixFieldNames​

Attempt to prevent insertion errors due to unsupported characters in field names by converting them to underscores. Convert any first character that is not alphanumeric and any following characters that are not underscore or alphanumeric.

fixFieldValues​

Attempt to prevent insertion errors by truncating values that are larger than their defined maximum field length.

multiValuesJoiner​

Characters used to join a multi-valued field into the single value stored in its column. Default is |. Choose something that cannot appear in your values if you intend to split them apart again later.

primaryKey​

The name of the table primary key field where to store the document reference value. The document reference from the source document is used unless the source document has a field matching this name. Then the matching source field will be used to populate the primary key. If for some reason it is not possible to define a table field as the primary key, at a minimum, the target field should be "unique" and ideally "indexed".

properties​

Additional connection properties as per database vendor specifications.

queue​

Configures the committer queue used to batch documents before sending them to the target system. Adjust queue settings to tune throughput and memory usage.

restrictions​

Defines filter conditions that restrict which documents this committer processes. Documents not matching the restrictions are ignored by this committer.

tableName​

The target database table name where documents will be committed.

targetContentField​

Table field name where to store the document content. Leave blank if you do not want to store the document content. Since document content can sometimes be quite large, a CLOB field (or equivalent) is usually advised. If the source document contains a field of the same name, that field value will take precedence over the document content and the document content is ignored. Default is "content".