lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jhon Smith" <doom...@gmx.com>
Subject How to sort docs basing on nested docs' fields
Date Wed, 09 Mar 2016 15:51:52 GMT
There are usual documents: products and nested documents containing different prices.
How to sort product documents basing on minimum price in nested documents.

Example:
<doc>
    <field name="id">1</field>
    <field name="doc_type">product</field>  
    <doc>
        <field name="id">2</field>
        <field name="doc_type">price</field>   
        <field name="price">100</field>
    </doc>
    <doc>
        <field name="id">3</field>
        <field name="doc_type_s">price</field>   
        <field name="price">200</field>
    </doc>	
</doc>
<doc>
    <field name="id">4</field>
    <field name="doc_type">product</field>  
    <doc>
        <field name="id">5</field>
        <field name="doc_type">price</field>   
        <field name="price">300</field>
    </doc>
    <doc>
        <field name="id">6</field>
        <field name="doc_type">price</field>   
        <field name="price">50</field>
    </doc>	
</doc>  

So 
product with id=1 has prices 100 and 200: minimum price = 100
product with id=4 has prices 300 and 50: minimum price = 50
Hence sorting in ascending order should return second document(id=4) first and first document(id=1)
next.

Denormalization or storing the min price in product document itself is not an option since
the actual structure and requirements are more complex.

I guess some function query should be used somehow?

Mime
View raw message