{"id":13721175,"url":"https://github.com/kuzzleio/computed-fields-plugin","last_synced_at":"2025-05-07T13:31:54.409Z","repository":{"id":71813068,"uuid":"149427497","full_name":"kuzzleio/computed-fields-plugin","owner":"kuzzleio","description":"Allow definition and usage of computed fields in documents","archived":true,"fork":false,"pushed_at":"2019-02-28T13:18:30.000Z","size":137,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-14T10:38:31.057Z","etag":null,"topics":["kuzzle","kuzzle-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kuzzleio.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-09-19T09:40:07.000Z","updated_at":"2023-01-27T20:45:39.000Z","dependencies_parsed_at":"2023-09-10T16:00:43.266Z","dependency_job_id":null,"html_url":"https://github.com/kuzzleio/computed-fields-plugin","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/kuzzleio%2Fcomputed-fields-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuzzleio%2Fcomputed-fields-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuzzleio%2Fcomputed-fields-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuzzleio%2Fcomputed-fields-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kuzzleio","download_url":"https://codeload.github.com/kuzzleio/computed-fields-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252886462,"owners_count":21819720,"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":["kuzzle","kuzzle-plugin"],"created_at":"2024-08-03T01:01:13.339Z","updated_at":"2025-05-07T13:31:53.993Z","avatar_url":"https://github.com/kuzzleio.png","language":"JavaScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Others"],"readme":"# kuzzle computed-fields plugin\n\n\u003c!-- TOC --\u003e\n\n- [kuzzle computed-fields plugin](#kuzzle-computed-fields-plugin)\n  - [Purpose](#purpose)\n  - [Usage](#usage)\n  - [Installing the plugin](#installing-the-plugin)\n  - [Computed fields management](#computed-fields-management)\n    - [Create a computed field](#create-a-computed-field)\n    - [List computed fields](#list-computed-fields)\n    - [Delete a computed field](#delete-a-computed-field)\n\n\u003c!-- /TOC --\u003e\n\n## Purpose\n\nThis plugin allows creating computed fields from a document's existing fields. For instance, considering the following document:\n\n```json\n{\n  \"name\": \"Michael\",\n  \"surname\": \"Romeo\"\n}\n```\n\nyou could have a computed field `fullname` defined as `\"${name} ${surname}\"` and whose value would be `\"Michael Romeo\"`.\n\nThe computed fileds are stored in a `_computedFields` object to avoid collision with document fields, so the final document will be:\n\n```json\n{\n  \"name\": \"Michael\",\n  \"surname\": \"Romeo\",\n  \"_computedFields\": {\n    \"fullname\": \"Michael Romeo\"\n  }\n}\n```\n\nA computed field is applied to documents in a given `collection` and is defined as follow:\n\n```json\n{\n  \"name\": \"myComputedField\",\n  \"value\": \"Here is my computed field using ${my_document_field} and ${a.nested.field}\"\n}\n```\n\n## Usage\n\n| Field   | Description       |\n| ------- | -- |\n| `name`  | This is the name by which it will be represented in the documents.   |\n| `value` | The computed field's `value` is a template string where you can insert document's field values using the `${fieldname}` syntax. Note that you are note limited to field at the root of the document, you can access insert nested property field using the classic `.` syntax: `${my.nested.field}` |\n\n**Note:** To avoid any collision with documents fields, all computed fields are nested in `_computedFields` object.\n\n## Installing the plugin\n\nClone this repository locally and make it accessible from the `plugins/enabled` directory relative to the Kuzzle installation directory. A common practice is to put the code of the plugin in `plugins/available` and create a symbolic link to it in `plugins/enabled`.\n\n**Note:** If you are running Kuzzle within a Docker container, you will need to mount the local plugin installation directory as a volume in the container.\n\nPlease refer to the Guide for further instructions on [how to install Kuzzle plugins](http://docs.kuzzle.io/guide/essentials/plugins/#managing-plugins).\n\n## Computed fields management\n\nOnce installed, the plugin exposes a new controller: `computedFields` c\n\nThe controller has de following actions:\n\n| Action      | Description                                                               |\n| ----------- | ------------------------------------------------------------------------- |\n| `create`    | Add or update a computed field to an `index/collection`                   |\n| `delete`    | Remove a computed field from an `index/collection`                        |\n| `list`      | List computed fields of an `index/collection`                             |\n| `recompute` | Recompute computed fields for all documents of a given `index/collection` |\n\n### Create a computed field\n\n**http**\n\nYou can create or update a computed field sending a http `POST` request to `http+https://\u003chost\u003e:\u003cport\u003e/_plugin/computed-fields/\u003cindex\u003e/\u003ccollection\u003e`\n\nFor example:\n\n```sh\n$ curl  localhost:7512/_plugin/computed-fields/myIndex/myCollection -H \"Content-Type: application/json\"\n-d '{\n  \"name\": \"myComputedField\",\n  \"value\": \"Here is my computed field using ${my_document_field} and ${a.nested.field}\"\n}'\n```\n\nResponse:\n\n```json\n{\n  \"requestId\": \"f0cef431-a642-41ba-98b5-c2f407f10bd1\",\n  \"status\": 200,\n  \"error\": null,\n  \"controller\": \"computed-fields/field\",\n  \"action\": \"create\",\n  \"collection\": \"myCollection\",\n  \"index\": \"myIndex\",\n  \"volatile\": null,\n  \"result\": {\n    \"_index\": \"%plugin:computed-fields\",\n    \"_type\": \"computedFields\",\n    \"_id\": \"myIndex-myCollection-myComputedField\",\n    \"_version\": 1,\n    \"result\": \"created\",\n    \"_shards\": {\n      \"total\": 2,\n      \"successful\": 1,\n      \"failed\": 0\n    },\n    \"created\": true,\n    \"_source\": {\n      \"name\": \"myComputedField\",\n      \"value\": \"Here is my computed field using ${my_document_field} and ${a.nested.field}\"\n    }\n  }\n}\n```\n\n**Using Kuzzle JS SDK**\n\nUsing the Kuzzle JS SDK, you can call controller actions using the `query` API:\n\n```javascript\n  kuzzle.queryPromise(\n    {\n      controller: 'computed-fields/computedFields',\n      action: 'create',\n      body: {\n      name: \"myComputedField\",\n      index: \"myIndex\",\n      collection: \"myCollection\",\n      value: \"Here is my computed field using ${my_document_field} and ${a.nested.field}\"\n    }\n  )\n```\n\n### List computed fields\n\nThe `list` action will return an array of computed fields for the given `index/collection`.\n\n```json\n[\n  { \"name\": \"aname\", \"value\": \"a template\" },\n  { \"name\": \"anotherone\", \"value\": \"another template\" }\n]\n```\n\n**http**\n\nSend a `GET` request to `http+https://\u003chost\u003e:\u003cport\u003e/_plugin/computed-fields/\u003cindex\u003e/\u003ccollection\u003e` to get computed fields list\n\n```sh\n$ curl  localhost:7512/_plugin/computed-fields/myIndex/myCollection\n```\n\nResponse:\n\n```json\n{\n  \"requestId\": \"43af0e90-7e4b-40d7-bae2-665a999e3152\",\n  \"status\": 200,\n  \"error\": null,\n  \"controller\": \"computed-fields/computedFields\",\n  \"action\": \"list\",\n  \"collection\": \"myCollection\",\n  \"index\": \"myIndex\",\n  \"volatile\": null,\n  \"result\": [\n    {\n      \"name\": \"another-computed-field\",\n      \"value\": \"A fake template\",\n      \"_id\": \"my-index-1-my-first-collection-another-computed-field\"\n    }\n  ]\n}\n```\n\n**Using Kuzzle JS SDK**\n\nUsing the Kuzzle JS SDK, you can call controller actions using the `query` API:\n\n```javascript\nkuzzle\n  .queryPromise({\n    controller: \"computed-fields/computedFields\",\n    action: \"list\"\n  })\n  .then(r =\u003e console.log(r.result));\n```\n\nOutputs:\n\n```sh\n[\n  {\n    \"name\": \"another-computed-field\",\n    \"index\": \"my-index-1\",\n    \"collection\": \"my-first-collection\",\n    \"value\": \"A fake template\",\n    \"_id\": \"my-index-1-my-first-collection-another-computed-field\"\n  }\n]\n```\n\n### Delete a computed field\n\nThe `delete` action allow one to remove a computed field.\n\n**http**\n\nSend a `DELETE` request to `http+https://\u003chost\u003e:\u003cport\u003e/_plugin/computed-fields/\u003cindex\u003e/\u003ccollection\u003e/\u003cname\u003e` to delete computed field named \\\u003cname\u003e \n\n```sh\n$ curl -X DELETE  localhost:7512/_plugin/computed-fields/my-index/my-first-collection/another-computed-field\n```\n\nResponse:\n\n```json\n{\n  \"requestId\": \"ab711c47-62f4-4bd0-b127-3e8012ca1135\",\n  \"status\": 200,\n  \"error\": null,\n  \"controller\": \"computed-fields/computedFields\",\n  \"action\": \"delete\",\n  \"collection\": \"my-collection\",\n  \"index\": \"my-index\",\n  \"volatile\": null\n}\n```\n\n**Using Kuzzle JS SDK**\n\nUsing the Kuzzle JS SDK, you can call controller actions using the `query`API:\n\n```javascript\nkuzzle.queryPromise({\n  controller: \"computed-fields/computedFields\",\n  action: \"delete\",\n  _id: \"my-index-1-my-first-collection-another-computed-field\"\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuzzleio%2Fcomputed-fields-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuzzleio%2Fcomputed-fields-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuzzleio%2Fcomputed-fields-plugin/lists"}