elasticsearch-js icon indicating copy to clipboard operation
elasticsearch-js copied to clipboard

SQL Query should return a response json with full data

Open pandareen opened this issue 3 years ago • 1 comments

🚀 Feature Proposal

Current sql query api in node.js is returning a resultset and we have to iterate over it and create final key:value json object. I propose it return a json with key:value pairs in result data. The SQL REST API already returns a json (Even though it doesn't return a key value pair).

Motivation

This is to stop us from running into memory issues when the result set is large and the for loop runs for too long.

Example

Existing code is this (picked from here)

  const result = await client.sql.query({
    query: "SELECT * FROM \"game-of-thrones\" WHERE house='stark'"
  })

  console.log(result)

  const data = result.rows.map(row => {
    const obj = {}
    for (let i = 0; i < row.length; i++) {
      obj[result.columns[i].name] = row[i]
    }
    return obj
  })

  console.log(data)

Proposed code is this instead of the user iterating on the resultset to make the final JSON, can we have the result.data as a JSON response, which is const data as per the above example.

pandareen avatar Apr 29 '22 16:04 pandareen

Hello! The client returns the response as Elasticsearch crafts them, and it cannot change them. You are asking more of a helper, which currently doesn't exist for SQL. I'll mark this as a feature request and think about it.

delvedor avatar May 06 '22 08:05 delvedor