# \_mpercolate on existing documents

**URL:** https://discuss.elastic.co/t/-mpercolate-on-existing-documents/46711
**Category:** Elasticsearch
**Created:** [April 7, 2016, 3:37pm UTC](https://discuss.elastic.co/t/-mpercolate-on-existing-documents/46711 "2016-04-07T15:37:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jhendric98](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jhendric98](https://discuss.elastic.co/u/jhendric98)
#### Post date: [April 7, 2016, 3:37pm UTC](https://discuss.elastic.co/t/-mpercolate-on-existing-documents/46711/1 "2016-04-07T15:37:23Z")

</div>

I see where we can run percolate on existing single documents. I've tested this successfully.  
I've run \_mpercolate on mulitple new documents.

But what about existing multiple documents. I've not found successful syntax to make that work in Sense. I recreated the example index from the docs and then added several documents under my-type. Then I executed this query:

POST /my-index/my-type/\_mpercolate  
also tried GET

results:

{  
"error": {  
"root\_cause": [  
{  
"type": "parse\_exception",  
"reason": "Failed to derive xcontent"  
}  
],  
"type": "parse\_exception",  
"reason": "Failed to derive xcontent"  
},  
"status": 400  
}

Any help is appreciated.

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [April 7, 2016, 6:11pm UTC](https://discuss.elastic.co/t/-mpercolate-on-existing-documents/46711/2 "2016-04-07T18:11:10Z")

</div>

You are probably missing body of the \_mpercolate request. Please take a look at the following example:

```
DELETE /test

PUT /test/doc/1 
{
  "foo": "bar"
}

PUT /test/doc/2 
{
  "foo": "baz"
}

PUT /test/.percolator/p1
{
  "query": {
    "match_all": {}
  }
}

PUT /test/.percolator/p2
{
  "query": {
    "match": {
      "foo": "bar"
    }
  }
}

POST /test/_mpercolate
{"percolate" : {"index" : "test", "type" : "doc", "id":1}}
{}
{"percolate" : {"index" : "test", "type" : "doc", "id":2}}
{}
```

---

<div class="post-metadata">

### Author: ![jhendric98](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jhendric98](https://discuss.elastic.co/u/jhendric98)
#### Post date: [April 7, 2016, 7:20pm UTC](https://discuss.elastic.co/t/-mpercolate-on-existing-documents/46711/3 "2016-04-07T19:20:41Z")

</div>

Thanks Igor, that helps.

I guess I was looking to issue a single command without specifying all the documents to run over first.

In my potential use case, the queries are actually matching logic that categorizes documents. The queries are updated over time with added intelligence.

If I understand this correctly, I'll have to first run a query over my entire index of documents to build the body for \_mpercolate, parse and create this query, then run over my index. Then finally taking the matched results and writing it back to the index.

This will work. I was hoping for just a nice command to run it against all documents in the index.

Thank you for the help.

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [April 7, 2016, 7:29pm UTC](https://discuss.elastic.co/t/-mpercolate-on-existing-documents/46711/4 "2016-04-07T19:29:44Z")

</div>

When you run a percolate command on a document, elasticsearch creates a special index with just this document (or a small group of documents in case of \_mpercolate) and then executes one percolation query at a time on this special index, and then gets rid of this index.

If you want to run percolation on the entire index of existing documents, using percolate API is going to be very wasteful since you already have an index with all documents that you want to percolate against. It will be significantly faster to reverse the process and simply run the updated queries against the index of already indexed documents to see if these queries match anything.

---

<div class="post-metadata">

### Author: ![jhendric98](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jhendric98](https://discuss.elastic.co/u/jhendric98)
#### Post date: [April 7, 2016, 7:33pm UTC](https://discuss.elastic.co/t/-mpercolate-on-existing-documents/46711/5 "2016-04-07T19:33:55Z")

</div>

Good point. Thank you.

---

<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:01pm UTC](https://discuss.elastic.co/t/-mpercolate-on-existing-documents/46711/6 "2017-07-05T23:01:22Z")

</div>


