Default token in Aanlyzer if emitted tokens are empty

Hello Experts,

The requirement is - when firing a query on index, we have one big Elastic Query DSL query built to run a a search on the index.

For one of the property field, we have applied a custom analyzer. 

One of the Filter used in the analyzer is a synonym translator, which produces one of the 4 expected tokens based on input string/token.

***IF nothing matches, is there a way to test if emitted tokens are null - only then set "xyz" as default output token ?***

"CustomTranslator" : {
"type" : "synonym",
"synonyms" : [
"volunt,voluntari,chip,regist => typeA",
"program,event,particip,partak,regist => typeB",
"contribut,donat,donor,give,provid,sponsor,fund,raise,money,support => typeC",
"enlist,associat,enrol,join,member,membership,regist => typeD",

My custom analyzer is like this

"MyCustomTypeAnalyzer" : {
"filter" : [
"tokenizer" : "standard"

If the input text had no matching synonym I get only empty token array. But I need to place this in a must block (i.e. this CustomTypeAnalyzer is applied on a property in a query which is used in a must query block.

So it cannot be empty, I need a default token to be emited by the Analyzer, if my choice of default token is 'typeA', then I need my analyzer to emit the default token only if the CustomTranlator did not yeild any tokens.

How can I do it ?

I tried conditional filter, but that too seems to operate only on input tokens only.

I basically need to be able to test if emitted tokens are null.

I cannot run multiple queries, my query builder will run and fire one search query on the index, so I want my Custom Analyzer itself to be conditionally able to emit a default token if the emitted tokens were to be null.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.