Tips and tricks

Moving files to a “watched” directory

When moving an existing file to the directory FSCrawler is watching, you need to explicitly touch all the files as when moved, the files are keeping their original date intact:

# single file
touch file_you_moved

# all files
find  -type f  -exec touch {} +

# all .txt files
find  -type f  -name "*.txt" -exec touch {} +

Or you need to restart from the beginning with the --restart option which will reindex everything.

Workaround for huge temporary files

FSCrawler uses a media library that currently does not clean up their temporary files. Parsing MP4 files may create very large temporary files in /tmp. The following commands could be useful e.g. as a cronjob to automatically delete those files once they are old and no longer in use. Adapt the commands as needed.

# Check all files in /tmp
find /tmp \( -name 'apache-tika-*.tmp-*' -o -name 'MediaDataBox*' \) -type f -mmin +15 ! -exec fuser -s {} \; -delete

# When using a systemd service with PrivateTMP enabled
find $(find /tmp -maxdepth 1 -type d -name 'systemd-private-*-fscrawler.service-*') \( -name 'apache-tika-*.tmp-*' -o -name 'MediaDataBox*' \) -type f -mmin +15 ! -exec fuser -s {} \; -delete

Indexing from HDFS drive

There is no specific support for HDFS in FSCrawler. But you can mount your HDFS on your machine and run FS crawler on this mount point. You can also read details about HDFS NFS Gateway.

Using docker

See Using docker.

Running FSCrawler on multiple machines

Added in version 3.0.

If you run FSCrawler on several hosts against the same Elasticsearch cluster, and those hosts crawl paths that look identical (for example both watch /data/docs), document _ids can collide.

By default, the _id is derived from the file path (see Document IDs). The same path on machine1 and machine2 therefore produces the same _id. The last writer wins and silently overwrites the other machine’s document.

Do not point several crawlers at the same physical document index unless every path (and thus every _id) is guaranteed unique across machines.

Alternatives

  • Different fs.url layouts that never collide in the hashed path (for example mount points that include the hostname) can share one index, but that is brittle and hard to reason about.

  • fs.filename_as_id: true does not fix multi-machine collisions: identical filenames still share the same _id.

See also