/ELK-query_cli

Search school task

Primary LanguagePython

Task description

Develop simple console or web app (up to you) application, that would connect to Elasticsearch and would provide ability to use at least 7 different types of queries that you either learned in this section or in the Elasticsearch documentation

Ideally reuse practice task from module 6 and select appropriate dataset which would provide you ability to try several types of queries, not just text, but also range and distance

The implementation

  1. match Docs
  2. fuzzy Docs
  3. raw
  4. geo Docs
  5. regexp Docs
  6. time/number range Docs
  7. prefix Docs

Run it with suitable env

# local setup
docker-compose -f ./docker/docker-compose.yml up -d

Add data

Go to localhost:5061

image image

Add opensearch_dashboards_sample_data_ecommerce or whatever index you like

NB

Default terms for queries are from opensearch_dashboards_sample_data_ecommerce and it's a default index to search.

Build docker image

sudo docker build -t cli_es -f docker/Dockerfile .

Run image

docker run --network=host -it cli_es

Usage within container

For simplicity search alias is used to run the app in container

Will give you an overview for possible commands and basic desription

image

search

To change index type

search index "index_name"

You should see message if index exists

Index set to "index_name"

Otherwise

ValueError: Index 'index_name' doesn't exist.

Run every command search command --help to find out more

1. Match

image

Example

search match --term="geoip.city_name" --value="Cairo"

2. Fuzzy

image

Example

# There is no Gwan but Gwen
search fuzzy --term="customer_first_name.keyword" --value="Gwan"

3. Raw

image

Example

# Read query from file
search raw < example_query.json

4. Geo

image

Example

# To deal with negative numbers add "--" as in example
search geo --geo_term="geoip.location" -- -118.2 34.1

5. Regexp

image

Example

# Gwen or Gwan
search regex --term="customer_first_name.keyword" --re="Gw[a,e]n"

6. Time/number range

image

Example

# all events from yesterday till now 
search range --term="order_date" --lte="now" --gte="now-1d"
# all purshases more than 5 
search range --term="total_quantity" --gte="5"

7. Prefix

image

Example

# Search every category that starts with "Women"
search prefix --term="category.keyword" --pre="Women"