# Use Random\_score along with multiple filter

**URL:** <https://discuss.elastic.co/t/use-random-score-along-with-multiple-filter/93264>\
**Category:** Elasticsearch\
**Created:** [July 15, 2017, 2:29pm UTC](https://discuss.elastic.co/t/use-random-score-along-with-multiple-filter/93264 "2017-07-15T14:29:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mads\_Odgaard](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mads_odgaard/32/20087_2.png) [@Mads\_Odgaard](https://discuss.elastic.co/u/Mads_Odgaard)\
**Post date:** [July 15, 2017, 2:29pm UTC](https://discuss.elastic.co/t/use-random-score-along-with-multiple-filter/93264/1 "2017-07-15T14:29:30Z")

</div>

Hello.

I am quite new to Elasticsearch, and I've been trying my way around, but I just can't seem to get this to work exactly the way I want.

I wish to to retrieve 3 random documents based on filters.  
Lets just take two, so both of these needs to be true

- Where "propertyName" == "hot"
- Where "active" == true

Along with then it should use the random\_score function, I've tried combining those two, but with no help.

[https://pastebin.com/vYqJPA1i](https://pastebin.com/vYqJPA1i)

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [July 21, 2017, 2:28pm UTC](https://discuss.elastic.co/t/use-random-score-along-with-multiple-filter/93264/2 "2017-07-21T14:28:54Z")

</div>

How is your query behaving relative to what you want? What's wrong about it?

I think I'd probably structure the query a bit more like this, although your example looks like it would work too.

```auto
{
  "size": 3,
  "query": {
    "bool": {
      "filter": [
        {
            "term" : {"propertyName" : "hot"}
        },
        {
            "term" : {"active" : true}
        }
      ],
      "must": {
        {
          "function_score": {
            "functions": [
                {
                    "random_score": {
                        "seed": seed
                    }
                }
            ],
            "boost_mode": "replace"
          }
        }
      }
    }    
  }
}

```

E.g. use a boolean query, put the term's inside the filter clause, and then use the `function_score` in the must clause so it does random scoring.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 18, 2017, 2:29pm UTC](https://discuss.elastic.co/t/use-random-score-along-with-multiple-filter/93264/3 "2017-08-18T14:29:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
