updated client.percolate examples to work with latest (reflecting changes to Percolator API as described here: https://www.elastic.co/blog/percolator-redesign-blog-post)
74 lines
1.3 KiB
Plaintext
74 lines
1.3 KiB
Plaintext
.First, Register queries named “alert-1” and “alert-2” for the “myindex” index
|
|
[source,js]
|
|
---------
|
|
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'
|
|
}
|
|
}
|
|
}
|
|
}, function (error, response) {
|
|
// ...
|
|
});
|
|
|
|
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'
|
|
}
|
|
}
|
|
}
|
|
}, function (error, response) {
|
|
// ...
|
|
});
|
|
---------
|
|
|
|
.Then you can send documents to learn which query `_percolator` queries they match
|
|
[source,js]
|
|
---------
|
|
client.percolate({
|
|
index: 'myindex',
|
|
type: 'mytype',
|
|
body: {
|
|
doc: {
|
|
title: "Foo"
|
|
}
|
|
}
|
|
}, function (error, response) {
|
|
// response would equal
|
|
// {
|
|
// total: 1,
|
|
// matches: [ { _index: 'myindex', _id: 'alert-1' } ]
|
|
// }
|
|
});
|
|
|
|
client.percolate({
|
|
index: 'myindex',
|
|
type: 'mytype',
|
|
body: {
|
|
doc: {
|
|
title: "Foo Bar"
|
|
}
|
|
}
|
|
}, function (error, response) {
|
|
// response would equal
|
|
// {
|
|
// total: 2,
|
|
// matches: [
|
|
// { _index: 'myindex', _id: 'alert-1' },
|
|
// { _index: 'myindex', _id: 'alert-2' }
|
|
// ]
|
|
// }
|
|
});
|
|
--------- |