Most recent occurrence of a document

Hi

I am trying to build a query on an index which has 3 fields: name,
date and sum.
for a given name, I want to fetch the most recent (by date) occurrence
of that name, and get the sum field.

for example, if I have 2 docs:
"yehuda", "2012-02-20", "5"
"yehuda", "2012-02-19", "4"

I want to get "5".
The order of insertion is of course something I can't rely on.

Any suggestions?

Thanks!

Yehuda

Hi Yehuda,

You can execute a match all query and sort by the date field. Make
sure the mapping for the date field is correct (date, not string) and
that it is stored.

--
Ivan

On Mon, Feb 20, 2012 at 7:09 AM, Yehuda Zargarov yz1583@gmail.com wrote:

Hi

I am trying to build a query on an index which has 3 fields: name,
date and sum.
for a given name, I want to fetch the most recent (by date) occurrence
of that name, and get the sum field.

for example, if I have 2 docs:
"yehuda", "2012-02-20", "5"
"yehuda", "2012-02-19", "4"

I want to get "5".
The order of insertion is of course something I can't rely on.

Any suggestions?

Thanks!

Yehuda

Yea, just sort by date. It doesn't have to be stored, just indexed (which is the default).

On Tuesday, February 21, 2012 at 12:29 AM, Ivan Brusic wrote:

Hi Yehuda,

You can execute a match all query and sort by the date field. Make
sure the mapping for the date field is correct (date, not string) and
that it is stored.

--
Ivan

On Mon, Feb 20, 2012 at 7:09 AM, Yehuda Zargarov <yz1583@gmail.com (mailto:yz1583@gmail.com)> wrote:

Hi

I am trying to build a query on an index which has 3 fields: name,
date and sum.
for a given name, I want to fetch the most recent (by date) occurrence
of that name, and get the sum field.

for example, if I have 2 docs:
"yehuda", "2012-02-20", "5"
"yehuda", "2012-02-19", "4"

I want to get "5".
The order of insertion is of course something I can't rely on.

Any suggestions?

Thanks!

Yehuda

Sorting is an option, but when you have to get the last date result
for 600 users, it's not a very good one.

I mean, the example above is for 1 user. the real situation will be:

"yehuda", "2012-02-20", "5"
"yehuda", "2012-02-19", "4"
"Moshe", "2012-02-20", "5"
"Moshe", "2012-02-19", "4"
"Leon", "2012-02-20", "5"
"Leon", "2012-02-19", "4"
"Ben", "2012-02-20", "5"
"Ben", "2012-02-19", "4"
..

I need to sum up the values of the latest date of Yehuda, Moshe, Leon
and Ben..

Is there a more efficient way to do this?

Thanks

On Feb 24, 3:11 pm, Shay Banon kim...@gmail.com wrote:

Yea, just sort by date. It doesn't have to be stored, just indexed (which is the default).

On Tuesday, February 21, 2012 at 12:29 AM, Ivan Brusic wrote:

Hi Yehuda,

You can execute a match all query and sort by the date field. Make
sure the mapping for the date field is correct (date, not string) and
that it is stored.

--
Ivan

On Mon, Feb 20, 2012 at 7:09 AM, Yehuda Zargarov <yz1...@gmail.com (mailto:yz1...@gmail.com)> wrote:

Hi

I am trying to build a query on an index which has 3 fields: name,
date and sum.
for a given name, I want to fetch the most recent (by date) occurrence
of that name, and get the sum field.

for example, if I have 2 docs:
"yehuda", "2012-02-20", "5"
"yehuda", "2012-02-19", "4"

I want to get "5".
The order of insertion is of course something I can't rely on.

Any suggestions?

Thanks!

Yehuda