percolateedit

client.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

routing

String, String[], Boolean — A comma-separated list of specific routing values

preference

String — Specify the node or shard the operation should be performed on (default: random)

ignoreUnavailable

Boolean — Whether specified concrete indices should be ignored when unavailable (missing or closed)

allowNoIndices

Boolean — Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes _all string or when no indices have been specified)

[expandWildcards=open]

String — Whether to expand wildcard expression to concrete indices that are open, closed or both.

Options
  • "open"
  • "closed"
  • "none"
  • "all"

percolateIndex

String — The index to percolate the document into. Defaults to index.

percolateType

String — The type to percolate document into. Defaults to type.

percolateRouting

String — The routing value to use when percolating the existing document.

percolatePreference

String — Which shard to prefer when executing the percolate request.

percolateFormat

String — Return an array of matching query IDs instead of objects

Options
  • "ids"

version

Number — Explicit version number for concurrency control

versionType

String — Specific version type

Options
  • "internal"
  • "external"
  • "external_gte"
  • "force"

index

String — The index of the document being percolated.

type

String — The type of the document being percolated.

id

String — Substitute the document in the request body with a document that is known by the specified id. On top of the id, the index and type parameter will be used to retrieve the document from within the cluster.

body

Object, JSON — An optional request body, as either JSON or a JSON serializable object. See the elasticsearch docs for details about what can be specified here.

back to top