Skip to main content

ElasticSearch API

FlowG supports a subset of the ElasticSearch API, allowing you to plug it where you would use ElasticSearch, without any change in your application.

The compatibility API is available under the follwing endpoint: /api/v1/middlewares/elastic.

Configure the ElasticSearch client

NB: Adapt the username/password and URL according to your setup.

In Go:

cfg := elasticsearch.Config{
Username: "root",
Password: "root",
Addresses: []string{"http://localhost:5080/api/v1/middlewares/elastic/"},
}
client, err := elasticsearch.NewClient(cfg)

In Javascript:

const client = new Client({
node: 'http://localhost:5080/api/v1/middlewares/elastic/',
auth: {
username: 'root',
password: 'root',
},
})

In Python:

client = Elasticsearch(
hosts=["http://localhost:5080/api/v1/middlewares/elastic/"],
basic_auth=("root", "root"),
)

Supported authentication methods

HTTP Basic

The given credentials map directly to FlowG users.

🚧 HTTP Bearer

⚠️ This feature is not yet supported. ⚠️

The given token maps to either a FlowG JSON Web Token, or a FlowG Personal Access Token.

Supported operations

Check if index exists

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-exists

HEAD /api/v1/middlewares/elastic/{index}

NB: The name of the index maps to the name of a FlowG pipeline

ResponseWhen
401 UnauthorizedThe user could not be authenticated (does not exist, or invalid password)
403 ForbiddenThe user does not have the read_pipelines permission
404 Not FoundThe pipeline does not exist
200 0KThe pipeline exists
500 Internal Server ErrorAn error occured in FlowG

Example usage:

In Go:

resp, err := client.Indices.Exists(
[]string{"test"},
client.Indices.Exists.WithContext(context.TODO())
)

In Javascript:

resp = client.indices.exists({ index: 'test' })

In Python:

resp = client.indices.exists(index="test")

Index document

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-index

POST /api/v1/middlewares/elastic/{index}/_doc
{
"@timestamp": "...",
"message": "..."
}

NB: The name of the index maps to the name of a FlowG pipeline

ResponseWhen
401 UnauthorizedThe user could not be authenticated (does not exist, or invalid password)
403 ForbiddenThe user does not have the send_logs permission
400 Bad RequestThe request body was not JSON
200 0KThe document (in the request body) was successfully processed through the pipeline
500 Internal Server ErrorAn error occured in FlowG

NB: Since FlowG's datamodel is flat, the document will be flattenned first:

{
"foo": {
"bar": "baz"
}
}

will become

{
"foo.bar": "baz"
}

Example usage:

In Go:

resp, err = client.Index(
"test",
bytes.NewReader([]byte(`{"message": "hello world"}`)),
client.Index.WithContext(context.TODO()),
)

In Javascript:

resp = client.index({
index: 'test',
document: {foo: {bar: 'baz'}},
})

In Python:

resp = client.index(
index="test",
document={"foo": {"bar": "baz"}},
)

Roadmap

You can find the tracking issue on Github here.

Feel free to make new feature requests, or report bugs on the existing supported operations.