Getting the last nested or most recent nested element


(pentium10) #1

We have this mapping:

{
    "product_achievement": {
        "type": "nested",
        "properties": {
            "id": {
                "type": "long"
            },
            "last_purchase": {
                "type": "long"
            },
            "products": {
                "type": "long"
            }
        }
    }
}

As you see this is nested, and the last_purchase field is a unixtimestamp value. We would like to query from all nested elements the most recent entry defined by the last_purchase field, AND see if in the last entry there is some product id is in products.


(Igor Motov) #2

I think it might be easier and faster to just index the last_products field one more time as non-nested field of the root document. Then all you have to do is to perform a terms filter search on this field.


(system) #3