# Get value of a list

**URL:** <https://discuss.elastic.co/t/get-value-of-a-list/68265>\
**Category:** Elasticsearch\
**Created:** [December 7, 2016, 8:57am UTC](https://discuss.elastic.co/t/get-value-of-a-list/68265 "2016-12-07T08:57:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![minniek](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@minniek](https://discuss.elastic.co/u/minniek)\
**Post date:** [December 7, 2016, 8:57am UTC](https://discuss.elastic.co/t/get-value-of-a-list/68265/1 "2016-12-07T08:57:15Z")

</div>

Hello everyone,  
I would like to create a query wich match with a scpecific date and take the price to divide it between the sqm field.  
In other words,lets imagine that I have this doc  
....  
"historic": [{ "date": "2016-10-30","price": 161000, "sqm":54}, { "date": "2016-05-30","price": 113000, "sqm":55}]  
....

So I would like to look for "date": "2016-05-30" and take its price / sqm = 113000/55 --\> and put it in another variable. I know how to do the match but I guess that I need a Script formula in order to get the avg amount,

Any ideas? Thanks to all

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 7, 2016, 12:59pm UTC](https://discuss.elastic.co/t/get-value-of-a-list/68265/2 "2016-12-07T12:59:00Z")

</div>

Hey,

while you might be able to use a [script field](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-request-script-fields.html) - I would highly recommend you to do that calculation at index, for example you could use a [script processor](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/script-processor.html) for that. This means you document will be enriched with that field before it is being indexed.

--Alex

---

<div class="post-metadata">

**Author:** ![minniek](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@minniek](https://discuss.elastic.co/u/minniek)\
**Post date:** [December 9, 2016, 9:14am UTC](https://discuss.elastic.co/t/get-value-of-a-list/68265/3 "2016-12-09T09:14:46Z")

</div>

I am using an aggregation and the agg /sum got the amount that I set in the match by itself (awesome) . Unfortunately, It doesnt happen when I use a simple match (without agg) so I created a for loop in order to get the value that I am looking for.

---

<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, 2017, 9:15am UTC](https://discuss.elastic.co/t/get-value-of-a-list/68265/4 "2017-01-06T09:15:01Z")

</div>

Closed on January 6, 2017, 9:15am UTC

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