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

Vega: use elasticsearch's _query endpoint for queries #62333

Open
jpcarey opened this issue Apr 2, 2020 · 6 comments
Open

Vega: use elasticsearch's _query endpoint for queries #62333

jpcarey opened this issue Apr 2, 2020 · 6 comments
Labels
enhancement New value added to drive a business result Feature:Vega Vega visualizations impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. Team:Visualizations Visualization editors, elastic-charts and infrastructure

Comments

@jpcarey
Copy link

jpcarey commented Apr 2, 2020

Describe the feature: Allow usage of the elasticsearch /_sql endpoint with the Vega visualization / plugin.

Describe a specific use case for the feature: Allow graphing using vega, while using standard SQL syntax to query for the data in elasticsearch.

It is a challenge to build the elasticsearch query, then have to fully transform the return data from elasticsearch's aggregation to something that Vega can use. The SQL endpoint seems like it would be easier to get back something closer to a flattened table.

From Vega's documentation, most examples have a simple array of single level objects, where each object contains what needs to be plotted:

"values": [
  {"x": 0, "y": 28, "c": 0}, {"x": 0, "y": 55, "c": 1},
  {"x": 1, "y": 43, "c": 0}, {"x": 1, "y": 91, "c": 1},
  {"x": 2, "y": 81, "c": 0}, {"x": 2, "y": 53, "c": 1},
  {"x": 3, "y": 19, "c": 0}, {"x": 3, "y": 87, "c": 1},
]

The sql endpoint will return the data shaped like

{
  "columns" : [
    {
      "name" : "tier_c",
      "type" : "keyword"
    },
    {
      "name" : "week_of_year",
      "type" : "integer"
    },
    {
      "name" : "resources",
      "type" : "integer"
    },
    {
      "name" : "count",
      "type" : "long"
    },
    {
      "name" : "effort",
      "type" : "double"
    }
  ],
  "rows" : [
    [
      null,
      1,
      2,
      59,
      118
    ],
    [
      "fixme",
      1,
      0,
      3,
      6
    ]
  ]
}

This would still need to be transformed to combine the column names to create each row as an object (might be an enhancement for elasticsearch to return something similar to the Vega example structure above).

cc: @flash1293

@flash1293 flash1293 added enhancement New value added to drive a business result Feature:Vega Vega visualizations Team:Visualizations Visualization editors, elastic-charts and infrastructure labels Apr 2, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@flash1293
Copy link
Contributor

A little more context:

  • Vega offers a lot of ways to transform data, so the particular format it gets returned in doesn't matter too much - it's working ok for highly nested aggregation responses, so it should be possible to do it for this format as well.
  • As vega is an OSS feature and sql is not, we have to introduce an extension point for vega data sources. It's probably not too hard to do this, one option would be to tie it to the key in data, e.g.
  data: {
    url: { // handled by the default search datasource
  data: {
    sql: { // handled by the default essql datasource

Another option would be to leverage the expression framework here and provide a separate dedicated SQL input for the sql query and a different expression (essql query='...' | vega useContext=true) - this would be more work initially but could help us integrating vega with canvas and other datasources (like EQL) later on.

@wylieconlon
Copy link
Contributor

wylieconlon commented Jan 25, 2021

This is worth revisiting now that Vega is in GA, as I'd really like to see Vega support SQL and EQL. Vega already supports querying using:

  • Search source
  • Maps service
  • External URL fetching

The SQL and EQL endpoints are very simple, but they are not exposed directly in the browser so that increases the complexity of the integration. If we could have SQL and EQL support in the search source it would make this easier, but I don't think that's likely to happen soon.

What if we add a Vega server which exposes a SQL and EQL querying endpoint?

@wylieconlon
Copy link
Contributor

After discussion with @ppisljar and @lizozom we have realized that a SQL search strategy is the missing piece needed here, but that it can be done. There is currently no issue tracking the SQL search strategy.

@stratoula
Copy link
Contributor

Possibly we need to rethink it and instead of supporting _sql support ES|QL instead (_query api)

@stratoula stratoula added the impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. label Oct 4, 2023
@stratoula stratoula changed the title Vega: use elasticsearch's _sql endpoint for queries Vega: use elasticsearch's _query endpoint for queries Jan 30, 2024
@ethanjonez
Copy link

ethanjonez commented Feb 13, 2024

Assuming _sql can be used to make pipelined queries i.e. first result forms basis for second query +1. If this is simple to add, this is incredibly powerful for combining queries across non-time series indices with time-series indices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Feature:Vega Vega visualizations impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. Team:Visualizations Visualization editors, elastic-charts and infrastructure
Projects
None yet
Development

No branches or pull requests

6 participants