# Percolate Queries

**URL:** https://discuss.elastic.co/t/percolate-queries/162420
**Category:** Elasticsearch
**Created:** [December 29, 2018, 4:32pm UTC](https://discuss.elastic.co/t/percolate-queries/162420 "2018-12-29T16:32:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sebidchi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebidchi/32/39248_2.png) [@sebidchi](https://discuss.elastic.co/u/sebidchi)
#### Post date: [December 29, 2018, 4:32pm UTC](https://discuss.elastic.co/t/percolate-queries/162420/1 "2018-12-29T16:32:13Z")

</div>

Hello,

Following recommendation from one of you, I changed the approach to perform queries to percolate.

I've store each one of the `named_queries` and it returns me the results "more or less" in the way I need.

However, my app need filter those queries by dynamic params into the request and now with percolate I´m not able to get the results that I want.

Here's my mapping

```auto
{
  "template": "documents-en",
  "settings": {
    "index": {
      "number_of_shards": 5,
      "number_of_replicas": 0
    },
    "analysis": {
      "filter": {
        "english_stop": {
          "type": "stop",
          "stopwords": "_english_"
        },
        "english_keywords": {
          "type": "keyword_marker",
          "keywords": ["example"]
        },
        "english_stemmer": {
          "type": "stemmer",
          "language": "english"
        },
        "english_possessive_stemmer": {
          "type": "stemmer",
          "language": "possessive_english"
        }
      },
      "analyzer": {
        "rebuilt_english": {
          "tokenizer": "standard",
          "filter": [
            "english_possessive_stemmer",
            "lowercase",
            "english_stop",
            "english_keywords",
            "english_stemmer"
          ]
        }
      }
    }
  },
  "mappings": {
    "document": {
      "properties": {
        "text": {
          "type": "text",
          "analyzer": "rebuilt_english"
        },
        "goal": {
          "type": "keyword"
        },
        "blocking": {
          "type": "boolean"
        },
        "country_code": {
          "type": "keyword",
          "null_value": "_null_"
        },
        "query": {
          "type": "percolator"
        }
      }
    }
  }
}

```

Here an example of each query stored

```auto
{
                "_index": "documents-en",
                "_type": "document",
                "_id": "aQxj-mcBOTQdqKhHFO56",
                "_score": 1,
                "_source": {
                    "size": 1,
                    "query": {
                        "bool": {
                            "must": {
                                "simple_query_string": {
                                    "query": "+\\\"\"Marlboro coupons\\\"\" ",
                                    "fields": [
                                        "text"
                                    ],
                                    "default_operator": "and",
                                    "_name": 157
                                }
                            }
                        }
                    },
                    "goal": 2,
                    "country_code": null,
                    "blocking": true
                }
            }

```

And here the request that I do to get results:

```auto
{
	"query": {
		"percolate": {
			"field": "query",
			"document": {
				"text": "We specialize baby for adoption birth call girl control pills in all phones and tablet repairs iPhone 6 starting at just 25 bucks Same day repairs Low price keef Superior on catcher We will beat any in shirt Call firestick games ::: ::: Masa sandalye masa sandalye masa sandalye",
				"goal": 3,
				"blocking": true,
				"country_code": "TR"
			}
		}
	},
	"highlight": {
		"order": "none",
		"pre_tags": ["<span class=\"highlight\">"],
		"post_tags": ["<\/span>"],
		"fields": {
			"text": {
				"number_of_fragments": 0,
				"force_source": true
			}
		}
	}
}

```

The point here is I need to prioritize results where `blocking`: true and match with given `country_code` or `null` and given `goal` or 1.

Any ideas ?

Thanks in advance

---

<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: [January 26, 2019, 4:32pm UTC](https://discuss.elastic.co/t/percolate-queries/162420/2 "2019-01-26T16:32:24Z")

</div>

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