1
votes

I'm trying to use the geo search function from cloudant .

I have created a search index as follow:

{
    "_id": "_design/locations2",
    "_rev": "1-ca7f78894c9e6a26539f81322b640b4e",
    "indexes": {
        "find1": "function(doc){if(doc.coord){index('lat', doc.coord[0], {\"store\":\"yes\"});index('lon', doc.coord[1], {\"store\":\"yes\"})}; }"
    }
}  

I have few documents as follow:

{
    "_id": "9b01e808371c049285b1b40d1077c934",
    "_rev": "1-770b0d49ef839713003c5f17f81d3fc1",
    "type": "location",
    "name": "test",
    "description": "description",
    "coord": [ - 31.936722, 115.754979]
}

then i am querying as follow:

.cloudant.com/epic_test_db/_design/locations2/_search/find1?q=test

I am receiving this error:

{"error":"{case_clause,{<<\"find1\">>,\n              <<\"function(doc){if(doc.coord){index('lat', doc.coord[0], {\\\"store\\\":\\\"yes\\\"});index('lon', doc.coord[1], {\\\"store\\\":\\\"yes\\\"})}; }\">>}}","reason":"[{dreyfus_index,design_doc_to_index,2},\n {dreyfus_rpc,call,5},\n {rexi_server,init_p,3}]"}

Any idea why?

Ta

1

1 Answers

1
votes

Ok I find the answer. I missed index in the indexes definition before function (doc)

   {
        "_id": "_design/locations2",
        "_rev": "1-ca7f78894c9e6a26539f81322b640b4e",
        "indexes": {
            "find1": {
index: "function(doc){if(doc.coord){index('lat', doc.coord[0], {\"store\":\"yes\"});index('lon', doc.coord[1], {\"store\":\"yes\"})}; }"
        }
    }}