"Reverse formatting" Riak search results

72 Views Asked by At

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.

1

There are 1 best solutions below

3
On BEST ANSWER

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.