Support Questions

Find answers, ask questions, and share your expertise

Need to plug a variable into a elasticsearch query

avatar
Explorer

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
Explorer

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,
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
Explorer

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

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