Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Need to plug a variable into a elasticsearch query

avatar
Frequent Visitor

I am trying to roll my own search_after pagination query by saving the last sort values to a db and then retrieving them on the next time I run the query.  Thing is if there are no sort values from the db this means this is a new query and I skip the search_after clause in my query. If I do retrieve a set of sort values from the db then I need to plug them into the query. I am having trouble with the EL statement. This is what I have:

 

 

 

{
	"query": {
		"bool": {
			"must": [
				{"term": {"key1": "value1"}}
			],
			"must_not": [
				{"exists": {"key2": "value2"}}
			],
			"filter": [
				{"range": {"@timestamp": {"lte": "now-1w"}}}
			]
		}			
	}
	${search_after:isEmpty():not():ifElse(', \"search_after\": "${search_after}"', '')},
	"sort": [
		{"@timestamp": "asc"},
		{"value3": "asc"}
	]
}

 

 

 The ${search_after} variable defined as  '[ts int milliseconds, "a key value string"]'  Including the sq brackets.

 

The error I am receiving is:
Unknown key for a VALUE_STRING in search_after line 15 col 20 type parsing exception

 

Does anyone know how to write the variable correctly?

 

1 ACCEPTED SOLUTION

avatar
Frequent Visitor

I solved my problem. The solution is to not wrap the variable with double quotes.

${search_after:isEmpty():not():ifElse(', \"search_after\": ${search_after}', '')},

 

View solution in original post

2 REPLIES 2

avatar
Community Manager

@Phil_I_AM Welcome to the Cloudera Community!

To help you get the best possible solution, I have tagged our NiFi experts @SAMSAL and @MattWho  who may be able to assist you further.

Please keep us updated on your post, and we hope you find a satisfactory solution to your query.


Regards,

Diana Torres,
Senior Community Moderator


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:

avatar
Frequent Visitor

I solved my problem. The solution is to not wrap the variable with double quotes.

${search_after:isEmpty():not():ifElse(', \"search_after\": ${search_after}', '')},