Skip to content

[Reporting/CSV/7.17] allow query from state in parameters#149297

Merged
tsullivan merged 8 commits intoelastic:7.17from
tsullivan:reporting/csv-savedobject-export-allow-additional-state
Jan 24, 2023
Merged

[Reporting/CSV/7.17] allow query from state in parameters#149297
tsullivan merged 8 commits intoelastic:7.17from
tsullivan:reporting/csv-savedobject-export-allow-additional-state

Conversation

@tsullivan
Copy link
Copy Markdown
Member

@tsullivan tsullivan commented Jan 23, 2023

Summary

In 7.17.9, we're restoring a report generation API endpoint to create CSV reports based on saved searches. There has been one PR that serves as the first iteration: #148030

This resolves a missing capability from the first iteration. In the first iteration, POST bodies could allow an additional time range filter, which is merged with any saved filters or queries stored in the saved search object:

POST /api/reporting/v1/generate/csv/saved-object/search:${savedSearchId}
{
  timerange: {
    min: '2015-09-20 10:23:36.052',
    max: '2015-09-20 10:25:55.744'
  }
}

This PR is a second iteration. It allows additional "unsaved state" to be merged with the saved object at the time of report generation.

POST /api/reporting/v1/generate/csv/saved-object/search:${savedSearchId}
 state": {
  "query": { "multi_match": { "type": "best_fields", "query": "cognac", "lenient": true } },
  "timerange": <same as before>
POST /api/reporting/v1/generate/csv/saved-object/search:${savedSearchId}
"state": {
  "query": [
    { "multi_match": { "type": "best_fields", "query": "cognac", "lenient": true } },
    { "bool": { "must_not": { "multi_match": { "type": "best_fields", "query": "Pyramidustries", "lenient": true } } } }
  ],
 timerange": <same as before>

Details

In the details of #148030, it was stated:

Does not allow "raw state" to be merged with the Search object, as in the previous code (from 7.3-7.8). Otherwise, the API is compatible with the previous code.

This PR pushes a bit back against that limitation. Now, requests to generate a report can accept a state field in the POST body. This field contains additional "unsaved state" that gets merged with the contents of the stored saved search object.

However, the entire functionality of allowing sort and docvalue_fields keys in the request, is still not restored from the functionality that was implemented in 7.3-7.8. This limitation exists to minimize the complexity of the restored endpoint.

Both of the non-restored keys are related to the sorting of documents. The sorting of documents is controlled by the saved search object only. The user can change the sort of the CSV after downloading the report, in a spreadsheet application or by programmatically working on the file.

Checklist

Delete any items that are not applicable to this PR.

@tsullivan tsullivan force-pushed the reporting/csv-savedobject-export-allow-additional-state branch from 5594006 to 12bec57 Compare January 23, 2023 04:01
@tsullivan tsullivan added release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// labels Jan 23, 2023
interface CsvFromSavedObjectBase {
objectType: 'saved search';
state?: {
query: estypes.QueryDslQueryContainer | estypes.QueryDslQueryContainer[];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: sort and docvalue_fields are still not supported, as they had been in the older, removed code.

]);
});

it('with saved search containing a filter', async () => {
Copy link
Copy Markdown
Member Author

@tsullivan tsullivan Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't test anything new: it was added to make sure that filters stored on the saved search can be a singular object - not just an array.

@tsullivan tsullivan marked this pull request as ready for review January 23, 2023 21:09
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/appex-sharedux (Team:SharedUX)

Copy link
Copy Markdown
Contributor

@rshen91 rshen91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool PR 👍🏻
Thank you for the tests and comments to add clarity

@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@tsullivan tsullivan requested a review from a team January 24, 2023 04:10
@tsullivan tsullivan merged commit bc23001 into elastic:7.17 Jan 24, 2023
@tsullivan tsullivan deleted the reporting/csv-savedobject-export-allow-additional-state branch January 24, 2023 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes Team:SharedUX Platform AppEx-SharedUX (formerly Global Experience) t// v7.17.9

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants