So one interpretation of the provided instructions is to use a Cloud function to query the database by state.
(Another option would be to filter all the results with Django... so fine for a small project/database)
Create index in database
I've made two for testing: state-index
and single-state-index
state-index
includes the multiple fields needed
single-state-index
just looks for the state code
Went back to just a single index: dealersByState
- will try using the use_index
option in another test query.
{
"index": {
"fields": [
"st"
]
},
"name": "dealersByState",
"type": "json"
}
Create Cloud Function to Query Database
Running the public Cloudant function "List-query-indexes" lists all of them there.
Running the exec-query-find one, however, runs into an error stating there aren't any queries.
Because of this, I'm not sure if the "create index" step was done right. I have 3 or 4 different IBM API docs open to add to the confusion.
Custom Cloud Function Suggestion
The following has been suggested for the state query filter:
if(params.state){
return {
query: {fields : ['id','city','state','st','address','zip','lat','long','short_name','full_name'],
"selector":{st:{"eq":params.state}}}, include_docs: true}
}
The include_docs
bit means I can throw away the pass-the-docs step. Or would this be part of it?
Others have reported not passing the parameter as a string (just with CA, for ex.) causes trouble. (This is while manually testing the API. We could easily account for that with toString()
or something.)
Somebody make it make sense please...