Riak secondary indexing 'Unknown field type for field' error

Hrishikesh More hrishikesh.r.more at gmail.com
Wed Oct 24 17:59:38 EDT 2012


Hi Brian,

    I got this problem fixed as there was a special character in index
name.

    I have some follow-up queries related to secondary indexing:
1.  I stored IRiakObject ( with RiakIndexes)  using RiakBucket (Strongly
typed for IRiakObject) . Secondary indexes are created and object is stored
perfectly.  However,  the store operation returns 'null' IRiakObject. Is
there a way to get ETag or VTag of stored object through HttpResponseHeader
(while using RiakBucket and without querying again)?

2. In order to get proper http response I used RiakClient (instead of
RiakBucket.store ), where I performed same 'store' operation with secondary
indexes. I got the same error i.e. 'Unknown field type for field: 'login''.
If I do store without secondary indexes (commenting out 'indexes.add'
lines), it works fine.  I want to store json string (which is available
from client) without any converter. While storing json string I want to
store secondary indexes (which is also provided by client).

    Is this error related to 'prefix' used in creating RiakClient?

 The code snippet :

        StandardHttpRequestRetryHandler retryHandler = new
StandardHttpRequestRetryHandler(3, false);

        /* create RiakConfig */
        RiakConfig config = new RiakConfig("192.168.21.202",
"8098", "/riak");
                         config.setMaxConnections(500);
                         config.setTimeout(5000);
                         config.setRetryHandler(retryHandler);

        /* create http client for riak */
       RiakClient riakClient = new RiakClient(config);


List<RiakIndex> indexes = new ArrayList<RiakIndex>();
        indexes.add(new BinIndex("login","me at domain.com"));
        indexes.add(new IntIndex("quantity",77));


 RiakObject riakObject = new RiakObject(riakClient,
                                                "test",
                                                id, json.getBytes(),
                                                "application/json",
                                                null, null, null, null,
null, indexes);


     StoreResponse response = riakClient.store(riakObject);
        if (response.isSuccess()) {
            retval = response.getVtag();
        } else {
            int statusCode = response.getStatusCode();
            String errMsg = "Error while storing id : " + id + " status
code : " + statusCode;
            logger.error(errMsg);
            throw new xxxxException(errMsg);
        }

thanks!

On Wed, Oct 24, 2012 at 3:49 AM, Brian Roach <roach at basho.com> wrote:

> Without knowing exactly what you're doing, it's hard to tell. When
> you're using an IRiakObject with StoreObject.store() without
> specifying a Converter<T>, there's not any JSON
> serialization/deserialization occurring. It's simply storing whatever
> you pass to withValue() in Riak.
>
> If you can provide a short compilable example that exhibits the
> behavior you're describing, I'll be happy to look into it.
>
> Thanks!
> Brian Roach
>
> On Tue, Oct 23, 2012 at 3:08 PM, Hrishikesh More
> <hrishikesh.r.more at gmail.com> wrote:
> > Index preparation works but storing the JSON is not working. It complains
> > about 'sku1' (which is a 'object' type).
> >
> >
> > On Wed, Oct 24, 2012 at 2:33 AM, Hrishikesh More
> > <hrishikesh.r.more at gmail.com> wrote:
> >>
> >> I have config with list of attributes and their types (e.g. string,
> >> integer, boolean).  Based on attribute I appropriately put it in
> RiakIndexes
> >> object.  It works if I do it with simple (non nested) JSON.
> >>
> >> e.g.
> >> if (attrType.equals("String")) {
> >>           riakIndexes.add(fieldName, parser.getText());         ==>
> >> parser is JsonParser
> >> }
> >>
> >>
> >>
> >> On Wed, Oct 24, 2012 at 2:27 AM, Brian Roach <roach at basho.com> wrote:
> >>>
> >>> How, exactly, are you creating 'indexes' ?
> >>>
> >>> A secondary index in Riak has to be an integer or a string.
> >>>
> >>> Thanks,
> >>> Brian Roach
> >>>
> >>> On Tue, Oct 23, 2012 at 2:42 PM, Hrishikesh More
> >>> <hrishikesh.r.more at gmail.com> wrote:
> >>> > Hi,
> >>> >
> >>> >     Using following JSON I am trying to create secondary indexes in
> >>> > Riak.
> >>> >
> >>> >     {
> >>> >             “Id” :  “xxxx”,
> >>> >             “login”   : “xxx”,
> >>> >             “context” : “xxx”,
> >>> >             “creationDate” : “xxxx”,
> >>> >              ...........
> >>> >              ...........
> >>> >             “sku1” : {
> >>> >                          quantity : 1,
> >>> >                        },
> >>> >             “sku2” : {
> >>> >                          quantity : 2,
> >>> >                        },
> >>> >     }
> >>> >
> >>> >    I prepare RiakIndexes by using above JSON and looping over it.
> When
> >>> > I try
> >>> > to store (the same json string) it in following way I get 'Unknown
> >>> > field
> >>> > type for field: 'sku1'  error.
> >>> >
> >>> >    IRiakObject riakObj = RiakObjectBuilder.newBuilder(bucketName, id)
> >>> >                 .withIndexes(indexes)
> >>> >                 .withValue(json)
> >>> >                 .withContentType('application/json')
> >>> >                 .build();
> >>> >
> >>> >    IRiakObject returnObject = bucket.store(riakObj);
> >>> >
> >>> > Error:
> >>> >     com.basho.riak.client.http.response.RiakResponseRuntimeException:
> >>> > Unknown field type for field: 'sku1'.
> >>> > Unknown field type for field: 'sku2'.
> >>> >
> >>> > 1.  If I don't define nested JSON it works, however it I put 'skuid'
> >>> > using
> >>> > objectMapper.createObjectNode()  and add to parent object node (while
> >>> > preparing JSON for testing), it gives above error.
> >>> >      Do I have to write custom serializer here?
> >>> > 2.  Is there a way to ignore this error through config in Riak?
> >>> >
> >>> > thanx.
> >>> >
> >>> > _______________________________________________
> >>> > riak-users mailing list
> >>> > riak-users at lists.basho.com
> >>> > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
> >>> >
> >>
> >>
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20121025/b10377a2/attachment.html>


More information about the riak-users mailing list