-
Fork / Clone the repository
$ git clone https://github.com/elastic/pycon-2021-workshop-app-search$ cd pycon-2021-workshop-app-search
-
Create a virtual environment and install all dependencies in
requirements.txt:$ python -m venv venv$ source venv/bin/activate$ (venv) python -m pip install -r requirements.txt
-
Start an Enterprise Search instance. There are two options here:
- Create an Elastic Cloud account (comes with a 14 day free trial no credit card required)
- Install
docker-composeand usedocker-compose upto start an Enterprise Search instance locally
-
Update the
urlandprivate_keyvalues inconfig.ymlper the instructions for starting the Enterprise Search instance below. -
Make sure at least
examples/example_1_making_requests.pyis able to run completely. You should see the messageEverything worked! :-)in your terminal. All examples are meant to be run viapython examples/example_N_...pyor via the "Run" functionality in your IDE.
- Create an Elastic Cloud account
- Create a new Deployment using the "Enterprise Search" template
- Select a cloud provider and region and select
Create Deployment. The instance will be provisioned and available in a few minutes - Click
LaunchorCopy Endpointin the new deployment overview and copy the URL (minus the/loginpath). The result should look like approximately this:https://(deployment name)-1a6dc7.ent.us-west1.gcp.cloud.es.io - Open
config.ymland seturlfield to be"https://(deployment name)-1a6dc7.ent.us-west1.gcp.cloud.es.io"and run the script and ensure it passes without error. - Select
Launch App Search, from here you'll be placed in a getting started screen. You can follow these steps if you'd like otherwise you can selectSkip Onboardingin the top. - That's it, you're now in App Search!
- Download and install docker-compose
- With an open terminal in the cloned git repository run
docker-compose up. Wait for all services to spin up and configure for the first time which may take a minute. - You should be able to connect to
http://localhost:3002in a browser - Open
config.ymland seturlfield to be"http://localhost:3002"and run the script and ensure it passes without error. - The username will be
enterprise_searchand the password will bechangeme. - Select
Launch App Search, from here you'll be placed in a getting started screen. You can follow these steps if you'd like otherwise you can selectSkip Onboardingin the top. - That's it, you're now in App Search!
- When in App Search, navigate to the
Credentialstab - Click the
Copy to Clipboardbutton next to the Private Key - Paste the value into the
private_keyfield inconfig.yml
- Ensure your virtualenv is activated and
requirements.txtis installed - Change directory into
django/ - Run
python manage.py migrationsto createdb.sqlite3 - Run
python manage.py runserverto start the server onhttp://localhost:8000. Don't use these exact configurations in production! - Access
http://localhost:8000/resetto load data into the Django database
http://localhost:8000/<park-id>Shows a park by ID within the Django databasehttp://localhost:8000/searchHas the Reference UI configured for App Searchhttp://localhost:8000/remove-parkRemovespark-acadiafrom the Django database, see how signals keep App Search up to date.http://localhost:8000/add-parkAddspark-acadiafrom the Django database, see how signals keep App Search up to date.http://localhost:8000/remove-m2mRemoves the stateTennesseefrompark-great-smoky-mountains, see how signals keep App Search up to date.http://localhost:8000/add-m2mAdds the stateTennesseetopark-great-smoky-mountains, see how signals keep App Search up to date.http://localhost:8000/resetResets the Django database to its original set of data (takes a while because we're not using background tasks)http://localhost:8000/run-taskRuns the background task to index documents from the database into a new source engine and update a meta engine.
See django/parks/models.py for the signals approach to indexing documents in App Search.
See django/parks/tasks.py for the tasks approach to indexing documents in App Search.
When doing this in real life I recommend using background tasks for signal handlers to avoid blocking web requests.
The Reference UI has been generated and the production compressed JS and CSS are stored in django/static/.
When you're creating your own Reference UI you should not copy these and instead follow the instructions
on the Reference UI repository.