Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcracker79/ebe07a4209caf5863409aed8758ed81c to your computer and use it in GitHub Desktop.
Save fcracker79/ebe07a4209caf5863409aed8758ed81c to your computer and use it in GitHub Desktop.
Using OpenAI to convert SQL to ES queries
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