# Maximum value of an inexed field

**URL:** <https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215>\
**Category:** Elasticsearch\
**Created:** [August 14, 2013, 4:54pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215 "2013-08-14T16:54:21Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [August 14, 2013, 4:54pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/1 "2013-08-14T16:54:21Z")

</div>

Hi,

I was wondering what is the best way to get the maximum value of an indexed  
field?  
For example I have a document with a field named "localTime" and i want to  
take the maximum value of that field. Is the only way to do that the  
StatisticsFacet getMax method? Can somehow filter the results to return to  
me the document(s) that have this maximum value and then get the field I  
want?

Thank you

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [August 14, 2013, 4:58pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/2 "2013-08-14T16:58:59Z")

</div>

You may want to have a look at statistical facets. They are building an  
aggregation module but I don't believe it has been finished or released.

Nik

On Wed, Aug 14, 2013 at 12:54 PM, Thomas [thomas.bolis@gmail.com](mailto:thomas.bolis@gmail.com) wrote:

> Hi,
> 
> I was wondering what is the best way to get the maximum value of an  
> indexed field?  
> For example I have a document with a field named "localTime" and i want to  
> take the maximum value of that field. Is the only way to do that the  
> StatisticsFacet getMax method? Can somehow filter the results to return to  
> me the document(s) that have this maximum value and then get the field I  
> want?
> 
> Thank you
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 14, 2013, 7:09pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/3 "2013-08-14T19:09:09Z")

</div>

instead of faceting you can just do a reverse sort on that field?

simon

On Wednesday, August 14, 2013 6:58:59 PM UTC+2, Nikolas Everett wrote:

> You may want to have a look at statistical facets. They are building an  
> aggregation module but I don't believe it has been finished or released.
> 
> Nik
> 
> On Wed, Aug 14, 2013 at 12:54 PM, Thomas \<[thomas...@gmail.com](mailto:thomas...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > I was wondering what is the best way to get the maximum value of an  
> > indexed field?  
> > For example I have a document with a field named "localTime" and i want  
> > to take the maximum value of that field. Is the only way to do that the  
> > StatisticsFacet getMax method? Can somehow filter the results to return to  
> > me the document(s) that have this maximum value and then get the field I  
> > want?
> > 
> > Thank you
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [August 16, 2013, 11:21pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/4 "2013-08-16T23:21:05Z")

</div>

Hi,

Thanks for the replies, very helpful! I was thinking the solution of the  
reverse sorting, but I was wondering how fast n' efficient is this?  
probably will go that direction (sorting) till the new feature Nik is  
mentioning will be released..

T.

On 08/14/2013 10:09 PM, simonw wrote:

> instead of faceting you can just do a reverse sort on that field?
> 
> simon
> 
> On Wednesday, August 14, 2013 6:58:59 PM UTC+2, Nikolas Everett wrote:
> 
> ```
> You may want to have a look at statistical facets. They are
> building an aggregation module but I don't believe it has been
> finished or released.
> 
> Nik
> 
> On Wed, Aug 14, 2013 at 12:54 PM, Thomas <thomas...@gmail.com
> <javascript:>> wrote:
> 
> Hi,
> 
> I was wondering what is the best way to get the maximum value
> of an indexed field?
> For example I have a document with a field named "localTime"
> and i want to take the maximum value of that field. Is the
> only way to do that the StatisticsFacet getMax method? Can
> somehow filter the results to return to me the document(s)
> that have this maximum value and then get the field I want?
> 
> Thank you
> -- 
> You received this message because you are subscribed to the
> Google Groups "elasticsearch" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to elasticsearc...@googlegroups.com
> <javascript:>.
> For more options, visit
> https://groups.google.com/groups/opt_out
> <https://groups.google.com/groups/opt_out>.
> 
> ```
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 17, 2013, 6:11am UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/5 "2013-08-17T06:11:16Z")

</div>

@Thomas, reverse sorting is likely as efficient as it gets even in the  
future. Aggregations will likely be slower.

simon

On Saturday, August 17, 2013 1:21:05 AM UTC+2, Thomas wrote:

