Using Map-Reduce index with normal ones

86 views
Skip to first unread message

Shubha Lakshmi

unread,
Oct 13, 2017, 2:15:45 AM10/13/17
to RavenDB - 2nd generation document database
Is there any way to use Map-Reduce index for an entity along with some other index defined for the same entity , E.g: I have 2 indexes defined for Product (in NorthWind database) , one I use for regular querying, other one is Map-Reduce one which has 1 field as aggregate field (Group By Key). I want to know whether I can first put filters on IRavenQueryable<Product>  (i.e. IRavenQueryable<Product >.("MyIndex").Where(filters..))using regular index, and then use Map-Reduce index on it to get statistics on numerical fields.
TIA

Oren Eini (Ayende Rahien)

unread,
Oct 15, 2017, 2:57:05 AM10/15/17
to ravendb
You can first get the ids you want from the regular index, then use an IN to match the results from the other index.
Or you can include the fields you want to search by in the map/reduce.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


On Fri, Oct 13, 2017 at 9:15 AM, Shubha Lakshmi <shubh...@gmail.com> wrote:
Is there any way to use Map-Reduce index for an entity along with some other index defined for the same entity , E.g: I have 2 indexes defined for Product (in NorthWind database) , one I use for regular querying, other one is Map-Reduce one which has 1 field as aggregate field (Group By Key). I want to know whether I can first put filters on IRavenQueryable<Product>  (i.e. IRavenQueryable<Product >.("MyIndex").Where(filters..))using regular index, and then use Map-Reduce index on it to get statistics on numerical fields.
TIA

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shubha Lakshmi

unread,
Oct 16, 2017, 5:03:08 AM10/16/17
to RavenDB - 2nd generation document database
Thanks for your inputs Oren, I was not sure about making the fields on which dynamic filtering would be performed , part of Map Reduce index as they would vary from entity to entity, and would not have common values based on the aggregation criteria.  (Group By Key), while my understanding is we put only those fields in  Map Reduce Index which are either part of the key or summary (sum, min, max, average) fields, or have unique values per aggregation criteria, or the Grouping. ( E.g: g.First().MyField } Please correct me if I am wrong in my interpretation of Map Reduce indexes...
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Oct 16, 2017, 6:41:19 AM10/16/17
to ravendb
Yes, this is correct. If you first want to filter by something else, than you'll need two queries.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Shubha Lakshmi

unread,
Oct 16, 2017, 9:41:22 AM10/16/17
to RavenDB - 2nd generation document database
Thanks Oren, By using "IN" clause do you mean checking "Contains" , as in :

var results = session.Query<Product>().Search(t=>t.Name,"*ar*",escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards).Select(t=>t.Id);
var results1 = session.Query<Product>().Where(t=>results.Contains(t.Id));


But this throws a "Not Supported" exception :

Could not understand expression: .Where(t => value(UserQuery+<>c__DisplayClass0_0).results.Contains(t.Id))

Is there any other way to check for "Contains" / "IN" as you suggested.

Mrinal Kamboj

unread,
Oct 16, 2017, 2:28:44 PM10/16/17
to RavenDB - 2nd generation document database
I think this doesn't work since:

1. Raven DB doesn't support Contains operation. It will be search wild card operation.

2. Also not sure if you can supply IRavenQueryable<T> from one operation to another for cascading processing like this (Ideally that shall not be the issue, since its deferred execution), 1st point shall be the main reason.

Thanks,

Mrinal
Message has been deleted

Mircea Chirea

unread,
Oct 16, 2017, 4:26:17 PM10/16/17
to RavenDB - 2nd generation document database
Do this:

using Raven.Client.Linq;

var ids = session.Query<Product>().Search(t=>t.Name,"*ar*",escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards).Select(t=>t.Id).ToList();

var results = session.Query<Product>().Where(t=>t.Id.In(ids));

Mrinal Kamboj

unread,
Oct 16, 2017, 10:01:04 PM10/16/17
to RavenDB - 2nd generation document database
Is it possible to achieve the same without "ToList" in the first query, since that would materialize the intermediary result on the client, which may have performance implications

Shubha Lakshmi

unread,
Oct 17, 2017, 12:50:04 AM10/17/17
to RavenDB - 2nd generation document database
By importing Raven.Client.Linq namespace , we can avoid doing "ToList" and work with IRavenQueryable<string> instead .
 But once we get the IDs , how do we supply them to a Map Reduce index, which does not have Document ID as one of its field, i.e. having a different Aggregation criteria, other than Document ID Field.
Reply all
Reply to author
Forward
0 new messages