title: How to perform multi-dimensional queries in CouchDB/Cloudant
body: <p>I'm a beginner with CouchDB/Cloudant and I would like some expert advice on the most appropriate method of performing multidimensional queries.</p>
  
  <p>Example... 
  My documents are like this</p>
  
  <pre><code>{
    _id: 79f14b64c57461584b152123e3924516,
    lat: -71.05204477,
    lng: 42.36674199,
    time: 1531500769,
    tileX: 5,
    tileY: 10,
    lod: 7,
    val1: 200.1,
    val2: 101.5,
    val3: 50
  }
  </code></pre>
  
  <p><code>lat</code>, <code>lng</code>, and <code>time</code> are the query parameters and they will be queried as ranges.
  For example fetch all the documents that have</p>
  
  <pre><code> lat_startkey = -70 &amp; lat_endkey = -72  AND
   lng_startkey = 50 &amp; lng_endkey = 40  AND
   time_startkey = 1531500769 &amp; time_endkey = 1530500000
  </code></pre>
  
  <p>I will also query using <code>time</code> as a range, and <code>tileX</code>, <code>tileY</code>, <code>lod</code> as exact values</p>
  
  <pre><code>For example
  tileX = 5 AND
  tileY = 10 AND
  lod = 7 AND
  time_startkey = 1531500769 &amp; time_endkey = 1530500000
  </code></pre>
  
  <p>I've been reading about Views (map reduce), and I guess for the first type of query I could create a View each for <code>time</code>, <code>lat</code>, <code>lng</code>. My client could then perform 3 separate range queries, one against each View, and then in the client perform an intersection (inner join) of the resulting document id's. However this is obviously moving some of the processing outside of CouchDB, and I was hoping I could do this all within CouchDB itself.</p>
  
  <p>I have also just found that CouchSearch (json/lucene), and n1ql exist... would these be of any help?</p>