papelr
papelr

Reputation: 438

NiFi: QueryElasticSearchHttp: Matching Objects with Expression Language?

I have a NiFi flow where I bring in some data through an API, which I easily route into ElasticSearch.

I have a second flow where I need to use the processor QueryElasticSearchHttp. Within that processor, I have a JSON query:

{
    "query" : { 
        "bool" : {
            "must" : [
                { "match" : { "Example1" : ${Example1} } },
                { "match" : { "ExampleCode" : ${ExampleCode} } }
            ]
        }
    }       
}

I am trying to match the object Example1 and ExampleCode and return the whole column. I've tried to inject expression language into the query. Does not work, and I cannot find an example of how to match on an entire object.

I have tried to put quotation marks like so: "${}".

I get the error:

ERROR [Timer-Driven Process Thread-7] ...from Elasticsearch due to 
Elasticsearch returned code 400 with message Bad Request, transferring 
flow file to failure: 
org.apache.nifi.processors.elasticsearch.UnretryableException: 
Elasticsearch returned code 400 with message Bad Request

The Attributes are also correctly routed, and appear where they need to appear.

What is the correct way to format this? Thanks

Upvotes: 0

Views: 2270

Answers (1)

Jagrut Sharma
Jagrut Sharma

Reputation: 4754

You can try using the JsonQueryElasticsearch processor. A demo flow shown below:

Overall Flow Overall flow

Start Step Start Step

Query ES Step Query ES Step

The JSON query The JSON query

Store Result Step enter image description here

The Controller Service The Controller Service

Output of Run:

$ cd /var/so_out
$ cat 17973351988502 | python -m json.tool
[
    {
        "_id": "o002",
        "_index": "office",
        "_score": 0.26742277,
        "_source": {
            "description": "Shows and events",
            "name": "Tom",
            "title": "Marketing Manager"
        },
        "_type": "doc"
    }
]

Upvotes: 1

Related Questions