elasticsearch-js: client6.sql.query is not work
elastic version: 6.6.2
my code:
const { Client: Client7 } = require('@elastic/elasticsearch')
const client6 = new Client7({ node: 'http://localhost:9200' })
let aa = await client6.sql.query({
body: {
query: `SELECT * FROM "${this.elastic_name}"`,
}
});
Correct interface request:
POST _xpack/sql?format=json
{
"query":"SELECT * FROM \"f271444afc2479560efc51b68a0cc996\" limit 10"
}
He works normally.
but api/sql.query.js
line 82:
path = '/' + '_sql'
The request is:
{ method: 'POST',
path: '/_sql',
body: { query: 'SELECT * FROM "f271444afc2479560efc51b68a0cc996"' },
querystring: {} }
error:
{ body:
{ error: 'Incorrect HTTP method for uri [/_sql] and method [POST], allowed: [PUT, DELETE, GET, HEAD]',
status: 405 },
Change the code to :
path = '/' + '_xpack/sql'
Can operate normally
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (7 by maintainers)
For whoever is looking for a direct solution, here it is.
@mitjafelicijan you can’t change the path via an option, as this client is generated from the Elasticsearch’s spec. You can either use the
transport.requestor use theextendAPI and override the default implementation.