PaginatedJsonQueryElasticsearch 2025.10.9.21

Bundle

org.apache.nifi | nifi-elasticsearch-restapi-nar

Description

A processor that allows the user to run a paginated query (with aggregations) written with the Elasticsearch JSON DSL. It will use the flowfile’s content for the query unless the QUERY attribute is populated. Search After/Point in Time queries must include a valid “sort” field.

Tags

elasticsearch, elasticsearch7, elasticsearch8, elasticsearch9, json, page, query, read, scroll

Input Requirement

REQUIRED

Supports Sensitive Dynamic Properties

false

Properties

PropertyDescription
Aggregation Results FormatFormat of Aggregation output.
Aggregation Results SplitOutput a flowfile containing all aggregations or one flowfile for each individual aggregation.
AggregationsOne or more query aggregations (or “aggs”), in JSON syntax. Ex: {“items”: {“terms”: {“field”: “product”, “size”: 10}}}
Client ServiceAn Elasticsearch client service to use for running queries.
FieldsFields of indexed documents to be retrieved, in JSON syntax. Ex: [“user.id”, “http.response.*”, {“field”: “@timestamp”, “format”: “epoch_millis”}]
IndexThe name of the index to use.
Max JSON Field String LengthThe maximum allowed length of a string value when parsing a JSON document or attribute.
Output No HitsOutput a “hits” flowfile even if no hits found for query. If true, an empty “hits” flowfile will be output even if “aggregations” are output.
Pagination Keep AlivePagination “keep_alive” period. Period Elasticsearch will keep the scroll/pit cursor alive in between requests (this is not the time expected for all pages to be returned, but the maximum allowed time for requests between page retrievals).
Pagination TypePagination method to use. Not all types are available for all Elasticsearch versions, check the Elasticsearch docs to confirm which are applicable and recommended for your service.
QueryA query in JSON syntax, not Lucene syntax. Ex: {“query”:{“match”:{“somefield”:”somevalue”}}}. If this parameter is not set, the query will be read from the flowfile content. If the query (property and flowfile content) is empty, a default empty JSON Object will be used, which will result in a “match_all” query in Elasticsearch.
Query AttributeIf set, the executed query will be set on each result flowfile in the specified attribute.
Query ClauseA “query” clause in JSON syntax, not Lucene syntax. Ex: {“match”:{“somefield”:”somevalue”}}. If the query is empty, a default JSON Object will be used, which will result in a “match_all” query in Elasticsearch.
Query Definition StyleHow the JSON Query will be defined for use by the processor.
Script FieldsFields to created using script evaluation at query runtime, in JSON syntax. Ex: {“test1”: {“script”: {“lang”: “painless”, “source”: “doc[ ‘price’].value * 2”}}, “test2”: {“script”: {“lang”: “painless”, “source”: “doc[ ‘price’].value * params.factor”, “params”: {“factor”: 2.0}}}}
Search Results FormatFormat of Hits output.
Search Results SplitOutput a flowfile containing all hits or one flowfile for each individual hit or one flowfile containing all hits from all paged responses.
SizeThe maximum number of documents to retrieve in the query. If the query is paginated, this “size” applies to each page of the query, not the “size” of the entire result set.
SortSort results by one or more fields, in JSON syntax. Ex: [{“price” : {“order” : “asc”, “mode” : “avg”}}, {“post_date” : {“format”: “strict_date_optional_time_nanos”}}]
TypeThe type of this document (used by Elasticsearch for indexing and searching).

Relationships

NameDescription
aggregationsAggregations are routed to this relationship.
failureAll flowfiles that fail for reasons unrelated to server availability go to this relationship.
hitsSearch hits are routed to this relationship.
originalAll original flowfiles that don’t cause an error to occur go to this relationship.

Writes attributes

NameDescription
mime.typeapplication/json
aggregation.nameThe name of the aggregation whose results are in the output flowfile
aggregation.numberThe number of the aggregation whose results are in the output flowfile
page.numberThe number of the page (request), starting from 1, in which the results were returned that are in the output flowfile
hit.countThe number of hits that are in the output flowfile
elasticsearch.query.errorThe error message provided by Elasticsearch if there is an error querying the index.

See also