0

I am trying to run the following map/reduce query on my riak database:

curl -XPOST http://localhost:8098/mapred \
     -H 'Content-Type: application/json' \
     -d '{"inputs":{"bucket":"my_customers","key_filters":[["eq","sales+p3@dummy3.gr"]]},"query":[{"map":{"language":"javascript","source":"function(v) {var results = []; results.push(v); return results;}"}}]}' 

The bucket my_customers contains the value with key sales+p3@dummy3.gr but the result returned from this map/reduce query is an empty array.

If I change the query to search for another value with key sales@dummy.gr, which exists too, it returns the result without problem.

I suspect that the problem is around the character + which is part of the key.

Thanks in advance.

p.matsinopoulos
  • 7,655
  • 6
  • 44
  • 92
  • 1
    Check your key by listing the keys in the bucket. I suspect there's an url encoding problem here and the key actually has a space. – Brian Roach Jul 23 '13 at 21:37
  • aaaaah....You are right!!!! So, the key I thought it was with plus sign it is stored inside the bucket with a space instead! Very useful answer. Now, I need to find out how to store keys with plus sign literally. But, please, your answer is correct and answers my question why the query does not bring results. Please, post it as official answer so that I can accept it. – p.matsinopoulos Jul 23 '13 at 21:42
  • done and it should also answer your second question :) – Brian Roach Jul 23 '13 at 21:57

1 Answers1

0

Check your key by listing the keys in the bucket. I suspect there's an url encoding problem here and the key actually has a space rather than a +.

When you do a PUT/POST operation to the HTTP API, the Riak side actually urldecodes the bucket and key in the URL and sees that + as a space. You'll want to urlencode the + when PUT/POSTing that key using %2B (/buckets/mybucket/keys/sales%2Bp3@dummy3.gr) and do the same if you're doing a regular GET to retrieve it.

Brian Roach
  • 76,169
  • 12
  • 136
  • 161