title: Elasticsearch random scoring with filters
body: <p>I've got a situation, using ES 6.5, where I can either perform a <code>bool</code> or a <code>random_score</code>, but not both at the same time. Here is one of those potential queries: </p>
  
  <pre><code>{
    "from": 0,
    "size": 50,
    "query": {
      "function_score": {
        "random_score": {
          "seed": 10,
          "field": "_seq_no"
        }
      },
      "bool": {
        "filter": [
          {
            "terms": {
              "primary_category": [
                "foobar"
              ]
            }
          },
          {
            "terms": {
              "primary_type": [
                "barbaz"
              ]
            }
          }
        ]
      }
    }
  }
  </code></pre>
  
  <p>If I were to remove either the <code>function_score</code> block or the <code>bool</code> block, the query works, but in combination, it does not:</p>
  
  <p><code>[function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]</code></p>
  
  <p>Am I missing something about the example at: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-function-score-query.html#function-random" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/6.2/query-dsl-function-score-query.html#function-random</a></p>
  
  <p>All I want to do is "randomly sort" my results in a predictable way which will work across pagination, etc. Really I am just trying to display the filtered results with high variance, as any sort of standard sorting will create patterns in the result which I am trying to avoid. </p>
  
  <p>Any help would be appreciated, and I'll keep tinkering with it.  </p>