{"id":13153,"library":"esq","title":"ESQ (Elasticsearch Query) Builder","description":"ESQ (Elasticsearch Query) is a JavaScript library designed to simplify the construction of Elasticsearch queries by providing a programmatic API to build complex JSON query objects. Its primary function is to abstract away the repetitive object creation inherent in crafting Elasticsearch DSL, allowing developers to focus on the query logic rather than the structural boilerplate. The current stable version is 1.0.0, which was last updated in April 2016. The project appears to be abandoned, with no significant updates or maintenance activity since then. It differentiates itself by offering a concise, chainable syntax for deeply nested query structures, making it easier to read and write complex queries compared to manual JSON object manipulation.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"http://github.com/holidayextras/esq","tags":["javascript","elasticsearch","esq","querying","queries","query","elastic","search","dsl"],"install":[{"cmd":"npm install esq","lang":"bash","label":"npm"},{"cmd":"yarn add esq","lang":"bash","label":"yarn"},{"cmd":"pnpm add esq","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESQ is a CommonJS-only library. ESM imports are not supported and will result in errors.","wrong":"import ESQ from 'esq'; // ESQ is CJS-only\nimport { ESQ } from 'esq'; // ESQ is CJS-only","symbol":"ESQ","correct":"const ESQ = require('esq');\nconst esq = new ESQ();"},{"note":"When included via a script tag in a browser, ESQ exposes itself as a global constructor function.","symbol":"ESQ (Browser Global)","correct":"// In browser, after <script src=\"esq.js\"></script>\nconst esq = new ESQ();"},{"note":"The `query` method is the primary API for building nested query structures, accepting strings for path segments and an array to create array nodes.","symbol":"esq.query","correct":"esq.query('bool', ['must'], { match: { user: 'kimchy' } });"}],"quickstart":{"code":"const ESQ = require('esq');\n\nconst esq = new ESQ();\n\n// Build a boolean query with a 'must' clause\nesq.query('bool', ['must'], { match: { user: 'kimchy' } });\n\n// Add a minimum_should_match to the same boolean query\nesq.query('bool', 'minimum_should_match', 1);\n\n// Add another 'should' clause to the existing boolean query\nesq.query('bool', ['should'], { term: { status: 'active' } });\n\n// Get the final query object\nconst query = esq.getQuery();\n\nconsole.log(JSON.stringify(query, null, 2));\n\n/*\nExpected output:\n{\n  \"bool\": {\n    \"must\": [\n      {\n        \"match\": {\n          \"user\": \"kimchy\"\n        }\n      }\n    ],\n    \"minimum_should_match\": 1,\n    \"should\": [\n      {\n        \"term\": {\n          \"status\": \"active\"\n        }\n      }\n    ]\n  }\n}\n*/","lang":"javascript","description":"Demonstrates how to initialize ESQ and incrementally build a complex boolean Elasticsearch query object."},"warnings":[{"fix":"Consider using more actively maintained Elasticsearch query builders or manually constructing query DSL for modern applications.","message":"The ESQ project appears to be abandoned. The last update was in April 2016, and there has been no significant maintenance, new features, or bug fixes since then. Use with caution for new projects.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your project uses CommonJS (`require()`) when importing ESQ, or use a bundler that transpiles CommonJS to ESM if absolutely necessary (e.g., for browser builds).","message":"ESQ is a CommonJS-only library and does not officially support ES Modules (ESM). Attempting to import it using `import` statements in an ESM context will result in errors.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Create a `declarations.d.ts` file with `declare module 'esq';` or more specific types if needed. Alternatively, disable type checking for ESQ imports.","message":"The library does not ship with TypeScript declaration files (.d.ts). Integrating ESQ into a TypeScript project will require creating manual type declarations or using `@ts-ignore`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are importing ESQ using CommonJS syntax: `const ESQ = require('esq');`. If in a browser, ensure the `esq.js` script is loaded before `new ESQ()` is called.","cause":"Attempting to instantiate ESQ after an incorrect ESM import (e.g., `import ESQ from 'esq';`) where `ESQ` might resolve to `undefined` or the module object itself, or when a bundler fails to correctly expose the default export.","error":"TypeError: ESQ is not a constructor"},{"fix":"Run your application in a Node.js environment configured for CommonJS, or use a build tool (like Webpack or Rollup) that can transpile CommonJS modules for ESM or browser environments.","cause":"This error occurs when trying to use `require('esq')` in an environment that only supports ES Modules natively (e.g., Node.js with `\"type\": \"module\"` or modern browsers without a CJS transpiler).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}