From bbd0f1157b0c722ed4b65a1ef3aef9eb351adc74 Mon Sep 17 00:00:00 2001 From: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Date: Tue, 27 Sep 2022 15:09:28 -0400 Subject: [PATCH] Refactors transform APIs (#1265) * Refactors transform APIs Signed-off-by: Fanit Kolchina * Refactors transform API Signed-off-by: Fanit Kolchina * Incorporates editorial feedback * Minor editing Signed-off-by: Fanit Kolchina Signed-off-by: Fanit Kolchina --- .../index-transforms/transforms-apis.md | 308 +++++++++++------- 1 file changed, 184 insertions(+), 124 deletions(-) diff --git a/_im-plugin/index-transforms/transforms-apis.md b/_im-plugin/index-transforms/transforms-apis.md index 43cff3ba..df9ff19f 100644 --- a/_im-plugin/index-transforms/transforms-apis.md +++ b/_im-plugin/index-transforms/transforms-apis.md @@ -18,57 +18,90 @@ Aside from using OpenSearch Dashboards, you can also use the REST API to create, Introduced 1.0 {: .label .label-purple } -Creates a transform job. +Creates a transform job. -**Sample Request** +### Request format ```json PUT _plugins/_transform/ +``` +### Path parameters + +Parameter | Data Type | Description +:--- | :--- | :--- +transform_id | String | Transform ID | + +### Request body fields + +You can specify the following options in the HTTP request body: + +Option | Data Type | Description | Required +:--- | :--- | :--- | :--- +enabled | Boolean | If true, the transform job is enabled at creation. | No +continuous | Boolean | Specifies whether the transform job should be continuous. Continuous jobs execute every time they are scheduled according to the `schedule` field and run based off of newly transformed buckets as well as any new data added to source indexes. Non-continuous jobs execute only once. Default is false. | No +schedule | Object | The schedule for the transform job. | Yes +start_time | Integer | The Unix epoch time of the transform job's start time. | Yes +description | String | Describes the transform job. | No +metadata_id | String | Any metadata to be associated with the transform job. | No +source_index | String | The source index containing the data to be transformed. | Yes +target_index | String | The target index the newly transformed data is added to. You can create a new index or update an existing one. | Yes +data_selection_query | Object | The query DSL to use to filter a subset of the source index for the transform job. See [query domain-specific language(DSL)]({{site.url}}{{site.baseurl}}/opensearch/query-dsl) for more information. | Yes +page_size | Integer | The number of buckets IM processes and indexes concurrently. A higher number results in better performance, but it requires more memory. If your machine runs out of memory, Index Management (IM) automatically adjusts this field and retries until the operation succeeds. | Yes +groups | Array | Specifies the grouping(s) to use in the transform job. Supported groups are `terms`, `histogram`, and `date_histogram`. For more information, see [Bucket Aggregations]({{site.url}}{{site.baseurl}}/opensearch/bucket-agg). | Yes if not using aggregations. +source_field | String | The field(s) to transform. | Yes +aggregations | Object | The aggregations to use in the transform job. Supported aggregations are `sum`, `max`, `min`, `value_count`, `avg`, `scripted_metric`, and `percentiles`. For more information, see [Metric Aggregations]({{site.url}}{{site.baseurl}}/opensearch/metric-agg). | Yes if not using groups. + +#### Sample Request + +The following request creates a transform job with the id `sample`: + +```json +PUT _plugins/_transform/sample { "transform": { - "enabled": true, - "continuous": true, - "schedule": { - "interval": { - "period": 1, - "unit": "Minutes", - "start_time": 1602100553 - } - }, - "description": "Sample transform job", - "source_index": "sample_index", - "target_index": "sample_target", - "data_selection_query": { - "match_all": {} - }, - "page_size": 1, - "groups": [ - { - "terms": { - "source_field": "customer_gender", - "target_field": "gender" - } + "enabled": true, + "continuous": true, + "schedule": { + "interval": { + "period": 1, + "unit": "Minutes", + "start_time": 1602100553 + } }, - { - "terms": { - "source_field": "day_of_week", - "target_field": "day" + "description": "Sample transform job", + "source_index": "sample_index", + "target_index": "sample_target", + "data_selection_query": { + "match_all": {} + }, + "page_size": 1, + "groups": [ + { + "terms": { + "source_field": "customer_gender", + "target_field": "gender" + } + }, + { + "terms": { + "source_field": "day_of_week", + "target_field": "day" + } + } + ], + "aggregations": { + "quantity": { + "sum": { + "field": "total_quantity" + } + } } - } - ], - "aggregations": { - "quantity": { - "sum": { - "field": "total_quantity" - } - } - } } } ``` -**Sample Response** +#### Sample Response ```json { @@ -125,35 +158,47 @@ PUT _plugins/_transform/ } } ``` -You can specify the following options in the HTTP request body: - -Option | Data Type | Description | Required -:--- | :--- | :--- | :--- -enabled | Boolean | If true, the transform job is enabled at creation. | No -continuous | Boolean | Specifies whether the transform job should be continuous. Continuous jobs execute every time they are scheduled according to the `schedule` field and run based off of newly transformed buckets, as well as any new data added to source indexes. Non-continuous jobs execute only once. Default is false. | No -schedule | Object | The schedule the transform job runs on. | Yes -start_time | Integer | The Unix epoch time of the transform job's start time. | Yes -description | String | Describes the transform job. | No -metadata_id | String | Any metadata to be associated with the transform job. | No -source_index | String | The source index whose data to transform. | Yes -target_index | String | The target index the newly transformed data is added into. You can create a new index or update an existing one. | Yes -data_selection_query | Object | The query DSL to use to filter a subset of the source index for the transform job. See [query DSL]({{site.url}}{{site.baseurl}}/opensearch/query-dsl) for more information. | Yes -page_size | Integer | The number of buckets IM processes and indexes concurrently. Higher number means better performance but requires more memory. If your machine runs out of memory, IM automatically adjusts this field and retries until the operation succeeds. | Yes -groups | Array | Specifies the grouping(s) to use in the transform job. Supported groups are `terms`, `histogram`, and `date_histogram`. For more information, see [Bucket Aggregations]({{site.url}}{{site.baseurl}}/opensearch/bucket-agg). | Yes if not using aggregations -source_field | String | The field(s) to transform | Yes -aggregations | Object | The aggregations to use in the transform job. Supported aggregations are: `sum`, `max`, `min`, `value_count`, `avg`, `scripted_metric`, and `percentiles`. For more information, see [Metric Aggregations]({{site.url}}{{site.baseurl}}/opensearch/metric-agg). | Yes if not using groups ## Update a transform job Introduced 1.0 {: .label .label-purple } -Updates a transform job if `transform_id` already exists. +Updates the transform job if `transform_id` already exists. For this request you must specify the sequence number and primary term of the transform to be updated. To get these, use the [Get a transform job's details](#get-a-transform-jobs-details) API call. -**Sample Request** +### Request format ```json -PUT _plugins/_transform/ +PUT _plugins/_transform/?if_seq_no=&if_primary_term= +``` +### Query parameters + +The update operation supports the following query parameters: + +Parameter | Description | Required +:---| :--- | :--- +`seq_no` | Only perform the transform operation if the last operation that changed the transform job has the specified sequence number. | Yes +`primary_term` | Only perform the transform operation if the last operation that changed the transform job has the specified sequence term. | Yes + +### Request body fields + +You can update the following fields. + +Option | Data Type | Description +:--- | :--- | :--- +schedule | Object | The schedule for the transform job. Contains the fields `interval.start_time`, `interval.period`, and `interval.unit`. +start_time | Integer | The Unix epoch start time of the transform job. +period | Integer | How often to execute the transform job. +unit | String | The unit of time associated with the execution period. Available options are `Minutes`, `Hours`, and `Days`. +description | Integer | Describes the transform job. +page_size | Integer | The number of buckets IM processes and indexes concurrently. A higher number results in better performance, but it requires more memory. If your machine runs out of memory, IM automatically adjusts this field and retries until the operation succeeds. + +#### Sample Request + +The following request updates a transform job with the id `sample`, sequence number `13`, and primary term `1`: + +```json +PUT _plugins/_transform/sample?if_seq_no=13&if_primary_term=1 { "transform": { "enabled": true, @@ -196,37 +241,26 @@ PUT _plugins/_transform/ } ``` -**Sample Response** +#### Sample Response ```json +PUT _plugins/_transform/sample?if_seq_no=13&if_primary_term=1 { - "_id": "sample", - "_version": 2, - "_seq_no": 14, - "_primary_term": 1, "transform": { - "transform_id": "sample", - "schema_version": 7, + "enabled": true, "schedule": { "interval": { - "start_time": 1602100553, "period": 1, - "unit": "Minutes" + "unit": "Minutes", + "start_time": 1602100553 } }, - "metadata_id": null, - "updated_at": 1621889843874, - "enabled": true, - "enabled_at": 1621889843874, "description": "Sample transform job", "source_index": "sample_index", - "data_selection_query": { - "match_all": { - "boost": 1.0 - } - }, "target_index": "sample_target", - "roles": [], + "data_selection_query": { + "match_all": {} + }, "page_size": 1, "groups": [ { @@ -253,37 +287,27 @@ PUT _plugins/_transform/ } ``` -The Update operation supports the following URL parameters: - -Parameter | Description | Required -:---| :--- | :--- -`if_seq_no` | Only perform the transform operation if the last operation that changed the transform job has the specified sequence number. | Yes -`if_primary_term` | Only perform the transform operation if the last operation that changed the transform job has the specified sequence term. | Yes - -You can update the following fields: - -Option | Data Type | Description -:--- | :--- | :--- -schedule | Object | The schedule the transform job runs on. Contains the fields `interval.start_time`, `interval.period`, and `interval.unit`. -start_time | Integer | The Unix epoch start time of the transform job. -period | Integer | How often to execute the transform job. -unit | String | The unit of time associated with the execution period. Available options are `Minutes`, `Hours`, and `Days`. -description | Integer | Describes the transform job. -page_size | Integer | The number of buckets IM processes and indexes concurrently. Higher number means better performance but requires more memory. If your machine runs out of memory, IM automatically adjusts this field and retries until the operation succeeds. - ## Get a transform job's details Introduced 1.0 {: .label .label-purple } -Returns a transform job's details. +Returns a transform job's details. -**Sample Request** +### Request format ```json GET _plugins/_transform/ ``` -**Sample Response** +#### Sample Request + +The following request returns the details of the transform job with the id `sample`: + +```json +GET _plugins/_transform/sample +``` + +#### Sample Response ```json { @@ -343,13 +367,15 @@ GET _plugins/_transform/ You can also get details of all transform jobs by omitting `transform_id`. -**Sample Request** +#### Sample Request + +The following request returns the details of all transform jobs: ```json GET _plugins/_transform/ ``` -**Sample Response** +#### Sample Response ```json { @@ -411,25 +437,27 @@ GET _plugins/_transform/ } ``` -You can specify these options as the `GET` API operation’s URL parameters to filter results: +### Query parameters + +You can specify the following GET API operation’s query parameters to filter the results. Parameter | Description | Required :--- | :--- | :--- -from | The starting index to search from. Default is 0. | No -size | Specifies the amount of results to return. Default is 10. | No +from | The starting transform to return. Default is 0. | No +size | Specifies the number of transforms to return. Default is 10. | No search |The search term to use to filter results. | No sortField | The field to sort results with. | No sortDirection | Specifies the direction to sort results in. Can be `ASC` or `DESC`. Default is ASC. | No -For example, this request returns two results starting from the eighth index. +#### Sample Request -**Sample Request** +The following request returns two results starting from transform `8`: ```json GET _plugins/_transform?size=2&from=8 ``` -**Sample Response** +#### Sample Response ```json { @@ -545,15 +573,23 @@ GET _plugins/_transform?size=2&from=8 Introduced 1.0 {: .label .label-purple } -Transform jobs created using the API are automatically enabled, but if you ever need to enable a job, you can use the `start` API operation. +Transform jobs created using the API are automatically enabled, but if you ever need to enable a job, you can use the start API operation. -**Sample Request** +### Request format -```json +``` POST _plugins/_transform//_start ``` -**Sample Response** +#### Sample Request + +The following request starts the transform job with the ID `sample`: + +```json +POST _plugins/_transform/sample/_start +``` + +#### Sample Response ```json { @@ -565,15 +601,23 @@ POST _plugins/_transform//_start Introduced 1.0 {: .label .label-purple } -Stops/disables a transform job. +Stops a transform job. -**Sample Request** +### Request format -```json +``` POST _plugins/_transform//_stop ``` -**Sample Response** +#### Sample Request + +The following request stops the transform job with the ID `sample`: + +```json +POST _plugins/_transform/sample/_stop +``` + +#### Sample Response ```json { @@ -585,15 +629,23 @@ POST _plugins/_transform//_stop Introduced 1.0 {: .label .label-purple } -Returns the status and metadata of a transform job. +Returns the status and metadata of a transform job. -**Sample Request** +### Request format -```json +``` GET _plugins/_transform//_explain ``` -**Sample Response** +#### Sample Request + +The following request returns the details of the transform job with the ID `sample`: + +```json +GET _plugins/_transform/sample/_explain +``` + +#### Sample Response ```json { @@ -628,7 +680,7 @@ Introduced 1.0 Returns a preview of what a transformed index would look like. -**Sample Request** +#### Sample Request ```json POST _plugins/_transform/_preview @@ -675,7 +727,7 @@ POST _plugins/_transform/_preview } ``` -**Sample Response** +#### Sample Response ```json { @@ -713,15 +765,23 @@ POST _plugins/_transform/_preview Introduced 1.0 {: .label .label-purple } -Deletes a transform job. This operation does not delete the source or target indexes. +Deletes a transform job. This operation does not delete the source or target indexes. -**Sample Request** +### Request format -```json +``` DELETE _plugins/_transform/ ``` -**Sample Response** +#### Sample Request + +The following request deletes the transform job with the ID `sample`: + +```json +DELETE _plugins/_transform/sample +``` + +#### Sample Response ```json {