# Filtered Percolator Queries

**URL:** <https://discuss.elastic.co/t/filtered-percolator-queries/28091>\
**Category:** Elasticsearch\
**Created:** [August 26, 2015, 10:13am UTC](https://discuss.elastic.co/t/filtered-percolator-queries/28091 "2015-08-26T10:13:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fresh83](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fresh83/32/1500_2.png) [@Fresh83](https://discuss.elastic.co/u/Fresh83)\
**Post date:** [August 26, 2015, 10:13am UTC](https://discuss.elastic.co/t/filtered-percolator-queries/28091/1 "2015-08-26T10:13:37Z")

</div>

Im trying to make suggestions to users based on several factors:

•Suggestions MUST only be students from the same college  
•Suggestions MUST match at least one other field  
Here is how I am currently doing it , but this does not seem right or efficent considering most of these fields are bool's .....if the colleges dont line up why bother even doing that query ?

```
 POST /interests_percolator/UNIQUE_INTERESTS/_percolate/
{ 
  "doc":{ 
    "message":"Bring it eminem"
  }
}

DELETE discovery

PUT discovery
{
  "mappings": {
    "user": {
      "properties": {
        "hashtag_bio": {
          "type": "string"
        },
        "college": {
            "type": "string"
        },
        "college_class": {
            "type": "string"
        }
      }
    }
  }
}

PUT /discovery/.percolator/1
{
  "query": {
    "bool": {
    "must": [
        { "match": { "college":{
            "query" : "Oakland University",
            "type" : "phrase"
        }}}
    ],
      "should": [
        { "match": { "hashtag_bio": "#poznasty" }},
        { "match": { "college_class": "BIO_310"}},
        { "match": { "college_class": "WRT_100"}}
      ],
      "minimum_should_match": 1 
    }
  }
}
PUT /discovery/.percolator/2
{
  "query": {
    "bool": {
    "must": [
        { "match": { "college":{
            "query" : "Oakland University",
            "type" : "phrase"
        }}}
    ],
      "should": [
        { "match": { "hashtag_bio": "#Chipotle"}}
      ],
      "minimum_should_match": 1 
    }
  }
}
PUT /discovery/.percolator/3
{
  "query": {
    "bool": {
    "must": [
        { "match": { "college":{
            "query" : "Oakland University",
            "type" : "phrase"
        }}}
    ],
      "should": [
        { "match": { "college_class": "ART_400"}}
      ],
      "minimum_should_match": 1 
    }
  }
}

POST /discovery/user/_percolate/
{ 
  "doc":{ 
    "hashtag_bio":"#Chipotle",
    "college":"Oakland University"
   
  }
}
```

---

<div class="post-metadata">

**Author:** ![Sarwar](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Sarwar](https://discuss.elastic.co/u/Sarwar)\
**Post date:** [August 26, 2015, 11:42am UTC](https://discuss.elastic.co/t/filtered-percolator-queries/28091/2 "2015-08-26T11:42:26Z")

</div>

You may be able to move the college part to a metadata of the percolator item rather than in the query.

e.g

```
PUT /discovery/.percolator/1
{
  "query": {
    "bool": {
      "should": [
        { "match": { "hashtag_bio": "#poznasty" }},
        { "match": { "college_class": "BIO_310"}},
        { "match": { "college_class": "WRT_100"}}
      ],
      "minimum_should_match": 1 
    }
  },
 "college":"Oakland University"
}

```

Then, when you call \_percolate, something like:

```
POST /discovery/user/_percolate/
{ 
  "doc":{ 
    "hashtag_bio":"#Chipotle"
  },
  "filter": {
     "term": { "college": "Oakland University" }
  }
}

```

Hope this helps. For more information, check out [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html#\_filtering\_executed\_queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html#_filtering_executed_queries)

Sarwar

---

<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:** [July 5, 2017, 11:53pm UTC](https://discuss.elastic.co/t/filtered-percolator-queries/28091/3 "2017-07-05T23:53:53Z")

</div>

Closed on July 5, 2017, 11:53pm UTC


