Elastic search sort by one of the single nested doc key
<p>i have docs which look like these :-</p>

<p>"_source": {</p>

<pre><code>      "product_name": "p2",
      "m_p": [
        {
          "m_id": "m2",
          "price": 100
        },
        {
          "m_id": "m4",
          "price": 101
        }
      ]
    }
</code></pre>

<p>and</p>

<p>"_source": {</p>

<pre><code>     "product_name": "p1",
      "m_p": [
        {
          "m_id": "m1",
          "price": 50
        },
        {
          "m_id": "m2",
          "price": 55
        },
        {
          "m_id": "m3",
          "price": 55
        },
        {
          "m_id": "m5",
          "price": 65
        }
      ]
    }
</code></pre>

<p>Now i need to sort these based on the price of given(from external source) m_id and p_id pair.
for example the external service gives that for p1-m2 , and p2-m4
so the query should have sorted products based on the price of p1 as 55(m2 selling at 55) and price of p2 as 101(m4 selling at 101).</p>