# Add documents from the CLI

**This document assumes that you have installed Datashare** [**in server mode within Docker**](/datashare/server-mode/install-with-docker.md)**.**

In server [mode](/datashare/concepts/running-modes.md), it's important to understand that Datashare does not provide an interface to add documents. As there is no build-in roles and permission in Datashare's data model, we have no way to differentiate users to offer admin additional tools.

This is likely to be changed in the near future, but in the meantime, you can still add documents to Datashare using the command-line interface.

Here is a simple command to scan a directory and index its files:

```bash
docker compose exec datashare_web /entrypoint.sh \
  stage run \
  --stages SCAN,INDEX \
  --defaultProject secret-project \
  --elasticsearchAddress http://elasticsearch:9200 \
  --dataDir /home/datashare/Datashare/
```

What's happening here:

* Datashare runs the pipeline [stages](/datashare/concepts/cli-stages.md)
* We ask to process both SCAN and INDEX [stages](/datashare/concepts/cli-stages.md) at the same time
* The SCAN stage feeds a queue in memory with file to add
* The INDEX stage pulls files from the queue to add them to ElasticSearch
* We tell Datashare to use the `elasticsearch` service
* Files to add are located in `/home/datashare/Datashare/` which is a directory mounted from the host machine

Alternatively, you can do this in two separated phases, as long as you tell Datashare to store the queue in a shared resource. Here, we use the Redis:

```bash
docker compose exec datashare_web /entrypoint.sh \
  stage run \
  --stages SCAN \
  --queueType REDIS \
  --queueName "datashare:queue" \
  --redisAddress redis://redis:6379 \
  --defaultProject secret-project \
  --elasticsearchAddress http://elasticsearch:9200 \
  --dataDir /home/datashare/Datashare/
```

Once the operation is done, we can easily check the content of queue created by Datashare in Redis. In this example we only display the 20 first files in the `datashare:queue`:

```bash
docker compose exec redis redis-cli lrange datashare:queue 0 20
```

The INDEX [stage](/datashare/concepts/cli-stages.md) can now be executed in the same container:

```bash
docker compose exec datashare_web /entrypoint.sh \
  stage run \
  --stages INDEX \
  --queueType REDIS \
  --queueName "datashare:queue" \
  --redisAddress redis://redis:6379 \
  --defaultProject secret-project \
  --elasticsearchAddress http://elasticsearch:9200 \
  --dataDir /home/datashare/Datashare/
```

Once the indexing is done, Datashare will exit gracefully and your document will already be visible on Datashare.

Sometimes you will face the case where you have an existing index, and you want to index additional documents inside your working directory without processing every document again. It can be done in two steps :

* Scan the existing ElasticSearch index and gather document paths to store it inside a report queue
* Scan and index (with OCR) the documents in the directory, thanks to the previous report queue, it will skip the paths inside of it

```bash
docker compose exec datashare_web /entrypoint.sh \
  stage run \
  --stages SCANIDX \
  --queueType REDIS \
  --reportName "report:queue" \
  --redisAddress redis://redis:6379 \
  --defaultProject secret-project \
  --elasticsearchAddress http://elasticsearch:9200 \
  --dataDir /home/datashare/Datashare/
```

```bash
docker compose exec datashare_web /entrypoint.sh \
  stage run \
  --stages SCAN,INDEX \
  --ocr true \
  --queueType REDIS \
  --queueName "datashare:queue" \
  --reportName "report:queue" \
  --redisAddress redis://redis:6379 \
  --defaultProject secret-project \
  --elasticsearchAddress http://elasticsearch:9200 \
  --dataDir /home/datashare/Datashare/
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://icij.gitbook.io/datashare/server-mode/add-documents-from-the-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
