Elasticsearch sort by children

Thanks for sharing, updated latest formula to ceil((log10(_score+1)+5) * 100) * 10000 + (9999 - ceil(log10(doc['price'].value +1) * 1000)) added +1 to score because in some cases it returns errors like this:

 "function score query returned an invalid score: -Infinity for doc: 4580"

Update: Got another error:

 "function score query returned an invalid score: NaN for doc: 1739"

changed formula to ceil((log10(_score+1)+5) * 100) * 10000 + (9999 - ceil(log10(doc['price'].value +1) * 1000)) added +1 to doc value to fix this

Update 2: Got another error:

 "function score query returned an invalid score: NaN for doc: 1739"

changed formula to ceil((log10(_score+1)+5) * 100) * 10000 + (9999 - ceil(log10(doc['price'].value > 0 ? doc['price'].value : 1) * 1000)) replaced +1 with expression

Update 3: Got another error:

doesn’t have an error message anymore it’s hard to find now, but it was similar to the previous 🙁

changed formula to ceil(_score+1) + ceil((doc['price'].value > 0 ? doc['price'].value : 1) * 100) simplified formula, so I can understand and it still working today 🙂

Leave a Comment