{"_id":"@brandom/ts-elasticsearch","_rev":"1-ab80f2805ee645910ae6fb759eb7f516","name":"@brandom/ts-elasticsearch","dist-tags":{"latest":"1.4.0"},"versions":{"1.4.0":{"name":"@brandom/ts-elasticsearch","version":"1.4.0","license":"MIT","description":"Elasticsearch decorated by TypeScript","main":"./dist/index.js","types":"./dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/brandom/node-ts-elasticsearch.git"},"keywords":["elasticsearch","typescript","decorator"],"pre-commit":["lint"],"scripts":{"build":"tsc  -p tsconfig.json","lint":"tslint -c ./tslint.json -p ./tsconfig.json -t verbose","start":"echo 'Not runable' && exit 1","test":"jest --silent=false --config=jest.json","coverage":"npm test --coverage"},"devDependencies":{"@gojob/tslint-config":"^1.0.0","@types/elasticsearch":"^5.0.35","@types/jest":"^24.0.18","@types/node":"^12.7.7","coveralls":"^3.0.6","jest":"^24.9.0","prettier":"^1.18.2","ts-jest":"^24.1.0","ts-node":"^8.4.1","tslint":"^5.20.0","tslint-config-prettier":"^1.18.0","tslint-plugin-prettier":"^2.0.1","typescript":"^3.6.3"},"dependencies":{"@elastic/elasticsearch":"^7.3.0","reflect-metadata":"^0.1.13"},"gitHead":"c23b0b75b5faefade556bfd1729bc1fa8ffee650","bugs":{"url":"https://github.com/brandom/node-ts-elasticsearch/issues"},"homepage":"https://github.com/brandom/node-ts-elasticsearch#readme","_id":"@brandom/ts-elasticsearch@1.4.0","_nodeVersion":"12.10.0","_npmVersion":"6.11.3","dist":{"integrity":"sha512-g1A62jFhO5OP91p1X+oxCrzGeGlSWKmRQCHtlfcJS0fjJQfZXUXM/XmqbLbCBao6xCV8VZX+rC8c11IxvlCmOA==","shasum":"888f58cfc5c1609d19eb1c6b50aa2d0137d0d7dc","tarball":"https://registry.npmjs.org/@brandom/ts-elasticsearch/-/ts-elasticsearch-1.4.0.tgz","fileCount":84,"unpackedSize":187217,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdkOQrCRA9TVsSAnZWagAAyZ4P/j9e2NCrC5t/go93yItQ\noA6wtj6/jXozyN+H9NWc3ddCSavL0wliQ1i0IVEGcLFsZqqX5V42o5zbhT+H\nNlPOD53RnUo8+MjnOaYV5duPnTkZtGHfbzcSZvCZDncSrQYqJSIc+VbvFmJC\ncFzwUlKdP8CqfPdMifdKOHFE46LZ2iOJsmmlRVGpxsPvgX5vyHA4c8TE0WYj\ncwIgFzC04/IwGRyZmMRV3qrnkgI3P0ALf/cKDwNt0mab494LfVWd9DlbH9JC\nXpwLIwSnGCaobL6K4bRUmLvMNFdZEHeBydLnqUBQeq2el4z7CrlmrmTmj/9h\n9vJjZ67OjyOg2rR2uokA3Wu8cywlkhkzmoddQwGfWsRtspiBj+WQa/wD7DjX\nDNY6xcLuKpOes3xBdW1XjUG5SgrxMAVVJj+b3Tll/Z40Bsd3thsejkJac9qt\n0zb+/xUjLRGM6hsz0V+Zz+kXQHIkWe7zCiNx7Duy2+RoE5VQQ/N8PZvvnxVw\nHppIRbcLQ3HMx0scWpQXYS6YgpOWDK04g+uOBkfy77dr3QQUdG89sq/ndOkt\npvmryAzhdbAUyTLd8TmIGMQSggvoAMzkomLQgb8oF+lmSxaOB6qBUi8HRG8S\nsKo1cEJIpKDaC3Wk5xUHlZ379dW3zaDYqycwWrx+KXwPQgh+1jjK8oGd+BsZ\n1ZaE\r\n=Z440\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICb4ulh7I044b0DbjUH70H7d5rqPEbParzpzeBoKlR8/AiBkPD+3Z0BlhGcx0juWE+fdLUWhYdxozgXIp2R4U4Buog=="}]},"maintainers":[{"name":"brandom","email":"brandom.v@gmail.com"}],"_npmUser":{"name":"brandom","email":"brandom.v@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ts-elasticsearch_1.4.0_1569776683046_0.27325042947456435"},"_hasShrinkwrap":false}},"time":{"created":"2019-09-29T17:04:42.817Z","1.4.0":"2019-09-29T17:04:43.165Z","modified":"2022-04-04T20:25:11.429Z"},"maintainers":[{"name":"brandom","email":"brandom.v@gmail.com"}],"description":"Elasticsearch decorated by TypeScript","homepage":"https://github.com/brandom/node-ts-elasticsearch#readme","keywords":["elasticsearch","typescript","decorator"],"repository":{"type":"git","url":"git+https://github.com/brandom/node-ts-elasticsearch.git"},"bugs":{"url":"https://github.com/brandom/node-ts-elasticsearch/issues"},"license":"MIT","readme":"# @brandom/ts-elasticsearch\n\n[![travis build](https://img.shields.io/travis/gojob-1337/node-ts-elasticsearch.svg)](https://travis-ci.org/gojob-1337/node-ts-elasticsearch) [![Coverage Status](https://coveralls.io/repos/github/gojob-1337/node-ts-elasticsearch/badge.svg?branch=master)](https://coveralls.io/github/gojob-1337/node-ts-elasticsearch?branch=master)\n\n## About\n\nFork of @gojob/ts-elasticsearch to upgrade elasticsearch client and add new features.\n\n## NPM publish\n\n**To publish a new version of this package, you have to build the project before run `npm publish`.**\n\n## Description\n\nThe purpose of this library is to provide a decorated class approch to use the [elasticsearch](https://www.npmjs.com/package/elasticsearch) module.\n\n## Installation\n\n```\nnpm install @brandom/ts-elasticsearch\n```\n\n## Usage example\n\n```typescript\nimport { Field, Elasticsearch, Primary } from '@brandom/ts-elasticsearch';\n\n@Index()\nclass User {\n  @Primary()\n  @Field({ enabled: false})\n  id: string;\n\n  @Field('text') name: string;\n  @Field('integer') age: number;\n}\n\n// ...\n\nconst elasticsearch = new Elasticsearch({ host: 'http://192.168.99.100:9200' });\n\nawait elasticsearch.indices.create(User);\nawait elasticsearch.indices.putMapping(User);\n\nconst user = new User();\nuser.id = 'agent-1122';\nuser.name = 'Smith';\nuser.age = 33;\n\nawait elasticsearch.index(user);\n\nawait elasticsearch.indices.refresh(User);\n\nconst { documents } = elasticsearch.search(User, { body: { query: { match_all: {} } } });\n```\n\n## Documentation\n\n### Decorators\n\n#### decorator `@Index`\n\nKeep in mind that index [types are scheduled to be removed in Elasticsearch 8](https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html#_skipping_types_2).\n\nThis class decorator factory declares a new Elasticsearch index.\n\nBy default, it uses the class name as index (and type), but it can be overwritten.\n\nIndex settings may be added in the `settings` optional parameter.\n\n```typescript\n@Index({index: 'twt', settings: { number_of_shards: 3 } })\nclass Tweeter {}\n```\n\n#### decorator `@Primary`\n\nThis property decorator factory declares the class primary key which will be used as `_id` in Elasticsearch index. When not provided, Elasticsearch generates ids by it own.\n\n```typescript\n@Index()\nclass User {\n  @Primary()\n  @Field({ enabled: false})\n  id: string;\n\n  @Field('text') name: string;\n  @Field('integer') age: number;\n}\n```\n\n#### decorator `@Field`\n\nThis property decorator factory declares a new property in the current class.\n\nIt takes either a simple type as string or an elasticsearch mapping setting.\n\n```typescript\n@Index()\nclass User {\n  @Field('keyword') id: string;\n  @Field({ type: 'text', boost: 2 })name: string;\n  @Field('integer') age: number;\n}\n```\n\n##### Special case of object or nested (array of object)\n\nWhen dealing with object or nested, you have to declare a class with some fields declared. Notice in this case, the class in not decorated with `@Index`.\n\nObject example:\n\n```typescript\nclass Country {\n  @Field('text') name: string;\n}\n\n@Index()\nclass City {\n  @Field('text') name: string;\n  @Field({ object: Country })\n  country: Country;\n}\n```\n\nNested example:\n\n```typescript\nclass Follower {\n  @Field({ enabled: false}) name: string;\n  @Field({ enabled: false}) popularity: number;\n}\n\n@Index()\nclass User {\n  @Primary()\n  @Field({ enabled: false})\n  id: string;\n\n  @Field('text') name: string;\n\n  @Field({ nested: Follower })\n  followers: Follower[];\n}\n```\n\n### Elasticsearch class\n\nThis class provides main elasticsearch features directly usable with indexed classes.\n\n**The purpose of this library is not to override all official plugin features, but only those that are relevant for managing documents using classes.**\n\nWhen dealing with documents, you can either uses indexed class instances or literal object associated to their indexed class.\n\nThe examples presents in this chapter are based on this setup.\n\n```typescript\nimport { Field, Elasticsearch, Primary } from '@brandom/ts-elasticsearch';\n\nconst elasticsearch = new Elasticsearch({ host: 'http://192.168.99.100:9200' });\n\n@Index()\nclass User {\n  @Primary()\n  @Field({ enabled: false})\n  id: string;\n\n  @Field('text') name: string;\n  @Field('integer') age: number;\n}\n```\n\n#### Elasticsearch core\n\nInstanciate this class with an [IConfigOptions](#iconfigoptions) or an [official elasticsearch.Client](https://github.com/elastic/elasticsearch-js/blob/14.x/docs/configuration.asciidoc) instance.\n\n#### IConfigOptions\n\nIConfigOptions extends the official [client configuration option](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html).\n\nExtended options provided by IConfigOptions:\n\n   Name     |                                                   Type                                                    | Optional | Description\n:---------: | :-------------------------------------------------------------------------------------------------------: | :------: | -------------------------------\n  client    | [elasticsearch.Client](https://github.com/elastic/elasticsearch-js/blob/14.x/docs/configuration.asciidoc) |    X     | Official client instance to use\nindexPrefix |                                                  string                                                   |    X     | Prefix to set to all indices\n\n#### Core functions\n\nThe main class provides the main part of the [document API](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/docs.html) functions.\n\n- bulkIndex: Index an arary or a stream of documents ([bulk api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-bulk)\n- count: Count documents in the index ([count api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-count))\n- create: Add a new document to the index [create api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-create))\n- delete: Delete a document from the index [delete api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-delete))\n- get: Retrieve a document by its id [get api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-get))\n- getIndices: Return all Indexed classes\n- index: Add or update a document in the index [index api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-index))\n- search: Search documents in the index [search api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-search))\n- update: Update a document [update api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-update))\n\n#### Elasticsearch.indices\n\nThe indices provides the main part of the [document API](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices.html) functions.\n\n- create: Create an Index ([indice create api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-indices-create))\n- delete: Delete an Index ([indice delete api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-indices-delete))\n- exists: Check if an Index exists ([indice exists api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-indices-exists))\n- flush: Flush an Index ([indice flush api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-indices-flush))\n- putMapping: Put mapping of an Index ([indice putmapping api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-indices-putmapping))\n- refresh: Refresh an Index ([indice refresh api](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-indices-refresh))\n","readmeFilename":"README.md"}