{"id":24350146,"url":"https://github.com/simonjang/elastic-query","last_synced_at":"2025-03-12T03:30:12.447Z","repository":{"id":57150691,"uuid":"154333216","full_name":"SimonJang/elastic-query","owner":"SimonJang","description":"Lightweight JavaScript Query builder for ElasticSearch","archived":false,"fork":false,"pushed_at":"2018-12-21T13:47:08.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-11T00:33:33.326Z","etag":null,"topics":["elasticsearch","fluent-api","querybuilder","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimonJang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-23T13:30:12.000Z","updated_at":"2018-12-21T13:47:10.000Z","dependencies_parsed_at":"2022-08-31T23:50:34.189Z","dependency_job_id":null,"html_url":"https://github.com/SimonJang/elastic-query","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonJang%2Felastic-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonJang%2Felastic-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonJang%2Felastic-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonJang%2Felastic-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimonJang","download_url":"https://codeload.github.com/SimonJang/elastic-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243150487,"owners_count":20244396,"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":["elasticsearch","fluent-api","querybuilder","typescript"],"created_at":"2025-01-18T13:27:14.403Z","updated_at":"2025-03-12T03:30:12.381Z","avatar_url":"https://github.com/SimonJang.png","language":"TypeScript","readme":"# elastic-query [![Build Status](https://travis-ci.org/SimonJang/elastic-query.svg?branch=master)](https://travis-ci.org/SimonJang/elastic-query) [![codecov](https://codecov.io/gh/SimonJang/elastic-query/badge.svg?branch=master)](https://codecov.io/gh/SimonJang/elastic-query?branch=master)\n\n\u003e Lightweight query builder for ElasticSearch\n\n## Install\n\n\n```\n$ npm install elastic-query\n```\n\n\n## Usage\n\n```js\nconst elasticQuery = require('elastic-query');\n\nelasticQuery\n\t.term('user.name', 'Foobaruser')\n\t.build();\n```\n\n\n## API\n\nCurrently, this query builder is only compatible with ElasticSearch 6.x.\n\nThis query builder covers most of the basics of the [Query DSL](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html) and one compound query:\n\n- `match_all` [query] (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html)\n- `match_none` [query] (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html)\n- All the [Full text queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/full-text-queries.html)\n- All the [Term level queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/term-level-queries.html)\n- The `bool` [Compound query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)\n\nAnother important note is when you chain multiple queries, only the last query in the chain will be returned using `build()`. If you use `buildQueryArray()` then the query builder will return an array of `Query` objects.\n\nSummary:\n\n- `build()` creates a leaf query clause.\n- `buildQueryArray()` creates a collection of queries that can be used in a compound query clause like `bool`.\n\n## Build operations\n\n### `elasticQuery.build()`\n\nThis will create a leaf query of the last query operation performed on the query builder.\n\n### `elasticQuery.buildQueryArray()`\n\nThis will return an array of queries which can be used in compound queries.\n\n## Full Text Queries\n\n### `elasticQuery.matchAll()`\n\n### `elasticQuery.matchNone()`\n\n### `elasticQuery.match(field, value, [options])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\n#### options\n\nType: `Object`\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.matchPhrase(field, value, [options])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\n#### options\n\nType: `Object`\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.matchPhrasePrefix(field, value, [options])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\n#### options\n\nType: `Object`\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.multiMatch(fields, value, [options])`\n\n#### field\n\nType: `string[]`\n\nFields you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided fields.\n\n#### options\n\nType: `Object`\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.commonTerms(field, value, cutOff, [options])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\n#### cutoff\n\nType: `number`\n\n\u003e Terms are allocated to the high or low frequency groups based on the `cutoff_frequency`, which can be specified as an absolute frequency (\u003e=1) or as a relative frequency (0.0 .. 1.0).\n[source](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html)\n\n#### options\n\nType: `Object`\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.queryString(field, value, [options])`\n\n#### field\n\nType: `string` or `string[]`\n\nField(s) you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field(s).\n\n#### options\n\nType: `Object`\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.simpleQueryString(fields, value, [options])`\n\n#### fields\n\nType: `string[]`\n\nFields you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided fields.\n\n#### options\n\nType: `Object`\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html) of ElasticSearch for all the additional properties.\n\n## Term level Queries\n\n### `elasticQuery.term(fields, value)`\n\n#### fields\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.terms(field, values)`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### values\n\nType: `string[] | Object`\n\nValue you want to match with the provided field(s). Either an array of values you want to match the field with or options for terms lookup mechanism.\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.termsSet(field, [options])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### options\n\nType: `Object`\n\nAdditional query options.\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-set-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.range(field, values)`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### values\n\nType: `string[] | Object`\n\nValue you want to match with the provided field.\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.exists(field)`\n\n#### fields\n\nType: `string`\n\nField you want to check if it exists.\n\n### `elasticQuery.prefix(field, value, [boost])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\n#### boost\n\nType: `number`\n\nValue you want to match boost your query with.\n\n### `elasticQuery.wildcard(field, value, [boost])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\n#### boost\n\nType: `number`\n\nValue you want to match boost your query with.\n\n### `elasticQuery.regexp(field, value, [options])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\n#### options\n\nType: `Object`\n\nAdditional query options.\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.fuzzy(field, value, [options])`\n\n#### field\n\nType: `string`\n\nField you want to match.\n\n#### value\n\nType: `string`\n\nValue you want to match with the provided field.\n\n#### options\n\nType: `Object`\n\nAdditional query options.\n\nSee the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html) of ElasticSearch for all the additional properties.\n\n### `elasticQuery.type(type)`\n\n#### type\n\nType: `string`\n\nFilters documents matching the provided document / mapping type.\n\n### `elasticQuery.ids(values, [type])`\n\n#### values\n\nType: `string` or `string[]`\n\nFilters documents that only have the provided values as ids.\n\n#### type\n\nType: `string`\n\nFilters documents matching the provided document / mapping type.\n\n## Compound Queries\n\n### `elasticQuery.bool(options)`\n\n#### options\n\nType: `Object`\n\nBoolean search options\n\n##### options.must\n\nType: `Object[]`\n\n`must` clause, must be an array of queries.\n\n##### options.filter\n\nType: `Object[]`\n\n`filter` clause, must be an array of queries.\n\n##### options.should\n\nType: `Object[]`\n\n`should` clause, must be an array of queries.\n\n##### options.must_not\n\nType: `Object[]`\n\n`must_not` clause, must be an array of queries.\n\n##### options.boost\n\nType: `number`\n\nPercentage of boost to boost the query with.\n\n##### options.minimum_should_match\n\nType: `number`\n\n\u003e If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. This behavior may be explicitly controlled by settings the minimum_should_match parameter.\n[source](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)\n\n## License\n\nMIT © [Simon Jang](https://github.com/SimonJang)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonjang%2Felastic-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonjang%2Felastic-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonjang%2Felastic-query/lists"}