Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write nested schema.xml in solr?

How to write nested schema.xml in solr

The document in schema.xml says

<!-- points to the root document of a block of nested documents. Required for nested
document support, may be removed otherwise
-->
<field name="_root_" type="string" indexed="true" stored="false"/>

http://svn.apache.org/viewvc/lucene/dev/trunk/solr/example/solr/collection1/conf/schema.xml?view=markup

Which can be used in

https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-BlockJoinQueryParsers

What will be schema.xml for nesting the following items:

  • Person string
  • Address
    • city string
    • postcode string
like image 457
user2230605 Avatar asked Mar 14 '14 03:03

user2230605


People also ask

What is schema XML in Solr?

The Solr search engine uses a schema. xml file to describe the structure of each data index. This XML files determines how Solr will build indexes from input documents, and how to perform index and query time processing. As well as describing the structure of the index, schema.

Where is schema XML in Solr?

The Solr schema. xml (typically found in the solr/conf/ directory) is where you tell Solr what types of fields you plan to support, how those types will be analyzed, and what fields you are going to make available for import and queries. Solr will then base its Lucene underbelly on what you define.


1 Answers

I know this is an old question, but I ran into a similar issue. Modifying my solution for yours, the fields you need to add to your schema.xml are as follows:

 <field name="person" type="string" indexed="true" stored="true" />
 <field name="address" type="string" indexed="true" stored="true" multiValued="true"/> 
 <field name="address.city" type="string" indexed="true" stored="true" />
 <field name="address.postcode" type="string" indexed="true" stored="true" />

Then when you run it you should be able to add the following JSON to your Solr instance and see the matching output in the query:

{
  "person": "John Smith",
  "address": {
      "city": "San Diego",
      "postcode": 92093
    }
}
like image 191
jencoston Avatar answered Sep 28 '22 00:09

jencoston