Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
Ravendb query order by value

I have objects with fields score and id. I need to get some amount of this objecs from from to from + count, which ordering by field score in descending order. Inside each equals range I need to get object with specific value of id on top of this range if it exist.

Example:

 1. score = 10, id = 5
 2. score = 20, id = 6
 3. score = 20, id = 7
 4. score = 20, id = 8
 5. score = 30, id = 9

Specific value id = 7, from = 0, count = 2

Expected result:

 1. score = 30, id = 9
 2. score = 20, id = 7  <--- my specific value on top of equal range, where score = 20

I write simple query:

final List<SomeClass> players = session.query(SomeClass.class, SomeIndexClass.class)
            .orderByDescending("score", OrderingType.LONG)
            .skip(from)
            .take(count)
            .toList();

But this does not take into account the conditions with specific value id. How can i do it?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you have this id field indexed in your index, then you can add a whereGreaterThan condition in your query, to filter for those id's that are greater than '7'

So query would be something like:

final List<SomeClass> players = session.query(SomeClass.class, SomeIndexClass.class)
            .whereGreaterThan("id", 7)
            .orderByDescending("score", OrderingType.LONG)
            .skip(from)
            .take(count)
            .toList();

See documentation link:
https://ravendb.net/docs/article-page/5.1/java/indexes/querying/filtering#where---numeric-property

Is id the document id ? because then it doesn't have to be indexed, should work w/ just adding the 'where' condition to the query. See: https://ravendb.net/docs/article-page/5.1/java/indexes/querying/basics#example-ii---filtering

Btw, check out the code samples in https://demo.ravendb.net/
In each sample, click the 'Java' tab to see sample Java code.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!