
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
@elastic/request-converter
Advanced tools
Library that converts Elasticsearch requests in Dev Console syntax to other formats.
Try it out here.
npm install @elastic/request-converter
import { convertRequests } from "@elastic/request-converter";
const devConsoleScript = `GET /my-index-000001/_search?from=40&size=20
{
"query": {
"term": {
"user.id": "kimchy"
}
}
}`
async function main() {
const code = await convertRequests(devConsoleScript, "python", {
checkOnly: false,
printResponse: true,
complete: true,
elasticsearchUrl: "http://localhost:9200",
});
console.log(code);
}
main();
The list of available formats that can be passed in the second argument can be obtained as follows:
import { listFormats } from "@elastic/request-converter";
const formats = listFormats();
The ouput code in the example above would look like this:
import os
from elasticsearch import Elasticsearch
client = Elasticsearch(
hosts=["http://localhost:9200"],
api_key=os.getenv("ELASTIC_API_KEY"),
)
resp = client.search(
index="my-index-000001",
from_="40",
size="20",
query={
"term": {
"user.id": "kimchy"
}
},
)
When using Node and JavaScript, you can import the functions in this library as follows:
const { convertRequests, listFormats } = require("@elastic/request-converter");
At this time the converter supports curl
, python
, javascript
, php
and ruby
. Work is currently in
progress to add support for more languages.
The curl exporter generates commands for the terminal using the curl command line HTTP client.
Supported options:
Option name | Type | Required | Description |
---|---|---|---|
elasticsearchUrl | string | no | The Elasticsearch endpoint to use in the generated commands. The default is http://localhost:9200 . |
otherUrls | Record<string, string> | no | URLs for other services. For Kibana, use {kbn: "http://localhost:5601"} |
windows | boolean | no | If true , use PowerShell escaping rules for quotes. If false , use bash/zsh escaping rules. The default is false . |
The Python exporter generates code for the Elasticsearch Python client.
Supported options:
Option name | Type | Required | Description |
---|---|---|---|
printResponse | boolean | no | If true , add code to print the response. The default is false . |
complete | boolean | no | If true , generate a complete script. If false , only generate the request code. The default is false . |
elasticsearchUrl | string | no | The Elasticsearch endpoint to use. The default is http://localhost:9200 . |
The PHP exporter generates code for the Elasticsearch PHP client.
Supported options:
Option name | Type | Required | Description |
---|---|---|---|
printResponse | boolean | no | If true , add code to print the response. The default is false . |
complete | boolean | no | If true , generate a complete script. If false , only generate the request code. The default is false . |
elasticsearchUrl | string | no | The Elasticsearch endpoint to use. The default is http://localhost:9200 . |
The Ruby exporter generates code for the Elasticsearch Ruby client.
Supported options:
Option name | Type | Required | Description |
---|---|---|---|
printResponse | boolean | no | If true , add code to print the response. The default is false . |
complete | boolean | no | If true , generate a complete script. If false , only generate the request code. The default is false . |
elasticsearchUrl | string | no | The Elasticsearch endpoint to use. The default is http://localhost:9200 . |
For convenience, a CLI that wraps the convertRequests
function is also available.
$ echo GET / > request.txt
$ node_modules/.bin/es-request-converter --format python --complete < request.txt
import os
from elasticsearch import Elasticsearch
client = Elasticsearch(
hosts=[os.getenv("ELASTICSEARCH_URL")],
api_key=os.getenv("ELASTIC_API_KEY"),
)
resp = client.info()
Instead of passing the name of one of the available exporters, you can pass a custom exporter instance.
To define a custom exporter format, create a class that implements the
FormatExporter
interface. Here is an example exporter that outputs the name
of the API used in the request:
import { FormatExporter, convertRequests } from "@elastic/request-converter";
class MyExporter implements FormatExporter {
async check(requests: ParsedRequest[]): Promise<boolean> { return true; }
async convert(requests: ParsedRequest[], options: ConvertOptions): Promise<string> {
return requests.map(req => req.api).join("\n");
}
}
const apis = await convertRequests("GET /my-index/_search\nGET /\n", new MyExporter(), {});
console.log(apis); // outputs "search\ninfo"
FAQs
Elasticsearch request converter
The npm package @elastic/request-converter receives a total of 50,780 weekly downloads. As such, @elastic/request-converter popularity was classified as popular.
We found that @elastic/request-converter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 67 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.