# Adding a synthetic field to documents generated by Transforms

**URL:** https://discuss.elastic.co/t/adding-a-synthetic-field-to-documents-generated-by-transforms/288014
**Category:** Elasticsearch
**Created:** [October 29, 2021, 3:29pm UTC](https://discuss.elastic.co/t/adding-a-synthetic-field-to-documents-generated-by-transforms/288014 "2021-10-29T15:29:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![romainneutron](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/romainneutron/32/96533_2.png) [@romainneutron](https://discuss.elastic.co/u/romainneutron)
#### Post date: [October 29, 2021, 3:29pm UTC](https://discuss.elastic.co/t/adding-a-synthetic-field-to-documents-generated-by-transforms/288014/1 "2021-10-29T15:29:36Z")

</div>

Hello,

I'm playing with Elastic Transforms ([Create transform API | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-transform.html))  
I have questions about those:

I've created a transform like this:

```auto
PUT _transform/transform_test_2s
{
  "source": {
    "index": "server"
  },
  "pivot": {
    "group_by": {
      "grain": {
        "date_histogram": {
          "field": "created_at",
          "fixed_interval": "2s"
        }
      }
    },
    "aggregations": {
      "avg": {
        "avg": {
          "field": "wt"
        }
      }
    }
  },
  "dest": {
    "index": "transform_test"
  },
  "frequency": "30s"
}

```

When I run it:

```auto
POST _transform/transform_test_2s/_start

```

I got that kind of output in the target index:

```auto
      {
        "_source" : {
          "avg" : 1095432.0,
          "grain" : "2021-10-02T08:44:02.000Z"
        }
      },
      {
        "_source" : {
          "avg" : 709561.0,
          "grain" : "2021-10-02T08:44:22.000Z"
        }
      }

```

I would like to add a second transform `transform_test_5s` that does the same thing with `"fixed_interval": "5s"` instead of 2s.  
The issue is that I would not be able to distinct records that have been generated by transform `transform_test_2s` or `transform_test_5s`

What I would like to have is :

```auto
      {
        "_source" : {
          "avg" : 1095432.0,
          "grain" : "2021-10-02T08:44:02.000Z",
          "used_period": "2s"
        }
      },
      {
        "_source" : {
          "avg" : 709561.0,
          "grain" : "2021-10-02T08:44:22.000Z",
          "used_period": "2s"
        }
      }

```

A way to achieve this is to use named aggregations like "grain\_2s", eg:

```auto
    "group_by": {
      "grain_2s": {
        "date_histogram": {
          "field": "created_at",
          "fixed_interval": "2s"
        }
      }
    },

```

When running with both transforms, it results in :

```auto
      {
        "_source" : {
          "grain_5s" : "2021-10-05T07:25:05.000Z",
          "avg" : 274935.0
        }
      },
      {
        "_source" : {
          "avg" : 621279.0,
          "grain_2s" : "2021-10-02T08:44:22.000Z"
        }
      }

```

The drawback is that it creates n+1 fields in the index (n is the number of transforms)

So it leads me to the question: is it possible to have multiple transforms that result in something like the following ? I would need a synthetic field defined in the transform like the "grain" one below.

```auto
      {
        "_source" : {
          "date" : "2021-10-05T07:25:05.000Z",
          "grain": "5s",
          "avg" : 274935.0
        }
      },
      {
        "_source" : {
          "date" : "2021-10-02T08:44:22.000Z",
          "grain": "2s",
          "avg" : 621279.0
        }
      }

```

Thanks,  
Romain

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 26, 2021, 3:29pm UTC](https://discuss.elastic.co/t/adding-a-synthetic-field-to-documents-generated-by-transforms/288014/2 "2021-11-26T15:29:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
