title: Rank records on the basis of a field value in Elasticsearch
body: <p>I have a field <code>distribution</code> in record schema that looks likes this:</p>
  <pre><code>...
  &quot;distribution&quot;: {
      &quot;properties&quot;: {
          &quot;availability&quot;: {
              &quot;type&quot;: &quot;keyword&quot;
           } 
       }
  }
  ...
  </code></pre>
  <p>I want to rank the records with <code>distribution.availability == &quot;ondemand&quot;</code> lower than other records.</p>
  <p>I looked in Elasticsearch <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow noreferrer">docs</a> but can't find a way to reduce the scores of this type of records in <strong>index-time</strong> to appear lower in search results.</p>
  <p>How can I achieve this, any pointers to related source would be enough as well.</p>
  <p>More Info:</p>
  <p>I was completely omitting these <code>ondemand</code> records with help of python client in <strong>query-time</strong> like this:</p>
  <pre><code>from elasticsearch_dsl.query import Q
  
  _query = Q(&quot;query_string&quot;, query=query_string) &amp; ~Q('match', **{'availability.keyword': 'ondemand'})
  
  </code></pre>
  <p>Now, I want to include these records but I want to place them lower than other records.</p>
  <p>If it is not possible to implement something like this in <strong>index-time</strong>, please suggest how can I achieve this in <strong>query-time</strong> with python client.</p>
  <p>After applying the suggestion from llermaly, the python client query looks like this:</p>
  <pre><code>boosting_query = Q(
      &quot;boosting&quot;,
      positive=Q(&quot;match_all&quot;),
      negative=Q(
          &quot;bool&quot;, filter=[Q({&quot;term&quot;: {&quot;distribution.availability.keyword&quot;: &quot;ondemand&quot;}})]
      ),
      negative_boost=0.5,
  )
  if query_string:
      _query = Q(&quot;query_string&quot;, query=query_string) &amp; boosting_query
  else:
      _query = Q() &amp; boosting_query
  </code></pre>