Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save time range in searches #3440

Open
51CGO opened this issue Feb 17, 2023 · 3 comments
Open

Save time range in searches #3440

51CGO opened this issue Feb 17, 2023 · 3 comments
Assignees
Labels
discover for discover reinvent enhancement New feature or request

Comments

@51CGO
Copy link

51CGO commented Feb 17, 2023

Is your feature request related to a problem? Please describe.

Saving a search does not save the time range.

Describe the solution you'd like

When saving a search, the Opensearch Dashboards should display a checkbox "Save time range" and the time range box.

Describe alternatives you've considered

Allow query arguments in URL, simplier than the filter format

Additional context

I'm using reporting-cli to generate reports but it's not possible to specify time range for reporting.

@51CGO 51CGO added the enhancement New feature or request label Feb 17, 2023
@ahopp
Copy link
Contributor

ahopp commented Feb 21, 2023

@joshuarrrr I think "sharing" snapshots saves the time frame added in dashboards and discover...but I guess save doesn't. Does the PIT solve for this?

@joshuarrrr joshuarrrr assigned dagneyb and unassigned joshuarrrr Mar 14, 2023
@joshuarrrr joshuarrrr added discover for discover reinvent and removed untriaged labels Mar 14, 2023
@joshuarrrr
Copy link
Member

After review, I believe this is a valid feature request.

Current alternatives

@51CGO While there's no current way to include the date range in the saved search, there are a couple alternatives that may be useful.

1. Generate "Share" links

As @ahopp mentioned, one way to "save" a search with the currently selected time range is to use the "Share" option from Discover:

Screen Shot 2023-03-14 at 1 54 01 PM

Either of the options (Snapshot or Saved object) will work, because the date filters are directly encoded in the URLs:

Snapshot permalink example:
http://localhost:5603/qeg/app/discover#/view/3791cdf0-c2a8-11ed-99fd-3d4e9310ea4b?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-2w,to:now))&_a=(columns:!(Carrier,OriginCityName,OriginCountry,DestCityName,DestCountry,FlightTimeMin,AvgTicketPrice,Cancelled,FlightDelayType,dayOfWeek,_type),filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:d3d7af60-4c81-11e8-b3d7-01146121b73d,key:dayOfWeek,negate:!f,params:(query:'3'),type:phrase),query:(match_phrase:(dayOfWeek:'3')))),index:d3d7af60-4c81-11e8-b3d7-01146121b73d,interval:auto,query:(language:kuery,query:''),sort:!(!(timestamp,desc)))

Saved object permalink example

http://localhost:5603/qeg/app/discover#/view/3791cdf0-c2a8-11ed-99fd-3d4e9310ea4b?_g=(filters%3A!()%2CrefreshInterval%3A(pause%3A!t%2Cvalue%3A0)%2Ctime%3A(from%3Anow-2w%2Cto%3Anow))

2. Use saved queries

In addition to "saved searches", OpenSearch Dashboards also has the concept of "saved queries". You can think of a saved query as a shortcut for easily applying and re-applying any queries, filters and timerange filters, regardless of which OpenSearch Dashboards application you're using (Discover, Visualize, Dashboard). You can save a query with the Save button to the left of the query field. Make sure to enable the "Include time filter" toggle if you want the time filter included.

Screen Shot 2023-03-14 at 1 57 36 PM

Screen Shot 2023-03-14 at 1 58 03 PM

Explanation of current behavior

When creating or saving a saved search from discover, both the query contents and any currently applied filters will be include in the saved search (specifically in the kibanaSavedObjectMeta.searchSourceJSON) field. Here's an example of a saved search that includes both.

Screen Shot 2023-03-14 at 2 24 57 PM

The date filter, however is not included. I believe this may be due to some quirks in global vs app state, which @abbyhu2000 can provide more info on. @dagneyb It would be useful to get some product insight on the expected behavior here - to me, it makes sense to treat date filters similarly to other filters, but doing so may have some architectural complications.

Also CC @vagimeli for ideas on how we could improve documentation around these concepts.

@abbyhu2000
Copy link
Member

abbyhu2000 commented Mar 14, 2023

As @joshuarrrr mentioned, when we create a saved search object, the query and filter will be saved in the saved search object, but not the date filter. This is because the app filter and query are persisted in the app state, and the time filter are persisted in the global state. (Unless we make the filter the global filter by pinning them, then it will also be persisted in the global state).

Since time filter are persisted globally, it will be encoded in the '_g' part of the URL, but not the actual saved object. (That is why we can persist the time filter value using generate share link function, because we can retrieve the date filter value by decoding the URL). This behavior is consistent throughout the app, for example, when we create visualization objects or dashboard objects with some time filter, the time filter will also not be persisted within the saved object.

Currently, Vis Builder, Visualization, Discover, and Dashboards are onboarded with the global state persistence functionalities. When we create a time filter on one of these pages, and we navigate to another one of these pages, the time filter will be persisted and applied there. For example, if we create a time filter on Discover page, and then we navigate to Dashboard page, the time filter will be automatically applied. The PR has a demo video that showcases the behavior of global persistence for time filter: #2896 (comment)

I also think this is a valid feature request, and we can discuss more on whether we should make the time filter not only a global state data but also an app state data so it can be saved within the app state. If we do include the time filter in the discover app state, we should also do the same thing for visualization, vis builder and dashboard plugin to ensure consistent behavior. We should also consider if we need to include the other global data such as the query in the app state as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discover for discover reinvent enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants