Rendering queries¶
Kaquel provides various utilities to render queries from Query
objects into different languages. In this section, we will use these utilities
in example programs.
Rendering queries as KQL¶
In order to parse a KQL query, you must use the render_as_kql()
function.
For example, say you need to make a program that converts a KQL query provided in the standard input into an ElasticSearch query. You can do the following:
from __future__ import annotations
from sys import stdin
from kaquel.es_query import parse_es_query
from kaquel.kql import render_as_kql
# Read the ES query from standard input.
query = parse_es_query(stdin.read())
# Render the ES query into a a KQL string.
kql_query = render_as_kql(query)
# Display the resulting KQL query.
print(kql_query)
For example, when executing the program with the following input:
{"bool": {"filter": [{"match": {"a": "b"}}, {"match_phrase": {"c": "d"}}]}}
The output will be the following:
a: b and c: "d"