Hello,
I have a question regarding couchbase search java sdk.
In java sdk we have a numericRange() function which allows you to work on a numeric range of values < >= <=, etc … But what i want is to search on exactly that number , for eg: if a field say id has number 123,
when i pass in a query with number 123 it should give me that info. I am able to do that with N1QL but not with couchbase search java sdk .
And if i use n1ql I am unable to find out how much total hits are there if i use pagination, for eg: if i paginate from 1-100 and there are 1000 hits … how would i know the end of the pagination if i dont know there total hits (java search sdk gives me that with searchmetrics)… If i get the total hits i would basically know i need to paginate 10 times .
The query that @vsr1 recommends above is accurate.
In full text search, the only way we support point look up over numeric data is in the form of a range query with min and max set to the same value and setting them as inclusive.
total_hits is part of the response returned by the search service, so you should be able to leverage that to paginate as many times as you see fit.
@vsr1@abhinav I have one more question…
So I am also doing alphabetic sort on a field called name … So if I want to do a A-Z I put I sort by field name and desc as false in sdk… But but when I do that it sorts as Z-A …is Z-A considered ascending and A-Z considered desc… So to get A-Z sort I have to put desc as true
Configures the list of fields (including special fields) which are used for sorting purposes. If empty, the default sorting (descending by score) is used by the server. The list of sort fields can include actual fields (like "firstname" but then they must be stored in the index, configured in the server side mapping). Fields provided first are considered first and in a "tie" case the next sort field is considered. So sorting by "firstname" and then "lastname" will first sort ascending by the firstname and if the names are equal then sort ascending by lastname. Special fields like "_id" and "_score" can also be used. If prefixed with "-" the sort order is set to descending. If no sort is provided, it is equal to sort("-_score"), since the server will sort it by score in descending order.
Parameters:
`sort` - the fields that should take part in the sorting.
Returns:
this SearchQuery for chaining.
but by using Search Java sdk , it returns 0 results …
final SearchQuery conjunctsQuery = SearchQuery.conjuncts(queryList.toArray(new SearchQuery[queryList.size()]));
final SearchOptions options = SearchOptions.searchOptions()
.limit(Long.valueOf(limit).intValue()) // value 20
.skip(Long.valueOf(offset).intValue()) // value 0
.fields("cardId", "thumbnailUrl", "contentType", "watchlistId", "contentName", "id");
Any reasons why?
I was initially trying with couchbase 7.0 in local docker and it worked , when i changed my server version 6.6.1 which we have in our environment , it is not working .
But N1QL works… but the issue is that sorting in N1ql is not working on the field contentName
One thing to note - to effectively support sorting on document fields, you will need to enable “doc values” for the field while configuring your index - contentName in your example.
For your java SDK related question - I will ping @daschl .