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
-
Write a query to search across two indexes using request URI. See references.
-
Add more complex request URI based filtering queries.
Recent comments