Skip to content

Commit

Permalink
adding in a new page for filtering search results documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
leanneeliatra committed Jul 10, 2024
1 parent c1542b7 commit 4e9b35b
Showing 1 changed file with 131 additions and 0 deletions.
131 changes: 131 additions & 0 deletions _search-plugins/searching-data/filtering-search-results.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
layout: default
title: Filter results
parent: Searching data
nav_order: 21
redirect_from:
- /opensearch/search/filter/
---
# Filtering search results in OpenSearch

Filtering the search results in OpenSearch allows you to refine the results returned. Specifying criteria to filter the indexes/documents by, allows you to refine the returned results. You can filter the results based on ranges, conditions or specific terms to refine the returned results. This is helpful when you have large datasets and allows you to interpret and understand larger datasets more easily.

Filtering allows you to:
- Improve search accuracy by reducing unneeded information on a case by case basis to allow accurate interpretation of results.
- Enhance performance by reducing the amount of data necessary to process and return when querying. Improving query performance.
- Categorised search by allowing data to be returned in categories which allows you to explore the data in a structured manner.

## Filtering with OpenSearch Dashboards

To begin filtering in OpenSearch Dashboards, follow these steps:

1. Navigate to the OpenSearch Dashboards UI.
2. Click on `Discover` in the sidebar.
3. Choose `opensearch_dashboards_sample_data_flights` from the index pattern selector.

### Example: Filter by destination airport

To filter flights arriving at "Zurich Airport":

**Add a filter:**
- Click on the `Add filter` button.
- In the filter field, select `Dest`.
- In the operator field, select `is`.
- In the value field, type `Zurich Airport`.
- Click `Save`.

This will display only the flights arriving at Zurich Airport.

### Example: Filter by flight delay

To filter flights that have been cancelled in the last 100 days:
- Click on the timeframe to update the time selection.

Check failure on line 42 in _search-plugins/searching-data/filtering-search-results.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.SubstitutionsError] Use 'time frame' instead of 'timeframe'. Raw Output: {"message": "[OpenSearch.SubstitutionsError] Use 'time frame' instead of 'timeframe'.", "location": {"path": "_search-plugins/searching-data/filtering-search-results.md", "range": {"start": {"line": 42, "column": 16}}}, "severity": "ERROR"}

Check failure on line 42 in _search-plugins/searching-data/filtering-search-results.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: timeframe. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: timeframe. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_search-plugins/searching-data/filtering-search-results.md", "range": {"start": {"line": 42, "column": 16}}}, "severity": "ERROR"}
- Under the 'Relative' time tab.
- Change the unit to '1'.
- From the dropdown select 'Days ago'.
- The data shown is now from the Last 100 days.

**Add a filter:**
- Click on the `Add filter` button.
- In the filter field, select `Cancelled`.
- In the operator field, select `is`.
- In the value field, type `true`.
- Click `Save`.

This will display only the flights that have been cancelled with a destination of Zurich Airport in the last 100 days.

## Using Query DSL for advanced filtering

OpenSearch Query DSL (Domain Specific Language) allows for more complex and powerful queries. You can combine multiple conditions and use advanced logic to filter data.

### Example of Query DSL filtering

To use Query DSL, you need to define your queries in JSON format.

To begin filtering via DSL in OpenSearch Dashboards, follow these steps:

Check warning on line 65 in _search-plugins/searching-data/filtering-search-results.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.LatinismsSubstitution] Use 'using, through, by accessing, or by choosing' instead of 'via'. Raw Output: {"message": "[OpenSearch.LatinismsSubstitution] Use 'using, through, by accessing, or by choosing' instead of 'via'.", "location": {"path": "_search-plugins/searching-data/filtering-search-results.md", "range": {"start": {"line": 65, "column": 20}}}, "severity": "WARNING"}

1. Navigate to the OpenSearch Dashboards UI.
2. Click on `Dev Tools` in the sidebar.
3. Write your DSL query in the dev tools left window.

Check failure on line 69 in _search-plugins/searching-data/filtering-search-results.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [Vale.Terms] Use 'Dev' instead of 'dev'. Raw Output: {"message": "[Vale.Terms] Use 'Dev' instead of 'dev'.", "location": {"path": "_search-plugins/searching-data/filtering-search-results.md", "range": {"start": {"line": 69, "column": 32}}}, "severity": "ERROR"}
4. Highlight the query and click the play button to run the query.
5. The answer is outputted in the right half of the dev tools window.

Check failure on line 71 in _search-plugins/searching-data/filtering-search-results.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [Vale.Terms] Use 'Dev' instead of 'dev'. Raw Output: {"message": "[Vale.Terms] Use 'Dev' instead of 'dev'.", "location": {"path": "_search-plugins/searching-data/filtering-search-results.md", "range": {"start": {"line": 71, "column": 53}}}, "severity": "ERROR"}

### Example: Filter flights with delay greater than 60 minutes

```json
GET opensearch_dashboards_sample_data_flights/_search
{
"query": {
"range": {
"FlightDelayMin": {
"gt": 60
}
}
}
}
```

This DSL query will retreive the instances where the flight delay is greater than 60 minutes.

Check failure on line 88 in _search-plugins/searching-data/filtering-search-results.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: retreive. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: retreive. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_search-plugins/searching-data/filtering-search-results.md", "range": {"start": {"line": 88, "column": 21}}}, "severity": "ERROR"}

### Example: Combined filter with Query DSL

To filter flights operated by "Logstash Airways", with an average ticket price (AvgTicketPrice) between 0 and 1000, and destination country (DestCountry) as Italy, you can use the following DSL query:

```json
GET opensearch_dashboards_sample_data_flights/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"Carrier": "Logstash Airways"
}
},
{
"range": {
"AvgTicketPrice": {
"gte": 0,
"lte": 1000
}
}
},
{
"term": {
"DestCountry": "IT"
}
}
]
}
}
}
```

This query uses a boolean must clause to combine three conditions:

Check failure on line 124 in _search-plugins/searching-data/filtering-search-results.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [Vale.Terms] Use 'Boolean' instead of 'boolean'. Raw Output: {"message": "[Vale.Terms] Use 'Boolean' instead of 'boolean'.", "location": {"path": "_search-plugins/searching-data/filtering-search-results.md", "range": {"start": {"line": 124, "column": 19}}}, "severity": "ERROR"}

Check failure on line 124 in _search-plugins/searching-data/filtering-search-results.md

View workflow job for this annotation

GitHub Actions / style-job

[vale] reported by reviewdog 🐶 [OpenSearch.Spelling] Error: boolean. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks. Raw Output: {"message": "[OpenSearch.Spelling] Error: boolean. If you are referencing a setting, variable, format, function, or repository, surround it with tic marks.", "location": {"path": "_search-plugins/searching-data/filtering-search-results.md", "range": {"start": {"line": 124, "column": 19}}}, "severity": "ERROR"}

1. The carrier is Logstash Airways.
2. The average price ticket is between 0 and 1000 dollars.
3. The destination country is Italy.

By following these steps, you can filter and examine large data sets with ease, based off the relevant queries and criteria for your investigations.

0 comments on commit 4e9b35b

Please sign in to comment.