toptal / chewy

High-level Elasticsearch Ruby framework based on the official elasticsearch-ruby client
MIT License
1.88k stars 364 forks source link

Index#order - add missing first/last option #924

Open ChrisKaun opened 7 months ago

ChrisKaun commented 7 months ago

Is your feature request related to a problem? Please describe.

I have a use case where a index should return records ordered by a string field, though records with an empty value must be returned first.
Lets assume an index with Person instances that have a first_name field.

Person.new(first_name: 'A')
Person.new(first_name: 'Z') 
Person.new(first_name: null/nil)

The index query should return the person without a first_name first, regardless of the order direction (ascending/descending).

Describe the solution you'd like

The elasticsearch documentation lists an missing-option which would be ideal for my use case.

Additional context

Maybe this option already exists and it's not documented in chewy, but even by looking throught the documentation I couldn't find it.