.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
[source,js]
---------
await Promise.all([
  client.index({
    index: 'myindex',
    type: '.percolator',
    id: 'alert-1',
    body: {
      // This query will be run against documents sent to percolate
      query: {
        query_string: {
          query: 'foo'
        }
      }
    }
  }),

  client.index({
    index: 'myindex',
    type: '.percolator',
    id: 'alert-2',
    body: {
      // This query will also be run against documents sent to percolate
      query: {
        query_string: {
          query: 'bar'
        }
      }
    }
  })
]);
---------

.Then you can send documents to learn which query `_percolator` queries they match
[source,js]
---------
const response1 = await client.percolate({
  index: 'myindex',
  type: 'mytype',
  body: {
    doc: {
      title: "Foo"
    }
  }
});

// response1 should look something like
// {
//   total: 1,
//   matches: [ { _index: 'myindex', _id: 'alert-1' } ]
// }

const response2 = await client.percolate({
  index: 'myindex',
  type: 'mytype',
  body: {
    doc: {
      title: "Foo Bar"
    }
  }
});

// response2 should look something like
// {
//   total: 2,
//   matches: [
//     { _index: 'myindex', _id: 'alert-1' },
//     { _index: 'myindex', _id: 'alert-2' }
//   ]
// }
---------
