Skip to content

WorkshopDudes/elasticsearch-workshop

 
 

Repository files navigation

Elasticsearch Workshop

This repository contains 19 tasks for learning how to write Query DSL.

During these tasks you will learn how to do:

Presentation

The slides for this workshop can be found at http://workshopdudes.github.io/elasticsearch-workshop-slides.

Prerequisites - Installation

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.

Alternative 1 - Manual installation

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

Alternative 2 - Docker

An alternative solution is to use Docker.

Then the following must be installed:

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/

Pizzas

The data that are used during the workshop is a list of pizzas, see data.json.

Mapping

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"
      }
    }
  }
}

Tasks

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.

Running the tasks

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.

Alternative 1 - Manual installation

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.

Windows

Open a terminal, go to the directory where you cloned this repository, and type:

run-tasks.cmd

Linux

Open a terminal, go to the directory where you cloned this repository, and type:

./run-tasks.sh

Alternative 2 - Docker

Open a terminal, go to the directory where you cloned this repository, and type:

make run-tasks

Releases

No releases published

Packages

No packages published

Languages

  • Gherkin 49.7%
  • Python 45.5%
  • Makefile 2.8%
  • Shell 1.9%
  • Batchfile 0.1%