[Recipes] Using the Elasticsearch Search API with Request URI

Problem: 

Need to search within elastic search by providing search parameters in the request URI.

Solution Summary: 

We can use the "_search" endpoint to search within elastic search. We can use it with a request body (query DSL) or with request URI. Here we will see examples for using search with request uri.

Prerequisites: 

Should set up accounts index from accounts.json as explained here.

Solution Steps: 

Simple Search with Sorting

GET /accounts/_search?sort=account_number:asc&pretty

 

Search with Simple Filtering

GET /accounts/_search?q=account_number:1&pretty

 

Search with Boolean operators

GET /accounts/_search?q=account_number:1 OR account_number:2&pretty

If you are searching from outside of Kibana from any standard HTTP client, you may have to use %20 for spaces:

GET /accounts/_search?q=account_number:1%20OR%20account_number:2&pretty 

 

Search with combinations of Boolean operators

You can add more than one OR operator:

GET /accounts/_search?q=account_number:1 OR account_number:2 OR account_number:3&pretty

 

You can have OR and AND together:

GET /accounts/_search?q=account_number:1 OR account_number:2 AND account_number:3&pretty

Note: This will be returning nothing anyway.

 

You may use paranthesis to group clauses:

GET /accounts/_search?q=account_number:1 OR (account_number:2 AND account_number:3)&pretty

 

TODO

  1. Write a query to search across two indexes using request URI. See references.

  2. Add more complex request URI based filtering queries.

Recipe Tags: 

Learn Serverless from Serverless Programming Cookbook

Contact

Please first use the contact form or facebook page messaging to connect.

Offline Contact
We currently connect locally for discussions and sessions at Bangalore, India. Please follow us on our facebook page for details.
WhatsApp (Primary): (+91) 7411174113
Phone (Escalations): (+91) 7411174114

Business newsletter

Complete the form below, and we'll send you an e-mail every now and again with all the latest news.

About

CloudMaterials is my blog to share notes and learning materials on Cloud and Data Analytics. My current focus is on Microsoft Azure and Amazon Web Services (AWS).

I like to write and I try to document what I learn to share with others. I believe that knowledge is useless unless you share it; the more you share, the more you learn.

Recent comments

Photo Stream