Skip to content

Commit

Permalink
Merge pull request #8404 from cfpb/index-script
Browse files Browse the repository at this point in the history
Split out index operations into own script
  • Loading branch information
wpears committed May 10, 2024
2 parents e76662d + 3cfd943 commit 1a60fb8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 7 additions & 6 deletions docs/page-search.md
Expand Up @@ -133,12 +133,7 @@ With the `Document` class created for your model in a `documents.py` module with
./cfgov/manage.py opensearch document --force --indices [INDEX] --refresh --parallel index
```

The index for that app's models can also be rebuilt at any time:

```shell
./cfgov/manage.py opensearch index --force rebuild [INDEX]
./cfgov/manage.py opensearch document --force --indices [INDEX] --refresh --parallel index
```
The above commands can also be run to rebuild the index for an app's models at any time.

Finally, the indexes for all apps can be rebuilt using:

Expand All @@ -147,6 +142,12 @@ Finally, the indexes for all apps can be rebuilt using:
./cfgov/manage.py opensearch document --force --refresh --parallel index
```

Conveniently, we have a shell script that invokes the above two commands to rebuild all indexes:

```shell
./index.sh
```

## Searching

The document class [provides a `search()` class method](https://django-opensearch-dsl.readthedocs.io/en/latest/getting_started/#search) that returns a [`Search` object](https://opensearch.org/docs/latest/opensearch/rest-api/search/). The `Search` object is opensearch-dsl-py's representation of Elasticsearch search requests.
Expand Down
4 changes: 4 additions & 0 deletions index.sh
@@ -0,0 +1,4 @@
#!/bin/bash
echo 'Updating search indexes'
./cfgov/manage.py opensearch index --force rebuild
./cfgov/manage.py opensearch document --force --refresh --parallel index
4 changes: 1 addition & 3 deletions refresh-data.sh
Expand Up @@ -69,9 +69,7 @@ refresh_data() {
}

update_index() {
echo 'Updating search indexes'
./cfgov/manage.py opensearch index --force rebuild
./cfgov/manage.py opensearch document --force --refresh --parallel index
source ./index.sh
}

get_data() {
Expand Down

0 comments on commit 1a60fb8

Please sign in to comment.