_mpercolate on existing documents

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.

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}}
{}

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.

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.

Good point. Thank you.