{"id":15361918,"url":"https://github.com/tj/es","last_synced_at":"2025-08-03T21:39:11.021Z","repository":{"id":65993653,"uuid":"93097215","full_name":"tj/es","owner":"tj","description":"Go DSL for Elasticsearch queries","archived":false,"fork":false,"pushed_at":"2017-06-02T02:49:32.000Z","size":19,"stargazers_count":207,"open_issues_count":5,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T11:51:21.340Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tj.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-01T20:34:45.000Z","updated_at":"2024-01-09T09:49:38.000Z","dependencies_parsed_at":"2023-04-04T05:17:54.962Z","dependency_job_id":null,"html_url":"https://github.com/tj/es","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"beb609de831b254ce406d5d9b23ef65dbaf652c4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tj","download_url":"https://codeload.github.com/tj/es/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788135,"owners_count":21161721,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-01T12:57:25.038Z","updated_at":"2025-04-13T21:34:21.282Z","avatar_url":"https://github.com/tj.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ES\n\nPackage es provides an Elasticsearch query DSL.\n\n## About\n\nThe use of Go \"dot imports\" is discouraged, however I'd recommend abstracting this logic into higher level query functions and packages if you'd like to utilize the expressiveness of dot imports in this scenario. I wouldn't recommend dot-importing it into other packages directly.\n\n## Example\n\n### Lispy\n\nIf you don't mind crazy nesting:\n\n```go\nquery := Pretty(Query(\n  Aggs(\n    Agg(\"results\",\n      Filter(\n        Term(\"user.login\", \"tj\"),\n        Range(\"now-7d\", \"now\"),\n      )(\n        Aggs(\n          Agg(\"repos\",\n            Terms(\"repository.name.keyword\", 100),\n            Aggs(\n              Agg(\"labels\",\n                Terms(\"issue.labels.keyword\", 100),\n                Aggs(\n                  Agg(\"duration_sum\", Sum(\"duration\"))))))))))))\n```\n\n### Less lispy\n\nIf you do mind crazy nesting:\n\n```go\nlabels := Aggs(\n  Agg(\"labels\",\n    Terms(\"issue.labels.keyword\", 100),\n    Aggs(\n      Agg(\"duration_sum\",\n        Sum(\"duration\")))))\n\nrepos := Aggs(\n  Agg(\"repos\",\n    Terms(\"repository.name.keyword\", 100),\n    labels))\n\nfilter := Filter(\n  Term(\"user.login\", \"tj\"),\n  Range(\"now-7d\", \"now\"))\n\nresults := Aggs(\n  Agg(\"results\",\n    filter(repos)))\n\nquery := Pretty(Query(results))\n```\n\nBoth yielding:\n\n```json\n{\n  \"aggs\": {\n    \"results\": {\n      \"aggs\": {\n        \"repos\": {\n          \"aggs\": {\n            \"labels\": {\n              \"aggs\": {\n                \"duration_sum\": {\n                  \"sum\": {\n                    \"field\": \"duration\"\n                  }\n                }\n              },\n              \"terms\": {\n                \"field\": \"issue.labels.keyword\",\n                \"size\": 100\n              }\n            }\n          },\n          \"terms\": {\n            \"field\": \"repository.name.keyword\",\n            \"size\": 100\n          }\n        }\n      },\n      \"filter\": {\n        \"bool\": {\n          \"filter\": [\n            {\n              \"term\": {\n                \"user.login\": \"tj\"\n              }\n            },\n            {\n              \"range\": {\n                \"timestamp\": {\n                  \"gte\": \"now-7d\",\n                  \"lte\": \"now\"\n                }\n              }\n            }\n          ]\n        }\n      }\n    }\n  },\n  \"size\": 0\n}\n```\n\n### Reuse\n\nThis also makes reuse more trivial, for example note how `sum` is re-used in the following snippet to fetch global, daily, and label-level summation.\n\n```go\nsum := Agg(\"duration_sum\", Sum(\"duration\"))\n\nlabels := Agg(\"labels\",\n  Terms(\"issue.labels.keyword\", 100),\n  Aggs(sum))\n\ndays := Agg(\"days\",\n  DateHistogram(\"1d\"),\n  Aggs(sum, labels))\n\nquery := Query(Aggs(sum, labels, days))\n```\n\nYielding:\n\n```json\n{\n  \"aggs\": {\n    \"days\": {\n      \"aggs\": {\n        \"duration_sum\": {\n          \"sum\": {\n            \"field\": \"duration\"\n          }\n        },\n        \"labels\": {\n          \"aggs\": {\n            \"duration_sum\": {\n              \"sum\": {\n                \"field\": \"duration\"\n              }\n            }\n          },\n          \"terms\": {\n            \"field\": \"issue.labels.keyword\",\n            \"size\": 100\n          }\n        }\n      },\n      \"date_histogram\": {\n        \"field\": \"timestamp\",\n        \"interval\": \"1d\"\n      }\n    },\n    \"duration_sum\": {\n      \"sum\": {\n        \"field\": \"duration\"\n      }\n    },\n    \"labels\": {\n      \"aggs\": {\n        \"duration_sum\": {\n          \"sum\": {\n            \"field\": \"duration\"\n          }\n        }\n      },\n      \"terms\": {\n        \"field\": \"issue.labels.keyword\",\n        \"size\": 100\n      }\n    }\n  },\n  \"size\": 0\n}\n```\n\n---\n\n[![GoDoc](https://godoc.org/github.com/tj/es?status.svg)](https://godoc.org/github.com/tj/es)\n![](https://img.shields.io/badge/license-MIT-blue.svg)\n![](https://img.shields.io/badge/status-experimental-orange.svg)\n\n\u003ca href=\"https://apex.sh\"\u003e\u003cimg src=\"http://tjholowaychuk.com:6000/svg/sponsor\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftj%2Fes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fes/lists"}