2

I have a bunch of documents in Solr, where each document is a product. Each product can have a list of prices, like this:

{ 
  "id": 1
  "name": "Product 1",
  "prices": [{"min":1,"max":100,"price":75}, {"min": 101, "max": 500, price: 50}]
}

Then problem is that this nested properties get stored in Solr like this:

{
  "id": 1
  "name": "Product1"
  "prices.min": [1, 101]
  "prices.max": [100, 500]
  "prices.price": [75, 50]  
}

The problem comes when I want to unserialize the json that Solr returns, because my objects don't have any "prices.min" field. So, is there any way for Solr to use the same format as it originally came in? I'm using rust and serde for talking to Solr:

#[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct SolrProduct {
    id: u64,
    name: String,
    prices: HashSet<PriceRange>
}

#[derive(Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct PriceRange {
    min: usize,
    max: usize,
    price: Option<Decimal>,
}
Dani
  • 897
  • 6
  • 7
  • Depending on how you're indexing your documents, if it's important to get the source JSON back (instead of just getting the id and the resolving that id locally before displaying things in your frontend), you can set the `srcField` setting if you're using the `/update/json/docs` endpoint: https://lucene.apache.org/solr/guide/6_6/transforming-and-indexing-custom-json.html#TransformingandIndexingCustomJSON-SettingJSONDefaults - alternatively you can also include the source document in a non-indexed string field as long as it's not above 32k in size. – MatsLindh Feb 25 '21 at 19:46
  • Also see [How to transform fields during deserialization using Serde?](https://stackoverflow.com/questions/46753955/how-to-transform-fields-during-deserialization-using-serde) – uanirudhx Feb 25 '21 at 21:35

0 Answers0