solrluceneriak

Search in json nested fields (schema + query)


I got the following JSON stored in a Riak bucket which handle Solr research.

{
  "date" : 1535673489, 
  "customer" : {
     "name" : "X"
     "id" : 1205643
    }
}

And my schema.xml fields look like that for the moment

 <field name="_version_" type="long" indexed="true" stored="true"/>
 <field name="date" type="int" indexed="true" stored="true" mult    iValued="true"/>

And the research on date works perfectly fine with query as

$RIAK_HOST/search/query/order?wt=json&q=date:[1535553489%20TO%201535599999]

Unfortunately I didn't found any documentation that explains how to properly field and query on sub field as customer.name or customer.id

Edit: As I found on the following post Riak search schema and nested fields, it seems that I need to create the fields as follow:

<field name="customer_name" type="string" indexed="true" stored="true" mult    iValued="true"/>

But then when I query on the fields, I got no answer to my request

Edit 2: I proceed to the following experimentation and I get no error from riak.

I uploaded the file

{
  "customer_name" : "toto", 
  "customer" : {
    "name" : "tata"
  }
}

And on research Riak obtained the result from the field "toto" and not the one from "tata". Is it possible that the nesting research is unactivated or associated to another character?


Solution

  • The fields you need to add to your schema.xml are as follows:

    <field name="date" type="string" indexed="true" stored="true"/>
    
    <field name="customer" type="string" indexed="true" stored="true" multiValued="true"/>
    
    <field name="customer.name" type="string" indexed="true" stored="true"/>
    
    <field name="customer.id" type="string" indexed="true" stored="true"/>
    

    And then you need to query your index as follow:

    $RIAK_HOST/search/query/order?wt=json&q=customer.name:t*