# Search with Synonyms do not to work

**URL:** <https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912>\
**Category:** Elasticsearch\
**Created:** [July 8, 2025, 12:13pm UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912 "2025-07-08T12:13:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreAT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreat/32/140410_2.png) [@AndreAT](https://discuss.elastic.co/u/AndreAT)\
**Post date:** [July 8, 2025, 12:13pm UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912/1 "2025-07-08T12:13:44Z")

</div>

Hi, with great assistence I was able to add own synonym file to my search.

> [@Synonyms with FSCrawler](https://discuss.elastic.co/t/synonyms-with-fscrawler/379785):
>
> Hi, I like to use synonym\_path to assign a couple of synonyms to optimize my search. My enviroment is setup with Elasticsearch 8.15.1 and FSCrawler and after some study I figure out that I can't add mapping as done in common tuturials as there's already a mapper assigned (by FSCrawler I think). So when I try PUT /my\_index/\_mapping { "properties": { "content": { "type": "text", "analyzer": "my\_synonym\_analyzer" } } } I get an error { "error": { "root\_cause": [ …

After updating the template I delete the index and use -restart to initial (as David mentioned).

The settings now looking like this:

```auto
{
  "component_templates": [
    {
      "name": "fscrawler_settings_total_fields",
      "component_template": {
        "template": {
          "settings": {
            "index": {
              "mapping": {
                "total_fields": {
                  "limit": "2000"
                }
              }
            }
          }
        }
      }
    },
    {
      "name": "fscrawler_mapping_file",
      "component_template": {
        "template": {
          "mappings": {
            "properties": {
              "file": {
                "properties": {
                  "extension": {
                    "type": "keyword"
                  },
                  "filename": {
                    "store": true,
                    "type": "keyword"
                  },
                  "indexed_chars": {
                    "type": "long"
                  },
                  "last_accessed": {
                    "format": "date_optional_time",
                    "type": "date"
                  },
                  "content_type": {
                    "type": "keyword"
                  },
                  "indexing_date": {
                    "format": "date_optional_time",
                    "type": "date"
                  },
                  "created": {
                    "format": "date_optional_time",
                    "type": "date"
                  },
                  "checksum": {
                    "type": "keyword"
                  },
                  "filesize": {
                    "type": "long"
                  },
                  "last_modified": {
                    "format": "date_optional_time",
                    "type": "date"
                  },
                  "url": {
                    "index": false,
                    "type": "keyword"
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "name": "fscrawler_mapping_attributes",
      "component_template": {
        "template": {
          "mappings": {
            "properties": {
              "attributes": {
                "properties": {
                  "owner": {
                    "type": "keyword"
                  },
                  "group": {
                    "type": "keyword"
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "name": "fscrawler_mapping_path",
      "component_template": {
        "template": {
          "settings": {
            "index": {
              "analysis": {
                "analyzer": {
                  "fscrawler_path": {
                    "tokenizer": "fscrawler_path"
                  }
                },
                "tokenizer": {
                  "fscrawler_path": {
                    "type": "path_hierarchy"
                  }
                }
              }
            }
          },
          "mappings": {
            "properties": {
              "path": {
                "properties": {
                  "virtual": {
                    "type": "keyword",
                    "fields": {
                      "tree": {
                        "fielddata": true,
                        "analyzer": "fscrawler_path",
                        "type": "text"
                      },
                      "fulltext": {
                        "type": "text"
                      }
                    }
                  },
                  "root": {
                    "type": "keyword"
                  },
                  "real": {
                    "type": "keyword",
                    "fields": {
                      "tree": {
                        "fielddata": true,
                        "analyzer": "fscrawler_path",
                        "type": "text"
                      },
                      "fulltext": {
                        "type": "text"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "name": "fscrawler_alias",
      "component_template": {
        "template": {
          "aliases": {
            "fscrawler": {}
          }
        }
      }
    },
    {
      "name": "fscrawler_mapping_meta",
      "component_template": {
        "template": {
          "mappings": {
            "dynamic_templates": [
              {
                "raw_as_text": {
                  "path_match": "meta.raw.*",
                  "mapping": {
                    "type": "text",
                    "fields": {
                      "keyword": {
                        "ignore_above": 256,
                        "type": "keyword"
                      }
                    }
                  }
                }
              }
            ],
            "properties": {
              "meta": {
                "properties": {
                  "date": {
                    "format": "date_optional_time",
                    "type": "date"
                  },
                  "altitude": {
                    "type": "text"
                  },
                  "keywords": {
                    "type": "text"
                  },
                  "modifier": {
                    "type": "text"
                  },
                  "latitude": {
                    "type": "text"
                  },
                  "rating": {
                    "type": "byte"
                  },
                  "description": {
                    "type": "text"
                  },
                  "language": {
                    "type": "keyword"
                  },
                  "source": {
                    "type": "text"
                  },
                  "title": {
                    "type": "text"
                  },
                  "creator_tool": {
                    "type": "keyword"
                  },
                  "type": {
                    "type": "text"
                  },
                  "relation": {
                    "type": "text"
                  },
                  "contributor": {
                    "type": "text"
                  },
                  "rights": {
                    "type": "text"
                  },
                  "metadata_date": {
                    "format": "date_optional_time",
                    "type": "date"
                  },
                  "longitude": {
                    "type": "text"
                  },
                  "coverage": {
                    "type": "text"
                  },
                  "identifier": {
                    "type": "text"
                  },
                  "comments": {
                    "type": "text"
                  },
                  "author": {
                    "type": "text"
                  },
                  "created": {
                    "format": "date_optional_time",
                    "type": "date"
                  },
                  "format": {
                    "type": "text"
                  },
                  "publisher": {
                    "type": "text"
                  },
                  "print_date": {
                    "format": "date_optional_time",
                    "type": "date"
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "name": "fscrawler_settings_shards",
      "component_template": {
        "template": {
          "settings": {
            "index": {
              "number_of_shards": "1"
            }
          }
        }
      }
    },
    {
      "name": "fscrawler_mapping_content",
      "component_template": {
        "template": {
          "settings": {
            "index": {
              "analysis": {
                "filter": {
                  "my_synonym_filter": {
                    "type": "synonym",
                    "synonyms_path": "synonyms.txt",
                    "updateable": "true"
                  }
                },
                "analyzer": {
                  "my_synonym_analyzer": {
                    "filter": [
                      "lowercase",
                      "my_synonym_filter"
                    ],
                    "tokenizer": "standard"
                  }
                }
              }
            }
          }
        }
      }
    },
    {
      "name": "fscrawler_mapping_attachment",
      "component_template": {
        "template": {
          "mappings": {
            "properties": {
              "attachment": {
                "type": "binary",
                "doc_values": false
              }
            }
          }
        }
      }
    }
  ]
}

```

The file **synonyms.txt** is stored at **..\elasticsearch\config\synonyms.txt** and contains this sample:

```auto
aws, amazon web service

```

But it has no effect.  
When I search **aws** I get:

```auto
EC2, **AWS** EFS, **AWS** FSx, **AWS** ALB, **AWS** NLB, **AWS** Systems Manager, **AWS** Secrets Manager, **AWS** Parameter Store.,

```

But for my understanding should searching for amazon web service return at least something similar but it's complete different scoring:

```auto
**web** services, and APIs using **Web** API. ).Proﬁcient in **Web** Services, SOAP, XML, CSS, HTML5, AJAX and JavaScript..Utilized contemporary design to create concise web sites for speciﬁc client needs..Services (Facebook, Gmaps, Bing Maps, YouTube, Flickr, Panoramio, **Amazon** S3), etc.

```

Did I miss something or what can be the reason?

Thanks, Andre

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 8, 2025, 12:38pm UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912/2 "2025-07-08T12:38:46Z")

</div>

First, you need to test the `my_synonym_analyzer` analyzer to check how it behaves.

This can be done by running the [\_analyze API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-analyze):

```auto
GET /fscrawler/_analyze
{
  "analyzer": "my_synonym_analyzer",
  "text": "AWS"
}

```

```auto
GET /fscrawler/_analyze
{
  "analyzer": "my_synonym_analyzer",
  "text": "Amazon Web Service"
}

```

What are the outputs?

But anyway, the component template is “wrong”:

```auto
    {
      "name": "fscrawler_mapping_content",
      "component_template": {
        "template": {
          "settings": {
            "index": {
              "analysis": {
                "filter": {
                  "my_synonym_filter": {
                    "type": "synonym",
                    "synonyms_path": "synonyms.txt",
                    "updateable": "true"
                  }
                },
                "analyzer": {
                  "my_synonym_analyzer": {
                    "filter": [
                      "lowercase",
                      "my_synonym_filter"
                    ],
                    "tokenizer": "standard"
                  }
                }
              }
            }
          }
        }
      }
    }

```

It should have this part which seems to be missing:

```auto
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "my_synonym_analyzer"
      }
      }
    }
  }

```

Check what the final mapping is with:

```auto
GET fscrawler/_mapping

```

---

<div class="post-metadata">

**Author:** ![AndreAT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreat/32/140410_2.png) [@AndreAT](https://discuss.elastic.co/u/AndreAT)\
**Post date:** [July 8, 2025, 1:03pm UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912/3 "2025-07-08T13:03:27Z")

</div>

Hi again,

the output looks good for my understanding:

```auto
{
  "tokens": [
    {
      "token": "aws",
      "start_offset": 0,
      "end_offset": 3,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "amazon",
      "start_offset": 0,
      "end_offset": 3,
      "type": "SYNONYM",
      "position": 0
    },
    {
      "token": "web",
      "start_offset": 0,
      "end_offset": 3,
      "type": "SYNONYM",
      "position": 1
    },
    {
      "token": "service",
      "start_offset": 0,
      "end_offset": 3,
      "type": "SYNONYM",
      "position": 2
    }
  ]
}

{
  "tokens": [
    {
      "token": "amazon",
      "start_offset": 0,
      "end_offset": 6,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "aws",
      "start_offset": 0,
      "end_offset": 18,
      "type": "SYNONYM",
      "position": 0,
      "positionLength": 3
    },
    {
      "token": "web",
      "start_offset": 7,
      "end_offset": 10,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "service",
      "start_offset": 11,
      "end_offset": 18,
      "type": "<ALPHANUM>",
      "position": 2
    }
  ]
}

```

And these are the mappings:

```auto
{
  "resumes": {
    "mappings": {
      "dynamic_templates": [
        {
          "raw_as_text": {
            "path_match": "meta.raw.*",
            "mapping": {
              "fields": {
                "keyword": {
                  "ignore_above": 256,
                  "type": "keyword"
                }
              },
              "type": "text"
            }
          }
        }
      ],
      "properties": {
        "attachment": {
          "type": "binary"
        },
        "attributes": {
          "properties": {
            "group": {
              "type": "keyword"
            },
            "owner": {
              "type": "keyword"
            }
          }
        },
        "content": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "file": {
          "properties": {
            "checksum": {
              "type": "keyword"
            },
            "content_type": {
              "type": "keyword"
            },
            "created": {
              "type": "date",
              "format": "date_optional_time"
            },
            "extension": {
              "type": "keyword"
            },
            "filename": {
              "type": "keyword",
              "store": true
            },
            "filesize": {
              "type": "long"
            },
            "indexed_chars": {
              "type": "long"
            },
            "indexing_date": {
              "type": "date",
              "format": "date_optional_time"
            },
            "last_accessed": {
              "type": "date",
              "format": "date_optional_time"
            },
            "last_modified": {
              "type": "date",
              "format": "date_optional_time"
            },
            "url": {
              "type": "keyword",
              "index": false
            }
          }
        },
        "meta": {
          "properties": {
            "altitude": {
              "type": "text"
            },
            "author": {
              "type": "text"
            },
            "comments": {
              "type": "text"
            },
            "contributor": {
              "type": "text"
            },
            "coverage": {
              "type": "text"
            },
            "created": {
              "type": "date",
              "format": "date_optional_time"
            },
            "creator_tool": {
              "type": "keyword"
            },
            "date": {
              "type": "date",
              "format": "date_optional_time"
            },
            "description": {
              "type": "text"
            },
            "format": {
              "type": "text"
            },
            "identifier": {
              "type": "text"
            },
            "keywords": {
              "type": "text"
            },
            "language": {
              "type": "keyword"
            },
            "latitude": {
              "type": "text"
            },
            "longitude": {
              "type": "text"
            },
            "metadata_date": {
              "type": "date",
              "format": "date_optional_time"
            },
            "modifier": {
              "type": "text"
            },
            "print_date": {
              "type": "date",
              "format": "date_optional_time"
            },
            "publisher": {
              "type": "text"
            },
            "rating": {
              "type": "byte"
            },
            "relation": {
              "type": "text"
            },
            "rights": {
              "type": "text"
            },
            "source": {
              "type": "text"
            },
            "title": {
              "type": "text"
            },
            "type": {
              "type": "text"
            }
          }
        },
        "path": {
          "properties": {
            "real": {
              "type": "keyword",
              "fields": {
                "fulltext": {
                  "type": "text"
                },
                "tree": {
                  "type": "text",
                  "analyzer": "fscrawler_path",
                  "fielddata": true
                }
              }
            },
            "root": {
              "type": "keyword"
            },
            "virtual": {
              "type": "keyword",
              "fields": {
                "fulltext": {
                  "type": "text"
                },
                "tree": {
                  "type": "text",
                  "analyzer": "fscrawler_path",
                  "fielddata": true
                }
              }
            }
          }
        }
      }
    }
  }
}

```

Of course I remember the part with missing bracket but after you solve it it response no error.

Can I solve it in this way?

```auto
PUT /my_index/_mapping
{
  "properties": {
    "content": {
      "type": "text",
      "analyzer": "my_synonym_analyzer"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 8, 2025, 1:51pm UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912/4 "2025-07-08T13:51:46Z")

</div>

You need to delete the existing index and recreate it:

```auto
DELETE fscrawler
PUT fscrawler

```

If you still see the following when calling `GET fscrawler/_mapping`:

```json
        "content": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },

```

Then something is wrong. And it won’t work with synonyms as the analyzer is not properly set.

---

<div class="post-metadata">

**Author:** ![AndreAT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreat/32/140410_2.png) [@AndreAT](https://discuss.elastic.co/u/AndreAT)\
**Post date:** [July 8, 2025, 2:49pm UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912/5 "2025-07-08T14:49:13Z")

</div>

I think this is the issue.  
When I execute

```auto
PUT _component_template/myindex_mapping_content
{
  "template": {
    "settings": {
      "analysis": {
        "filter": {
          "my_synonym_filter": {
            "type": "synonym",
            "synonyms_set": "my-synonym-set",
            "updateable": true
          }
        },
        "analyzer": {
          "my_synonym_analyzer": {
            "tokenizer": "standard",
            "filter": [
              "lowercase",
              "my_synonym_filter"
            ]
          }
        }
    }
  },
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "my_synonym_analyzer"
      }
      }
    }
  }
}

```

result is

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_exception",
        "reason": "analyzer [my_synonym_analyzer] contains filters [my_synonym_filter] that are not allowed to run in index time mode."
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping: analyzer [my_synonym_analyzer] contains filters [my_synonym_filter] that are not allowed to run in index time mode.",
    "caused_by": {
      "type": "mapper_exception",
      "reason": "analyzer [my_synonym_analyzer] contains filters [my_synonym_filter] that are not allowed to run in index time mode."
    }
  },
  "status": 400
}

```

I can exclude

```auto
"updateable": true

```

and result is

```auto
{
  "acknowledged": true
}

```

but when I execute **GET myindex/\_mapping** I still see

```auto
        "content": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 8, 2025, 6:57pm UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912/6 "2025-07-08T18:57:56Z")

</div>

But did you run:

```auto
DELETE myindex
PUT myindex

```

---

<div class="post-metadata">

**Author:** ![AndreAT](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreat/32/140410_2.png) [@AndreAT](https://discuss.elastic.co/u/AndreAT)\
**Post date:** [July 9, 2025, 9:59am UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912/7 "2025-07-09T09:59:15Z")

</div>

That's it - I missed the PUT.  
So everything is fine, thank you once again.

If you don't mind some questions to get it.  
What is the PUT for?  
After a DELETE a PUT looks a bit curious as I would expect that after a DELETE the index is deleted?

The same with **PUT \_component\_template/myindex\_mapping\_content** and the error result:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_exception",
        "reason": "analyzer [my_synonym_analyzer] contains filters [my_synonym_filter] that are not allowed to run in index time mode."
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping: analyzer [my_synonym_analyzer] contains filters [my_synonym_filter] that are not allowed to run in index time mode.",
    "caused_by": {
      "type": "mapper_exception",
      "reason": "analyzer [my_synonym_analyzer] contains filters [my_synonym_filter] that are not allowed to run in index time mode."
    }
  },
  "status": 400
}

```

It runs fine now even if there'd been an error previously.

Anyway I'm more than happy that it works now!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 9, 2025, 2:17pm UTC](https://discuss.elastic.co/t/search-with-synonyms-do-not-to-work/379912/8 "2025-07-09T14:17:30Z")

</div>

> [@AndreAT](#):
>
> What is the PUT for?

You don’t have to do this manually as anyway Elasticsearch will do it behind the scene when the first document is sent by FSCrawler.

`PUT index`, creates the index.
