How search with limit and top results?


(Tenaz3) #1

I want to sort 7 most expansive products with validate time ascending. I did:

{
"from": 0,
"size": 7,
"query": {
    "filtered": {
        "query": {
            "match_all": {}
        }
    }
},
"sort": [{
    "price": {
        "order": "desc"
    }
}, {
    "validate_time": {
        "order": "asc"
    }
}]
}

But I want this top 7 expansive products ordered by validate_time


(Nik Everett) #2

What you've got will sort products by price, breaking ties with validation_time. I don't believe there is a way to get the top 7 by price and then sort them by something else.


(Ivan Brusic) #3

Perhaps with the query rescorer?
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-rescore.html

There is no explicit sorting in the query scorer, your scorer will need to
submit a score based on the field. Should be easy with a date field.

Ivan


(Nik Everett) #4

Yes! That'll do it! I'd forgotten about the rescorer.


(Tenaz3) #5

Thanks, Ill take a look! =D


(system) #6