In the spring of 2020, we released the latest revamp of the Couchbase SDK: 3.0. Shipping alongside Couchbase Server 6.5.0 and offering early, experimental support for Scopes and Collections, it also included a completely new API and consistency across the different platforms. While SDK 3.0 was a significant milestone in the Couchbase history, it was just another incremental improvement for developers working with Couchbase Server. Couchbase Server continues to evolve adding new features and that is why we are now releasing Couchbase SDK 3.1.0 with even more improvements for things such as FTS Geo Polygon support and Bucket Durability Management amongst others.
This post reviews each new feature added across all Couchbase SDKs. The examples are in C# but expect similar idiomatic implementations across all the SDKs whether it be Java, Go or another language.
FTS Geo Polygon Support
To augment the two types of Geo queries, Point Distance and Bounded Rectangle, already supported by Couchbase, in 6.5.0 Geo Bounded Polygon queries support was added. Point Distance queries are useful for finding things like restaurants near you and sorted distance near you. Bounded Rectangle Queries help find restaurants within a specific rectangular boundary near you, such as a city block. Geo Bounded Polygon Queries allows you to find restaurants within a random bounded polygon using an array of coordinate pairs as input parameters.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
var query = new GeoPolygonQuery(new List<Coordinate> { Coordinate.OfLatLon(37.79393211306212, -122.44234633404847), Coordinate.OfLatLon(37.779958817339967, -122.43977141339417), Coordinate.OfLatLon(37.788031092020155, -122.42925715405579), Coordinate.OfLatLon(37.79026946582319, -122.41149020154114), Coordinate.OfLatLon(37.79571192027403, -122.40735054016113), Coordinate.OfLatLon(37.79393211306212, -122.44234633404847) }).Field("geo"); var results = await cluster.SearchQueryAsync("food-idx", query); foreach (var result in results) { //do something with the results. } |
You can read more about Geo Polygon queries in this blog post.
Bucket Durability Management
Durability level guarantees persistence for documents; whether or not a document has been persisted to disk and how many replicas it has been written to.
In the older versions of Couchbase Server and SDK, durability level settings could only be provided via K/V Operation, this could quickly turn into a repetitive and mundane process especially in the case where persistence guarantees were to be the same across all documents within a Bucket. Starting Couchbase Server 6.6 we can now add Durability as a setting on the Bucket level. This feature is now available for you via SDK 3.1 Couchbase Server 6.6 adds Bucket level durability which allows for a certain durability to be applied to all documents within a bucket. In Couchbase SDK 3.1.0 we continue the support into the SDKs using the Bucket Management API.
1 2 3 4 5 6 7 8 9 10 11 |
var settings = new BucketSettings { Name = name, BucketType = BucketType.Couchbase, RamQuotaMB = 100, EvictionPolicy = EvictionPolicyType.FullEviction, DurabilityMinimumLevel = DurabilityLevel.Majority }; // create await bucketManager.CreateBucketAsync(settings).ConfigureAwait(false); |
The supported Durability levels are:
- Majority – the document must have been replicated to a majority of the configured nodes in a cluster
- MajorityAndPersistActive – the same as Majority but the document must also be persisted to the active node for durability requirements to be met.
- PersistToMajority – the document must be persisted to a majority of the configured nodes on disk.
The default persistence level is none, but you can still specify the durability level upon insert or update of the document.
Bucket Ephemeral Management
This feature allows or the eviction policy for documents to be set for Ephemeral Buckets upon creation using the Management API. The following eviction policies are now supported:
- NRU Eviction – When the memory quota is reached, Couchbase Server ejects data that has not been used recently.
- No Eviction – Couchbase Server keeps all data until explicitly deleted but will reject any new data if you reach the quota (dedicated memory) you set for your bucket.
Here is an example of setting NRU Eviction:
1 2 3 4 5 6 7 8 9 10 |
var bucketManager = cluster.Buckets; var settings = new BucketSettings { Name = “some-bucket”, BucketType = BucketType.Ephemeral, RamQuotaMB = 100, EvictionPolicy = EvictionPolicyType.NotRecentlyUsed }; await bucketManager.CreateBucketAsync(settings).ConfigureAwait(false); |
The default is No Eviction if not specified.
FTS Flex Index
FTS Flex Index
Flex Index gives the developer the ability to use the Couchbase Query Service to leverage search capabilities. For example, N1QL uses B-Tree indexes as they have selectivity and FTS uses inverted indexes which provide low selectivity or “fuzziness”; Flex Index allows you to combine for queries that are both exact and fuzzy by simply providing a hint to the service as to which behavior you desire. From the SDK this functionality is exposed but setting a simple flag on the QueryOptions object telling the N1QL service to consider using any FTS index to fulfill the query.
1 2 3 4 5 6 |
var result = await cluster.QueryAsync<dynamic>("SELECT * FROM `default` WHERE type=$name;", options => { options.Parameter("name", "person"); options.FlexIndex(true); }).ConfigureAwait(false); |
To use Flex Indexes simply set the FlexIndex property or method on the QueryOptions class.
FTS Score Parameter
As an optimization, scoring can now be disabled when doing Search queries. This is exposed as an option block parameter passed:
1 2 3 4 5 6 |
var results = await cluster.SearchQueryAsync(IndexName, new MatchQuery("inn"), options => { options.Limit(10); options.DisableScoring(true); }); |
Scoring will be disabled if true is passed in, otherwise it will be included in the response.
GetResult.Expiry has been Deprecated
Finally, GetResult.Expiry
has been deprecated and replaced with GetResult.ExpiryTime
which specifies an instance in time as opposed to a duration.
Feedback please!
Those are the new features that have been added to Couchbase SDK 3.1 for Couchbase Server 6.6 and 7.0. We hope you find them useful and feel free to provide feedback on our forums or ask a Couchbase expert a question.