Confusing GeoSpatial

I need Radius-Based query on geo spatial data , I see similar topics but not helped

1. What is be best way (High performance) to search within 10 kilometers of specific location , when we have millions point in a country and many cities and want to fetch up to 100 items

— A. Using pure N1QL as described in
— B. Using spatial query as described

2. Is SpatialQuery in NodeJS SDK correspond to
If yes , why we just have bbox? Where is Radius-Based? If no!! What is the diffrence

3. What is Geospatial Index?
— A. When we use MapReduce Views for geo spatial data? and when we use Geospatial Index , As I understand SpatialQuery needs MapReduce Views but rest api need Geospatial Index so SpatialQuery and rest api is not same!!!
— B. Is Geospatial Index a special type of Secondery Indexes?


What I understand (And I know is wrong :roll_eyes:) is :

Theres is 3 way to query geospatial data

– A. Using pure N1QL and Math functions like RADIANS , COS , SIN , …
– B. Using spatial query and REST API , But What about NodeJS SDK?
– C. Using MapReduce and SpatialQuery, But What about Radius-Based query?

  1. MapReduce Views support for spatial has gone out of support (in 6.0). So, not recommended.

  2. FTS implémentation is the fully supported version. I couldn’t find the full documentation in SDK on how to use it, but thankfully there is a test showing how to use it. [@amarantha, @ingenthr]
    This supports the RADIUS based query.

  3. N1QL version uses the fully supported functional indexes, but you’ve to be careful to formulate the query, as shown in the article.

Which is better for large dataset? N1QL version or FTS implementation ?

Do you recommend me partitions data? or not needed

Hi @socketman2016, “large” is relative. How big is your dataset?

@keshav_m 50-100 millions

Hi @socketman2016,

100m documents, with 4KB document size, will need about 1 TB of diskspace and 10GB of memory. 4 cores for initial build.
You’ll have to see how much query workload you’d need to support and estimate the CPUs you need.

FTS automatically partitions the index in to six partitions, by default. Whether to put into multiple nodes or not depends on the query workload and your SLA.

1 Like

How you estimate memory?

In the

And in Geospatial Index , is lat and lon reserved key words? can I have latitude and longitude fields instead?

@brett19 Can you please convert the following REST query to NodeJS version?

  "from": 0,
  "size": 10,
  "query": {
    "location": {
      "lon": -2.235143,
      "lat": 53.482358
      "distance": "100mi",
      "field": "geo"
  "sort": [
      "by": "geo_distance",
      "field": "geo",
      "unit": "mi",
      "location": {
      "lon": -2.235143,
      "lat": 53.482358

This is actually quite interesting, @keshav_m… So with the mobile SDK v.2.1.1 (I’m using C#) what would be the best option to do spatial searches (as I understand N1QL i not an option)…?

@jda I think N1QL is a good option , specially when you need distinct and aggregation

Yes, but the thing is that you cannot use N1QL in the mobile SDK. It is not an option as it is not implemented - as far as I understand…

Geo spatial queries are not supported in CBL . This is something on our radar (no definite timelines at this time). For smaller data sets, you could do bounding box queries as suggested here

@jda CBL 2 doesn’t have a N1QL language parser, but it does have most of the query functionality of N1QL. Though not geospatial indexing, yet…

Oh no… that would really be a showstopper for me!!!

I’ll have a look at the link you suggested - and I really hope there is a working solution there. Otherwise, I would really need you to put it way higher on the radar…!!! Not many things on mobile work without some functionality that is based on where you are - and what is within a certain reach from there…

I’m really surprised - and sad - that I have overlooked such a basic functionality is missing in mobile… I have migrated our entire backend system to Couchbase for the sync functionality AND obviously the possibility to do things based on the user’s location :frowning:


Is this question answered anywhere?
I have the same question cause my data model does not contain a geo object with ‘lat’ and ‘long’ but rather has the ‘latitude’ and ‘longitude’ fields in an ‘address’ object which is contained in an array of addresses. Not sure how to express this in a type mapping or index.