# Synonym token filter question

**URL:** https://discuss.elastic.co/t/synonym-token-filter-question/225892
**Category:** Elasticsearch
**Created:** [March 31, 2020, 2:45pm UTC](https://discuss.elastic.co/t/synonym-token-filter-question/225892 "2020-03-31T14:45:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nages](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nages/32/46943_2.png) [@nages](https://discuss.elastic.co/u/nages)
#### Post date: [March 31, 2020, 2:45pm UTC](https://discuss.elastic.co/t/synonym-token-filter-question/225892/1 "2020-03-31T14:45:26Z")

</div>

I created a test index with synonym token filter

```
> PUT /synonyms-index

```

> ```
> {
> 
> "settings": {
> 
> "analysis": {
> 
> "filter": {
> 
> "my_synonym_filter": {
> 
> "type": "synonym",
> 
> "synonyms": [
> 
> "shares","equity","stock"
> 
> ]
> 
> }
> 
> },
> 
> "analyzer": {
> 
> "my_synonyms": {
> 
> "tokenizer": "standard",
> 
> "filter": [
> 
> "lowercase",
> 
> "my_synonym_filter"
> 
> ]
> 
> }
> 
> }
> 
> }
> 
> }
> 
> }
> 
> ```

Then I ran analyze API ,  
post synonyms-index/\_analyze  
{  
"analyzer":"my\_synonyms",  
"text":"equity awesome"  
}

I got the following response to see what token got into inverted index and I was expecting "shares" and "stock" needed to be added as per the synonym rule, but it doesn't seem so. Am I missing anything here ?

```
{
  "tokens": [
    {
      "token": "equity",
      "start_offset": 0,
      "end_offset": 6,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "awesome",
      "start_offset": 7,
      "end_offset": 14,
      "type": "<ALPHANUM>",
      "position": 1
    }
  ]
}

```

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [April 1, 2020, 8:16am UTC](https://discuss.elastic.co/t/synonym-token-filter-question/225892/2 "2020-04-01T08:16:09Z")

</div>

> [@nages](#):
>
> "synonyms": ["shares","equity","stock"]

Hi @nages,

you ran into a common pitfall that I also experienced multiple times when playing with synonyms. Each rule should be its own String, so in your case "shares, equity, stock". In your current setup you have three rules which don't epxand to anything. This is easy to miss, but take a look at this snippet from our [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html#analysis-synonym-tokenfilter) to convince yourself and try it:

```auto
"synonyms" : [
        "i-pod, i pod => ipod",
        "universe, cosmos"
]

```

I a synonym file, which would be the usual way of managing larger collections, each line represents one rule so you don't get this problem there.

Hope this helps.

---

<div class="post-metadata">

### Author: ![nages](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nages/32/46943_2.png) [@nages](https://discuss.elastic.co/u/nages)
#### Post date: [April 1, 2020, 9:03am UTC](https://discuss.elastic.co/t/synonym-token-filter-question/225892/3 "2020-04-01T09:03:43Z")

</div>

strange 🙂 . JSON thing -

I made it as "synonyms": ["shares,equity,stock"] instead of ("synonyms": ["shares","equity","stock"]) - All set 🙂

---

<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 29, 2020, 9:03am UTC](https://discuss.elastic.co/t/synonym-token-filter-question/225892/4 "2020-04-29T09:03:53Z")

</div>

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