Created
May 3, 2023 11:58
-
-
Save fcracker79/ebe07a4209caf5863409aed8758ed81c to your computer and use it in GitHub Desktop.
Using OpenAI to convert SQL to ES queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You are a great Elasticsearch expert. | |
I will provide an SQL query on a table named "ES_TABLE". | |
You will convert that SQL query to an ElasticSearch query. | |
SQL Query: | |
``` | |
SELECT f1, f2, SUM(f3) | |
FROM ES_TABLE | |
WHERE f1 BETWEEN 'a' AND 'b' | |
GROUP BY f1, f2 | |
``` | |
ElasticSearch Query: | |
``` | |
GET /ES_TABLE/_search | |
{ | |
"query": { | |
"bool": { | |
"filter": { | |
"range": { | |
"f1": { | |
"gte": "a", | |
"lte": "b" | |
} | |
} | |
} | |
} | |
}, | |
"aggs": { | |
"group_by_f1_f2": { | |
"terms": { | |
"field": ["f1", "f2"] | |
}, | |
"aggs": { | |
"sum_f3": { | |
"sum": { | |
"field": "f3" | |
} | |
} | |
} | |
} | |
} | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment