# Combine different fields for percentile

**URL:** <https://discuss.elastic.co/t/combine-different-fields-for-percentile/303634>\
**Category:** Elasticsearch\
**Created:** [April 29, 2022, 9:50pm UTC](https://discuss.elastic.co/t/combine-different-fields-for-percentile/303634 "2022-04-29T21:50:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweeper42](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@sweeper42](https://discuss.elastic.co/u/sweeper42)\
**Post date:** [April 29, 2022, 9:50pm UTC](https://discuss.elastic.co/t/combine-different-fields-for-percentile/303634/1 "2022-04-29T21:50:03Z")

</div>

I have a situation where I have documents with multiple histogram fields. I would sometimes like to get the percentile of combined fields.  
Here is a sample mapping

```auto
PUT /t1
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "myDocId":{"type":"keyword"},
      "field_1": {
        "properties": {
          "histogram": {"type": "histogram"}
        }
      },
      "field_2": {
        "properties": {
          "histogram": {"type": "histogram"}
        }
      }
    }
  }
}

```

Here we can load a few documents

```auto
PUT t1/_doc/1
{
  "myDocId": "md_1",
  "field_1": {
    "histogram": {
      "values": [10,12,15,17,20],
      "counts": [3,7,23,12,6]
    }
  },
  "field_2": {
    "histogram": {
      "values": [21,23],
      "counts": [3,5]
    }
  }
}

PUT t1/_doc/2
{
  "myDocId": "md_2",
  "field_1": {
    "histogram": {
      "values": [21,23,24,26,28],
      "counts": [3,7,23,12,6]
    }
  },
  "field_2": {
    "histogram": {
      "values": [29,32],
      "counts": [3,5]
    }
  }
}

```

I know I can get the percentile of single doc field by grouping on myDocId or going across multiple documents on the same field like:

```auto
GET t1/_search
{
  "size": 0,
  "aggs": {
    "percentile_field1": {
      "percentiles": {
        "field": "field_1.histogram"
      }
    }
  }
}

```

But what I can't seem to get is combining field\_1 and field\_2 together to pass into the percentile agg. Any thoughts?  
thanks --

---

<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:** [May 27, 2022, 9:50pm UTC](https://discuss.elastic.co/t/combine-different-fields-for-percentile/303634/2 "2022-05-27T21:50:24Z")

</div>

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