Map reduce indexes sorting on a numeric field does not work

34 views
Skip to first unread message

Arun Noronha

unread,
Aug 26, 2014, 8:37:13 AM8/26/14
to rav...@googlegroups.com
Hi, 

I am having the following issue: 
When I setup a map/reduce index and I have a field in the index that is numeric on which I define a sort as double. I am not able to get the sort working. 
I have tried both with and without field storage.

I have a solution attached and some detail below

Any insight into the issue would be greatly appreciated.

Details: 

Raven Version : 2.5
Build : 2910


I have the following document types

Collection1 (Tag):

TagUuid 
TagSpecificationUuid
......


Collection2 (Program)

TagUuid
TagSpecificationUuid
NumberOfYears
......

I have the map/reduce setup the following way 

First map is setup on program with tag fields defaults. There is a where clause on tagspecificationuuid
Second map is setup on tag with program fields defaults. There is a where clause on tagspecificationuuid
Reduce then goes off the tagUuid as the key.

To verify this I go to raven studio and query the index with a sort on number of years
When I do this I do not get expected results. The output is not sorted by number of years.

Not sure what I am doing wrong.

To run the solution

1) Crrate a database called "TestIndexing"
1) Change the app.configuration entry for RavenDataStoreServer to the appropriate url (it is defaulted to localhost:8080)
2) run the application
3) choose either option 1 or option 2 to create an index with field storage or without for number of years (this will create your map reduce)
4) choose option 3 to load data. 


You will see here that after you run this and go to studio the results will be unsorted even with sorting defined in the query.

RavenDbMapReduceSort.zip

Grisha Kotler

unread,
Aug 27, 2014, 7:53:20 AM8/27/14
to rav...@googlegroups.com
Hi,

The field ProgramTemplate_NumberOfYears can be null.
In order to sort it by double, it needs to be of a double type.
Set the number of years to a default value:
ProgramTemplate_NumberOfYears=(double?)0
or
ProgramTemplate_NumberOfYears = g.Select(x => x.ProgramTemplate_NumberOfYears).Where(x => x != null).FirstOrDefault() ?? 0


Grisha Kotler

RavenDB Core Team

Tel: 972-4-6227811

Fax: 972-153-4-6227811





--
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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages