Files
elasticsearch-js/docs/_examples/percolate.asciidoc
Spencer 83a464ac66 Update docs to use async/await (#667)
* [docs] update readme and examples to use async/await

* [apis] regenerate (including updated examples)
2018-05-23 14:31:34 -07:00

73 lines
1.3 KiB
Plaintext

.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' }
// ]
// }
---------