0

Let's say I have an object in the test bucket in my Riak installation with the following structure:

{
    "animals": {
        "dog": "woof",
        "cat: "miaow",
        "cow": "moo"
    }
}

When performing a search request for this object, the structure of the search results is as follows:

{
    "responseHeader": {
        "status": 0,
        "QTime": 3,
        "params": {
            "q": "animals_cow:moo",
            "q.op": "or",
            "filter":"",
            "wt": "json"
        }
    },
    "response": {
        "numFound": 1,
        "start": 0,
        "maxScore": "0.353553",
        "docs": [
            {
                "id": "test",
                "index": "test",
                "fields": {
                    "animals_cat": "miaow",
                    "animals_cow": "moo",
                    "animals_dog": "woof"
                },
                "props": {}
            }
        ]
    }
}

As you can see, the way the object is stored, the cat, cow and dog keys are nested within animals. However, when the search results come back, none of the keys are nested, and are simply separated by _.

My question is this: Is there any way provided by Riak to "reverse format" the search, and return the fields of the object in the correct (nested) format? This becomes a problem when storing and returning user data that might possibly contain _.

I do see that the latest version of Riak (beta release) provides a search schema, but I can't seem to see whether my question would be answered by this.

garbetjie
  • 579
  • 3
  • 10

1 Answers1

0

What you receive back in the search result is what the object looked like after passing through the json analyzer. If you need the data formatted differently, you can use a custom analyzer. However, this will only affect newly put data.

For existing data, you can use the id field and issue a get request for the original object, or use the solr query as input to a MapReduce job.

Joe
  • 25,000
  • 3
  • 22
  • 44
  • Thanks for the answer, Joe. Just one piece of clarification needed though - when you say to use the id and issue a get request, do you mean basically fetching the data, and then re-saving it? I don't see how just reading the data would cause the custom analyzer to come into play. – garbetjie Jun 10 '14 at 05:10
  • I mean when you want the data, use search to find the key and then get the value using a normal get so you have the original object to work with. – Joe Jun 10 '14 at 05:29
  • Ah, yeah, I did consider that. However, my only concern is that if there are 100 search results returned, we'd be making 101 Riak requests, as opposed to the 1 for the search only. Considering all the data is returned in the search, it makes sense to pull it from there if possible. – garbetjie Jun 10 '14 at 07:32