Accessing fields in last_doc scripted metric aggregation in a transform

If I have implemented this last_doc scripted metric aggregation in a transform example, how could I access fields within the returned doc (let's imagine there is a field "price" in the last_doc), in bucket script metric in the same transform, for instance,


          "example": {
            "bucket_script": {
              "buckets_path": {
                "last_price": "last_doc.price",
[...]

scripted metric aggregationedit

thanks
Mark

here is the last_doc scripted metric example/documentation

Not exactly on the topic, but have you tried using latest transform instead of pivot transform for your use-case?

https://www.elastic.co/blog/how-to-use-transforms-to-track-your-most-recent-customer-orders

Yes the latest transform is a helpful tool, for sure.

But do you know it you can add additional metrics like bucket scripts to do further calculations against the latest doc?

And also, I use the scripted metrics to pull >1 indexes data into a single transform destination doc... Do you know if you can do that with the latest transform, i.e. have the transform combine the docs from >1 index in the transform output? That would definitely be helpful to me.

But do you know it you can add additional metrics like bucket scripts to do further calculations against the latest doc?

Not directly within transform config, but maybe you could implement ingest pipeline that does it and attach it to the destination index using [dest.pipeline](https://But do you know it you can add additional metrics like bucket scripts to do further calculations against the latest doc?) setting?

i.e. have the transform combine the docs from >1 index in the transform output?

Yes, you can specify more than 1 source index in the transform configuration (see source.index).
latest transform then "combines" them by taking the latest document (from one of the indices) with the given unique_key.

Hi thanks. Yeah an ingest pipeline could suffice for some simple calcs. Thanks!

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