Web console query returns results, CURL query does not return results

I have a query that I run in the web console:

SELECT $prop1 FROM $bucket WHERE type = '$type' AND $bucket.$prop2 = '$value'

It returns one result. When I run this query from the command line, it returns no results:

curl -d "statement=SELECT $prop1 FROM $bucket WHERE type = '$type' AND $bucket.$prop2 = '$value'" -v http://$query_node_url:$port/query -u $user:$password | jq

The JSON I get back looks like this:

{ "requestID": "cbd3cc4c-e004-4b4c-956e-9e633a36c29a", "signature": { "userPk": "json" }, "results": [], "status": "success", "metrics": { "elapsedTime": "4.818299ms", "executionTime": "4.768587ms", "resultCount": 0, "resultSize": 0 }

No results!

Could this be a permissions issue? If not, what?

Thanks.

It is not permission issue.

Please try with exact query text (echo “statement=SELECT $prop1 FROM $bucket WHERE type = ‘$type’ AND $bucket.$prop2 = ‘$value’” ). N1QL $variable is query named parameter.

Post what is the values. Exact query you ran on web console.

There are no actual variables in the request. I have a script evaluates certain variables before sending the request.

It works on one cluster of nodes, but not a different cluster. The clusters are not identical. When I point the script at the second cluster, I get 0 results, when I know 1 exists.

Here’s an example of the query:

SELECT userID FROM userData WHERE type = 'user' AND userData.email = 'email_address@example.com'

Thanks.

execute in UI and goto Plan Tab and check each operator #ItemsIn, #ItemsOut and see where is issue

No apparent issues. Stream, Project and Filter all list 1 in, 1 out. Something called IndexScan3 lists 1 out and Authorize lists nothing.

@joes

That means things normal. same try with curl and see what is difference.
If needed post the output of following commands. Strip out document information if needed.

curl -v -u user:password http://<host>:8093/query/service -H "Content-Type: application/json" -d '{"statement":"SELECT d.* FROM userData AS d WHERE d.type = \"user\" AND d.email = \"email_address@example.com\""}'
curl -v -u user:password http://<host>:8093/query/service -H "Content-Type: application/json" -d '{"statement":"SELECT d.* FROM userData AS d WHERE d.type = \"user\" AND d.email = \"email_address@example.com\"", "profile":"timings"}'

FYI : https://en.wikipedia.org/wiki/Percent-encoding @ is Reserved Characters it might be causing. Try replace with ASCII (i.e. @ with %40) or use curl JSON header as described above.

@ vsr1 thank you. Your first suggestion:

curl -v -u user:password http://<host>:8093/query/service -H "Content-Type: application/json" -d '{"statement":"SELECT d.* FROM userData AS d WHERE d.type = \"user\" AND d.email = \"email_address@example.com\""}'

worked. I did not need to use percent-encoding for the @.

Do you know why sending JSON worked but ‘statement=’ did not in this one instance?

Anyways, it worked! Happy holidays : )

Already posted in the FYI, curl might be sending whole thing as Content-Type: application/x-www-form-urlencoded , @ is reserved character and interpreted differently and doesn’t match.

In Web console navigate to Query->Monitoring ( /ui/index.html#!/query/monitoring ) then choose Completed and you see exact statement executed with curl

1 Like