# Default token in Aanlyzer if emitted tokens are empty

**URL:** https://discuss.elastic.co/t/default-token-in-aanlyzer-if-emitted-tokens-are-empty/355971
**Category:** Elasticsearch
**Tags:** eql-elastic-query-language
**Created:** [March 22, 2024, 8:50am UTC](https://discuss.elastic.co/t/default-token-in-aanlyzer-if-emitted-tokens-are-empty/355971 "2024-03-22T08:50:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sumanth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sumanth/32/132897_2.png) [@Sumanth](https://discuss.elastic.co/u/Sumanth)
#### Post date: [March 22, 2024, 8:50am UTC](https://discuss.elastic.co/t/default-token-in-aanlyzer-if-emitted-tokens-are-empty/355971/1 "2024-03-22T08:50:40Z")

</div>

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" : [  
"EngStopWordsRemover",  
"lowercase",  
"EngStemmer",  
"CustomTranslator",  
"SpaceTokenRemover",  
"unique"  
],  
"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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [April 19, 2024, 8:50am UTC](https://discuss.elastic.co/t/default-token-in-aanlyzer-if-emitted-tokens-are-empty/355971/2 "2024-04-19T08:50:44Z")

</div>

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