VJohn
VJohn

Reputation: 533

How to Index nested json objects in solr

I have a json object like this,

{  
"id" : "123",  
"name" : "aaa",  
"loc" : {  
 "lat" : "",  
 "lon" : ""  
},  
}  

In solr i added a field like

<field name="loc" type="string" indexed="true" stored="true" multiValued="true"/>  

Then i tried adding the json doc to solr
But i couldn't see the 'loc' object being indexed in solr.
Am i doing wrong? Do i need to add anything in schema.xml
Can someone help me out of this pls?

Upvotes: 1

Views: 5979

Answers (3)

gpilotino
gpilotino

Reputation: 13312

post to

/solr/update/json?commit=true?split=/&f=txt:/**

see http://lucidworks.com/blog/schemaless-solr-part-1/

Upvotes: 0

Alexandre Rafalovitch
Alexandre Rafalovitch

Reputation: 9789

How are you adding your JSON? Because it does not look like the format required by Solr.

You need to conform to that. Also, if those lat/longs are really geographic coordinates, Solr has a dedicated geospatial support. Though you will need to get data into the appropriate shape either on the client side or with something like UpdateRequestProcessor, most likely ConcatFieldUpdateProcessorFactory.

Upvotes: 1

ajreal
ajreal

Reputation: 47321

I afraid you have to flatten the nested object to become something like

loc_lat = value of loc.lat
loc_lon = value of loc.lon

And of course, two new fields to store the data.

Upvotes: 1

Related Questions