1

Is it possible to have my map reduce take advantage of the shard key on my collection and only query one shard for results instead of all shards?

If so lets work from the example here. If you change it as follows:

public class InvoicesAmountByDate : AbstractIndexCreationTask<Invoice, 

InvoicesAmountByDate.ReduceResult>
{
    public class ReduceResult
    {
        public decimal Amount { get; set; }
        public DateTime IssuedAt { get; set; }
        public string CompanyId { get;set; } //<--- Does adding this mean we can target shard?
    }

    public InvoicesAmountByDate()
    {
        Map = invoices =>
              from invoice in invoices
              select new
              {
                  invoice.Amount,
                invoice.IssuedAt,
                invoice.CompanyId //<--- Does adding this mean we can target shard?
              };

        Reduce = results =>
                 from result in results
                 group result by result.IssuedAt
                 into g
                 select new
                 {
                     Amount = g.Sum(x => x.Amount),
                    IssuedAt = g.Key,
                    CompanyId = g.CompanyId //<--- Does adding this mean we can target shard?
                 };
    }
}

Is it possible to set up the map reduce to query invoice amounts by date and company. For example getting the amount by from March 14th, 2012 for only "Company 1" which should be on the Asia server so that only the Asia server is queried?

Ben Tidman
  • 2,129
  • 17
  • 30

1 Answers1

0

That is how it works by default, yes.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • Ayende, I am finally getting around to setting this up in my app and I am having trouble getting this to query just one server. When I query my map reduce I can see in the logs that it hits all three of my shards. Is there a special convention that I need to use in my id, shard strategy, or map/reduce so that ravendb knows what shard to query? – Ben Tidman Feb 26 '14 at 12:40
  • Do I have to have a shard strategy for the reduce result? – Ben Tidman Mar 01 '14 at 11:50