IMPORTANT: elasticsearch.js has been replaced by the new Elasticsearch JavaScript client. We strongly advise you to migrate to the new client. To learn more, see the migration guide.
percolate
editpercolate
editclient.percolate([params, [callback]])
Match a document against registered percolator queries.
Check the API Conventions and the elasticsearch docs for more information pertaining to this method.
First, Register queries named “alert-1” and “alert-2” for the “myindex” index.
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.
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' }
// ]
// }
Params
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|