Elastic Search - Sort by multiple fields with the missing parameter
<p>I am trying to apply a sort to an Elastic Search query by two different fields:</p>

<p><code>price_sold</code> and <code>price_list</code></p>

<p>I would like to first sort on <code>price_sold</code>, but if that value is null, I would like to then sort by <code>price_list</code></p>

<p>Would the query be correct if I just set the sorts to:</p>

<pre><code>"sort": [
 { "price_sold": { "order": "desc"}},
 { "price_list": { "order": "desc"}}
]
</code></pre>

<p>I have executed the query, and I do not get any errors, and it seems like the results are correct, however I am curious if I have overlooked something.</p>

<p>I have been reading about the <code>missing</code> filter, along with possibly using a <code>custom value</code>.  This may not be required, but I am not quite sure.</p>

<p>Would there be a way to define a second field to sort on if the first field is missing, or is that not necessary? Something like:</p>

<p><code>"sort": [{"price_sold: {"order": "desc", "missing": "doc['field_name']"}]</code></p>

<p>Would simply adding these two sorts give me the desired result?</p>

<p>Thanks.</p>