[Kibana 4] How do I feed a complex query result to terms visualization?

Is it possible to use a complex query as a data source for a terms visualization, rather than just a simple field specification?

You can specify extra json to be added to the KB query in the Advanced option of a visualisation.
Is that what you're after?

Maybe. What kind of JSON should I put there?
Kibana 4 looks quite alien after the third version :frowning:

What sort of query do you want to do?

The ideal solution would be to use a Lucene query as I was doing in Kibana 3; something like:

FieldX:SomeValue1 OR FieldY:SomeValue2

(and then use some FieldZ from the selected records as the input to the terms visualization)