This repository contains 19 tasks for learning how to write Query DSL.
During these tasks you will learn how to do:
- Match all (task 0)
- Full-text search (task 1-4)
- Term queries (task 5-8)
- Aggregations (task 9-13)
- Combine full-text search and aggregations (task 14)
- Sorting (task 15)
- Highlightning (task 16)
- Pagination (task 17-18)
The slides for this workshop can be found at http://workshopdudes.github.io/elasticsearch-workshop-slides.
Get the code:
git clone https://github.com/WorkshopDudes/elasticsearch-workshop
In order to support multiple platforms, we have provided two installation methods. We recommend that Windows users follow the manual installation guide. Linux users will probably want to use Docker, but manual installation is of course also possible on Linux.
The following must be installed:
Elasticsearch is built using Java, and requires at least Java 7 in order to run.
Windows:
// If you are on the Statoil network
setx HTTPS_PROXY "http://www-proxy.statoil.no:80"
setx HTTP_PROXY "http://www-proxy.statoil.no:80"
setx JAVA_HOME "c:\Program Files\Java\jre1.7.0_72"
(restart cmd)
set PATH=%PATH%;c:\appl\Python27;c:\appl\Python27\Scripts
Linux:
// If you are on the Statoil network
export HTTPS_PROXY="http://www-proxy.statoil.no:80"
export HTTP_PROXY="http://www-proxy.statoil.no:80"
Then, install all the required Python packages:
pip install -r requirements.txt
An alternative solution is to use Docker.
Then the following must be installed:
- Docker
- Docker Compose
- make (
sudo apt-get install make
on Ubuntu)
If you are on the Statoil network, comment in these two lines in the Dockerfile:
# ENV http_proxy http://www-proxy.statoil.no:80/
# ENV https_proxy http://www-proxy.statoil.no:80/
The data that are used during the workshop is a list of pizzas, see data.json.
Mapping is the process of defining how a document, and the fields it contains, are stored and indexed.
The pizzas has the mapping:
{
"pizza": {
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "string"
},
"topping": {
"type": "string",
"index": "not_analyzed"
},
"weight": {
"type": "long"
}
}
}
}
The tasks are feature tests, and they look like this:
Feature: Topic of the task
// Use https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-FEATURE-TO-USE.html
Scenario: Description of the task
Given all pizzas are indexed
When I make a query
"""
{ todo }
"""
Then the response should contain
"""
{ subset }
"""
Your task is to replace the { todo }
with the correct query.
The comment use https://...
points you to the page where you can find information about how to write the correct query.
A query needs to return a correct response { subset }
to be passed. To make the tests more compact and easy to read, they only compare and validates against a { subset }
.
Solutions to all tasks can be found here.
I recommend using the Chrome extension Sense during the creation of queries.
For windows users, we have experienced problems when using tab instead of space, therefore only use spaces when you indent your code.
Make sure elasticsearch is up and running before trying to run tasks. To start
elasticsearch, open a terminal window and run
<elasticsearch-directory>/bin/elasticsearch
.
Open a terminal, go to the directory where you cloned this repository, and type:
run-tasks.cmd
Open a terminal, go to the directory where you cloned this repository, and type:
./run-tasks.sh
Open a terminal, go to the directory where you cloned this repository, and type:
make run-tasks