cloudant / java-cloudant

A Java client for Cloudant
Apache License 2.0
79 stars 68 forks source link

Sorting on the result set is not happening with java code #455

Closed TigerAVAF6R closed 6 years ago

TigerAVAF6R commented 6 years ago

Please read these guidelines before opening an issue.

Bug Description

We are using one index query to return a result, we are using "sort" key word to do sorting based on a timestamp field, and set limit to 1, this means we want to get the latest one record, but we found that the query is working fine in browser dashboard, but not working in java code with api. We have created related index in cloudant already, we are not sure the reason behind this.

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

Below is the sample code we are using:

String query = {"selector":{"requestMethod":"xxx","profileID":"xxx"},"sort":[ {"createdTS:string": "desc"} ],"limit":1} List auditLogList = auditlogdb.findByIndex(query, AuditLogBean.class);

2. What you expected to happen

we expected the returned list has only one record, and the record is the latest one record

3. What actually happened

it is returning all record in a list, but no sorting happened on the records

Environment details

tomblench commented 6 years ago

I would recommend POSTing to the /_find endpoint with curl or similar using the contents of query. If the result is not what you are expecting, then your query is wrong.

We recommend the use of QueryBuilder (sample here which makes life easier since you don't have to worry about string escaping etc. There are options for sort, limit, etc.

emlaver commented 6 years ago

Closing as stale, please reopen if you require further assistance.