# How to generate candlesticks

**URL:** <https://discuss.elastic.co/t/how-to-generate-candlesticks/110927>\
**Category:** Elasticsearch\
**Created:** [December 9, 2017, 9:39am UTC](https://discuss.elastic.co/t/how-to-generate-candlesticks/110927 "2017-12-09T09:39:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandro2017](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@sandro2017](https://discuss.elastic.co/u/sandro2017)\
**Post date:** [December 9, 2017, 9:39am UTC](https://discuss.elastic.co/t/how-to-generate-candlesticks/110927/1 "2017-12-09T09:39:05Z")

</div>

i'm trying to add first element's property "open" and last element's property "close" to the inner aggregation.

The document looks as follows:

```
{ 
  "id": "1b73c03c-182e-4092-bf23-7fb6e2525586", 
  "assetId": 5, 
  "open": 143.345, 
  "close": 143.355, 
  "min": 143.335, 
  "max": 143.355, 
  "tS": "2017-04-10T18:24:00"
}

```

the query looks like this:

```
.Aggregations(a => a 
 .DateHistogram("bars", st => st 
   .Field(o => o.TS) 
   .Interval(interval) 
   .MinimumDocumentCount(2) 
   .Aggregations(childAggs => childAggs 
    .Min("min", avg => avg.Field(p => p.Min)) 
    .Max("max", avg => avg.Field(p => p.Max)) ) ) )

```

need to add aggregation for open which is first element's open property and aggregation for close which is last element's close property.

Does anyone have an idea how to do that?  
Thanks in advance

---

<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:** [January 6, 2018, 9:39am UTC](https://discuss.elastic.co/t/how-to-generate-candlesticks/110927/2 "2018-01-06T09:39:08Z")

</div>

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