> Hi,
> 
> Thanks for the replies, very helpful! I was thinking the solution of the  
> reverse sorting, but I was wondering how fast n' efficient is this?  
> probably will go that direction (sorting) till the new feature Nik is  
> mentioning will be released..
> 
> T.
> 
> On 08/14/2013 10:09 PM, simonw wrote:
> 
> instead of faceting you can just do a reverse sort on that field?
> 
> simon
> 
> On Wednesday, August 14, 2013 6:58:59 PM UTC+2, Nikolas Everett wrote:
> 
> > You may want to have a look at statistical facets. They are building an  
> > aggregation module but I don't believe it has been finished or released.
> > 
> > Nik
> > 
> > On Wed, Aug 14, 2013 at 12:54 PM, Thomas [thomas...@gmail.com](mailto:thomas...@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I was wondering what is the best way to get the maximum value of an  
> > > indexed field?  
> > > For example I have a document with a field named "localTime" and i want  
> > > to take the maximum value of that field. Is the only way to do that the  
> > > StatisticsFacet getMax method? Can somehow filter the results to return to  
> > > me the document(s) that have this maximum value and then get the field I  
> > > want?
> > > 
> > > ## Thank you
> > > 
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [August 19, 2013, 7:34am UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/6 "2013-08-19T07:34:37Z")

</div>

Hi,

Thanks guys!  
I contuinue with this and I implement the sort solution to get the maximum  
value but I note something else; in the results i try to get the max value  
returned of a date value like this:

java.util.Date max =  
response.getHits().getHits()[0].field(field.getName()).getValue();

But the value returned is always string, (I have also tryied to do it with  
a Long field). Is this correct? I note tha the signature of the getValue is

V getValue();

meaning tha should support my casting to Date since the field is declared  
as date field, or I'm missing something:

logDate: {  
"index": "analyzed",  
"format": "dateOptionalTime"  
"type": "date"  
}

Thank you in advance  
Tom

On Sat, Aug 17, 2013 at 9:11 AM, simonw  
[simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com)wrote:

> @Thomas, reverse sorting is likely as efficient as it gets even in the  
> future. Aggregations will likely be slower.
> 
> simon
> 
> On Saturday, August 17, 2013 1:21:05 AM UTC+2, Thomas wrote:
> 
> > Hi,
> > 
> > Thanks for the replies, very helpful! I was thinking the solution of the  
> > reverse sorting, but I was wondering how fast n' efficient is this?  
> > probably will go that direction (sorting) till the new feature Nik is  
> > mentioning will be released..
> > 
> > T.
> > 
> > On 08/14/2013 10:09 PM, simonw wrote:
> > 
> > instead of faceting you can just do a reverse sort on that field?
> > 
> > simon
> > 
> > On Wednesday, August 14, 2013 6:58:59 PM UTC+2, Nikolas Everett wrote:
> > 
> > > You may want to have a look at statistical facets. They are building an  
> > > aggregation module but I don't believe it has been finished or released.
> > > 
> > > Nik
> > > 
> > > On Wed, Aug 14, 2013 at 12:54 PM, Thomas [thomas...@gmail.com](mailto:thomas...@gmail.com) wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I was wondering what is the best way to get the maximum value of an  
> > > > indexed field?  
> > > > For example I have a document with a field named "localTime" and i want  
> > > > to take the maximum value of that field. Is the only way to do that the  
> > > > StatisticsFacet getMax method? Can somehow filter the results to return to  
> > > > me the document(s) that have this maximum value and then get the field I  
> > > > want?
> > > > 
> > > > ## Thank you
> > > > 
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to elasticsearc...@googlegroups.\*\*com.  
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > topic/elasticsearch/\*\*H9syKXvazH0/unsubscribe[https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe)  
> > > .  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > 
> > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > .
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [August 19, 2013, 8:10am UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/7 "2013-08-19T08:10:05Z")

</div>

Hi, I want to add a correction here, this is happening in the date field  
only i tried with other types of fields, and worked fine

On Mon, Aug 19, 2013 at 10:34 AM, Thomas Bolis [thomas.bolis@gmail.com](mailto:thomas.bolis@gmail.com)wrote:

> Hi,
> 
> Thanks guys!  
> I contuinue with this and I implement the sort solution to get the maximum  
> value but I note something else; in the results i try to get the max value  
> returned of a date value like this:
> 
> java.util.Date max =  
> response.getHits().getHits()[0].field(field.getName()).getValue();
> 
> But the value returned is always string, (I have also tryied to do it with  
> a Long field). Is this correct? I note tha the signature of the getValue is
> 
> V getValue();
> 
> meaning tha should support my casting to Date since the field is declared  
> as date field, or I'm missing something:
> 
> logDate: {  
> "index": "analyzed",  
> "format": "dateOptionalTime"  
> "type": "date"  
> }
> 
> Thank you in advance  
> Tom
> 
> On Sat, Aug 17, 2013 at 9:11 AM, simonw \<[simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com)
> 
> > wrote:
> 
> > @Thomas, reverse sorting is likely as efficient as it gets even in the  
> > future. Aggregations will likely be slower.
> > 
> > simon
> > 
> > On Saturday, August 17, 2013 1:21:05 AM UTC+2, Thomas wrote:
> > 
> > > Hi,
> > > 
> > > Thanks for the replies, very helpful! I was thinking the solution of the  
> > > reverse sorting, but I was wondering how fast n' efficient is this?  
> > > probably will go that direction (sorting) till the new feature Nik is  
> > > mentioning will be released..
> > > 
> > > T.
> > > 
> > > On 08/14/2013 10:09 PM, simonw wrote:
> > > 
> > > instead of faceting you can just do a reverse sort on that field?
> > > 
> > > simon
> > > 
> > > On Wednesday, August 14, 2013 6:58:59 PM UTC+2, Nikolas Everett wrote:
> > > 
> > > > You may want to have a look at statistical facets. They are building  
> > > > an aggregation module but I don't believe it has been finished or released.
> > > > 
> > > > Nik
> > > > 
> > > > On Wed, Aug 14, 2013 at 12:54 PM, Thomas [thomas...@gmail.com](mailto:thomas...@gmail.com) wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > I was wondering what is the best way to get the maximum value of an  
> > > > > indexed field?  
> > > > > For example I have a document with a field named "localTime" and i  
> > > > > want to take the maximum value of that field. Is the only way to do that  
> > > > > the StatisticsFacet getMax method? Can somehow filter the results to return  
> > > > > to me the document(s) that have this maximum value and then get the field I  
> > > > > want?
> > > > > 
> > > > > ## Thank you
> > > > > 
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to elasticsearc...@googlegroups.\*\*com.  
> > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > .
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > > topic/elasticsearch/\*\*H9syKXvazH0/unsubscribe[https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe)  
> > > > .  
> > > > To unsubscribe from this group and all its topics, send an email to  
> > > > elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > .
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [August 19, 2013, 5:05pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/8 "2013-08-19T17:05:39Z")

</div>

Finally, I wasn't able to figure this out.. A possible bug?

Thanks  
Tom

On Mon, Aug 19, 2013 at 11:10 AM, Thomas Bolis [thomas.bolis@gmail.com](mailto:thomas.bolis@gmail.com)wrote:

> Hi, I want to add a correction here, this is happening in the date field  
> only i tried with other types of fields, and worked fine
> 
> On Mon, Aug 19, 2013 at 10:34 AM, Thomas Bolis [thomas.bolis@gmail.com](mailto:thomas.bolis@gmail.com)wrote:
> 
> > Hi,
> > 
> > Thanks guys!  
> > I contuinue with this and I implement the sort solution to get the  
> > maximum value but I note something else; in the results i try to get the  
> > max value returned of a date value like this:
> > 
> > java.util.Date max =  
> > response.getHits().getHits()[0].field(field.getName()).getValue();
> > 
> > But the value returned is always string, (I have also tryied to do it  
> > with a Long field). Is this correct? I note tha the signature of the  
> > getValue is
> > 
> > V getValue();
> > 
> > meaning tha should support my casting to Date since the field is declared  
> > as date field, or I'm missing something:
> > 
> > logDate: {  
> > "index": "analyzed",  
> > "format": "dateOptionalTime"  
> > "type": "date"  
> > }
> > 
> > Thank you in advance  
> > Tom
> > 
> > On Sat, Aug 17, 2013 at 9:11 AM, simonw \<  
> > [simon.willnauer@elasticsearch.com](mailto:simon.willnauer@elasticsearch.com)\> wrote:
> > 
> > > @Thomas, reverse sorting is likely as efficient as it gets even in the  
> > > future. Aggregations will likely be slower.
> > > 
> > > simon
> > > 
> > > On Saturday, August 17, 2013 1:21:05 AM UTC+2, Thomas wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Thanks for the replies, very helpful! I was thinking the solution of  
> > > > the reverse sorting, but I was wondering how fast n' efficient is this?  
> > > > probably will go that direction (sorting) till the new feature Nik is  
> > > > mentioning will be released..
> > > > 
> > > > T.
> > > > 
> > > > On 08/14/2013 10:09 PM, simonw wrote:
> > > > 
> > > > instead of faceting you can just do a reverse sort on that field?
> > > > 
> > > > simon
> > > > 
> > > > On Wednesday, August 14, 2013 6:58:59 PM UTC+2, Nikolas Everett wrote:
> > > > 
> > > > > You may want to have a look at statistical facets. They are building  
> > > > > an aggregation module but I don't believe it has been finished or released.
> > > > > 
> > > > > Nik
> > > > > 
> > > > > On Wed, Aug 14, 2013 at 12:54 PM, Thomas [thomas...@gmail.com](mailto:thomas...@gmail.com) wrote:
> > > > > 
> > > > > > Hi,
> > > > > > 
> > > > > > I was wondering what is the best way to get the maximum value of an  
> > > > > > indexed field?  
> > > > > > For example I have a document with a field named "localTime" and i  
> > > > > > want to take the maximum value of that field. Is the only way to do that  
> > > > > > the StatisticsFacet getMax method? Can somehow filter the results to return  
> > > > > > to me the document(s) that have this maximum value and then get the field I  
> > > > > > want?
> > > > > > 
> > > > > > ## Thank you
> > > > > > 
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > send an email to elasticsearc...@googlegroups.\*\*com.  
> > > > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > > > .
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to a topic in the  
> > > > > Google Groups "elasticsearch" group.  
> > > > > To unsubscribe from this topic, visit [https://groups.google.com/d/](https://groups.google.com/d/)\*\*  
> > > > > topic/elasticsearch/\*\*H9syKXvazH0/unsubscribe[https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe)  
> > > > > .  
> > > > > To unsubscribe from this group and all its topics, send an email to  
> > > > > elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to a topic in the  
> > > > Google Groups "elasticsearch" group.  
> > > > To unsubscribe from this topic, visit  
> > > > [https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe](https://groups.google.com/d/topic/elasticsearch/H9syKXvazH0/unsubscribe).  
> > > > To unsubscribe from this group and all its topics, send an email to  
> > > > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [August 19, 2013, 5:10pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/9 "2013-08-19T17:10:52Z")

</div>

Finally, I wasn't able to figure this out.. A possible bug?

Thanks  
Tom

On Wednesday, August 14, 2013 7:54:21 PM UTC+3, Thomas wrote:

> Hi,
> 
> I was wondering what is the best way to get the maximum value of an  
> indexed field?  
> For example I have a document with a field named "localTime" and i want to  
> take the maximum value of that field. Is the only way to do that the  
> StatisticsFacet getMax method? Can somehow filter the results to return to  
> me the document(s) that have this maximum value and then get the field I  
> want?
> 
> Thank you

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 19, 2013, 6:36pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/10 "2013-08-19T18:36:23Z")

</div>

I am not sure I can follow you. What is a possible bug?

On Monday, August 19, 2013 7:10:52 PM UTC+2, Thomas wrote:

> Finally, I wasn't able to figure this out.. A possible bug?
> 
> Thanks  
> Tom
> 
> On Wednesday, August 14, 2013 7:54:21 PM UTC+3, Thomas wrote:
> 
> > Hi,
> > 
> > I was wondering what is the best way to get the maximum value of an  
> > indexed field?  
> > For example I have a document with a field named "localTime" and i want  
> > to take the maximum value of that field. Is the only way to do that the  
> > StatisticsFacet getMax method? Can somehow filter the results to return to  
> > me the document(s) that have this maximum value and then get the field I  
> > want?
> > 
> > Thank you

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [August 19, 2013, 7:11pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/11 "2013-08-19T19:11:14Z")

</div>

Hi Simonw,

Sorry for not explaining well,

What i mean is that i try to retrieve the value as a date but the actual  
value is of type string, having as a result a cast exception:

java.util.Date date =  
response.getHits().getHits()[0].field("logDate").getValue(); // Although in  
my mapping the field is of type date, the value returned is of type String

For other java types this works fine:

Double counter =  
response.getHits().getHits()[0].field("counter").getValue(); // Works fine

Does this makes sense?

thanks again  
T.

On Wednesday, 14 August 2013 19:54:21 UTC+3, Thomas wrote:

> Hi,
> 
> I was wondering what is the best way to get the maximum value of an  
> indexed field?  
> For example I have a document with a field named "localTime" and i want to  
> take the maximum value of that field. Is the only way to do that the  
> StatisticsFacet getMax method? Can somehow filter the results to return to  
> me the document(s) that have this maximum value and then get the field I  
> want?
> 
> Thank you

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [August 19, 2013, 9:15pm UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/12 "2013-08-19T21:15:18Z")

</div>

Unfortunately we can't return this as a date at this point. You have to  
parse the string back into a date. This is expected behavior.

simon

On Monday, August 19, 2013 9:11:14 PM UTC+2, Thomas wrote:

> Hi Simonw,
> 
> Sorry for not explaining well,
> 
> What i mean is that i try to retrieve the value as a date but the actual  
> value is of type string, having as a result a cast exception:
> 
> java.util.Date date =  
> response.getHits().getHits()[0].field("logDate").getValue(); // Although in  
> my mapping the field is of type date, the value returned is of type String
> 
> For other java types this works fine:
> 
> Double counter =  
> response.getHits().getHits()[0].field("counter").getValue(); // Works fine
> 
> Does this makes sense?
> 
> thanks again  
> T.
> 
> On Wednesday, 14 August 2013 19:54:21 UTC+3, Thomas wrote:
> 
> > Hi,
> > 
> > I was wondering what is the best way to get the maximum value of an  
> > indexed field?  
> > For example I have a document with a field named "localTime" and i want  
> > to take the maximum value of that field. Is the only way to do that the  
> > StatisticsFacet getMax method? Can somehow filter the results to return to  
> > me the document(s) that have this maximum value and then get the field I  
> > want?
> > 
> > Thank you

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Thomas\_Bolis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_bolis/32/700_2.png) [@Thomas\_Bolis](https://discuss.elastic.co/u/Thomas_Bolis)\
**Post date:** [August 20, 2013, 6:50am UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/13 "2013-08-20T06:50:26Z")

</div>

Thank you again for your help, yes this is the case I return it as a String  
and parse it back to Date

Tom

On Wednesday, August 14, 2013 7:54:21 PM UTC+3, Thomas wrote:

> Hi,
> 
> I was wondering what is the best way to get the maximum value of an  
> indexed field?  
> For example I have a document with a field named "localTime" and i want to  
> take the maximum value of that field. Is the only way to do that the  
> StatisticsFacet getMax method? Can somehow filter the results to return to  
> me the document(s) that have this maximum value and then get the field I  
> want?
> 
> Thank you

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:20am UTC](https://discuss.elastic.co/t/maximum-value-of-an-inexed-field/13215/14 "2017-07-06T02:20:36Z")

</div>


