# Understanding Percolator query extraction

**URL:** <https://discuss.elastic.co/t/understanding-percolator-query-extraction/168465>\
**Category:** Elasticsearch\
**Created:** [February 14, 2019, 6:19pm UTC](https://discuss.elastic.co/t/understanding-percolator-query-extraction/168465 "2019-02-14T18:19:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![psylone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/psylone/32/31186_2.png) [@psylone](https://discuss.elastic.co/u/psylone)\
**Post date:** [February 14, 2019, 6:19pm UTC](https://discuss.elastic.co/t/understanding-percolator-query-extraction/168465/1 "2019-02-14T18:19:37Z")

</div>

Hi, all!

Fighting with performance of the `percolate` query.

The first thing I need to understand is the conditions when terms [can be extracted](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-percolate-query.html#how-it-works) from the query during the indexing phase.

What I need to understand is whether terms will be extracted from the `bool` query in its `filter` part?

For example, giving this mapping:

```auto
curl "localhost:9200/queries/_mapping?pretty"
{
  "queries": {
    "mappings": {
      "_doc": {
        "dynamic": "false",
        "properties": {
          "location": {
            "type": "geo_point"
          },
          "query": {
            "type": "percolator"
          },
          "status": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

```

And this query:

```auto
curl -X PUT "localhost:9200/queries/_doc/1" -d ' {
  "query": {
    "bool": {
      "filter": [{
          "term": {
            "status": "active"
          }
        },
        {
          "geo_distance": {
            "distance": "15km",
            "location": {
              "lat": 55.8899,
              "lon": 37.5926
            }
          }
        }
      ],
      "must": [],
      "must_not": []
    }
  }
}
'

```

Will `{"term": {"status": "active"}}` be extracted or I need to manually index it this way:

```auto
curl -X PUT "localhost:9200/queries/_doc/1" -d ' {
  "status": "active",
  "query": {
    "bool": {
      "filter": [
        {
          "geo_distance": {
            "distance": "15km",
            "location": {
              "lat": 55.8899,
              "lon": 37.5926
            }
          }
        }
      ],
      "must": [],
      "must_not": []
    }
  }
}
'

```

and modify my percolate query from this:

```auto
{
  "query": {
    "bool": {
      "filter": [
        {
          "percolate": {
            "field": "query",
            "document": {
              "title": "Some document title",
              "status": "active"
            }
          }
        }
      ]
    }
  }
}

```

to this:

```auto
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "status": "active"
          }
        },
        {
          "percolate": {
            "field": "query",
            "document": {
              "title": "Some document title",
              "status": "active"
            }
          }
        }
      ]
    }
  }
}

```

Or may be I need to move `filter` part of the `bool` query to its `must` part?

Massive thank you in advance!

---

<div class="post-metadata">

**Author:** ![psylone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/psylone/32/31186_2.png) [@psylone](https://discuss.elastic.co/u/psylone)\
**Post date:** [February 15, 2019, 12:59pm UTC](https://discuss.elastic.co/t/understanding-percolator-query-extraction/168465/2 "2019-02-15T12:59:59Z")

</div>

After some IDE debugging I realized that terms are extracted in both `bool` query parts: `must` and `filter`. Extracted information is stored in the document (indexed query) field.

Not sure how this information is used in the `percolate` query.

---

<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:** [March 15, 2019, 1:00pm UTC](https://discuss.elastic.co/t/understanding-percolator-query-extraction/168465/3 "2019-03-15T13:00:06Z")

</div>

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