# Synonym configuration

**URL:** <https://discuss.elastic.co/t/synonym-configuration/5202>\
**Category:** Elasticsearch\
**Created:** [August 19, 2011, 7:03pm UTC](https://discuss.elastic.co/t/synonym-configuration/5202 "2011-08-19T19:03:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jessejlt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessejlt/32/2862_2.png) [@jessejlt](https://discuss.elastic.co/u/jessejlt)\
**Post date:** [August 19, 2011, 7:03pm UTC](https://discuss.elastic.co/t/synonym-configuration/5202/1 "2011-08-19T19:03:59Z")

</div>

Greetings!

I'm new to ElasticSearch and could use some quick validation of my  
configuration.

I installed ES via brew on Lion, so ES is installed at:  
/usr/local/Cellar/elasticsearch/0.17.1

My config file lives at:  
/usr/local/Cellar/elasticsearch/0.17.1/config/elasticsearch.yml

And I'm launching ES manually via:  
elasticsearch -f -D es.config=/usr/local/Cellar/elasticsearch/0.17.1/  
config/elasticsearch.yml

Now in my config file (elasticsearch.yml), I have the following index  
definition:

index :  
analysis :  
analyzer :  
standard :  
type : standard

```
    tokenizer :
        myTokenizer1 :
            type : standard

    filter :
        myTokenFilter1 :
            type : synonym
            synonyms_path : synonym.txt

```

And peer to elasticsearch.yml I have created a file named synonym.txt.  
A sample of the data in synonym.txt is:

field type, scan type, field dominance

upper field first, uff

After reading the documentation at:  
[http://www.elasticsearch.org/guide/reference/index-modules/analysis/synonym-tokenfilter.html](http://www.elasticsearch.org/guide/reference/index-modules/analysis/synonym-tokenfilter.html)  
It seems to suggest that that:  
field type == scan type == field dominance  
and  
upper field first == off

as in, they're all considered the same thing.

So to test this, I added a new document:

{ "scan type" : "upper field first" }

and then searched for it using:

curl -XGET [http://localhost:9200/test/records/\_search?q=uff](http://localhost:9200/test/records/_search?q=uff)

But I received no hits, but I would have expected that uff would have  
translated to "upper field first", which should have received a hit.

So I must be doing something wrong, and this is where I need your  
help.

Much thanks!  
-jesse

---

<div class="post-metadata">

**Author:** ![jessejlt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessejlt/32/2862_2.png) [@jessejlt](https://discuss.elastic.co/u/jessejlt)\
**Post date:** [August 19, 2011, 9:48pm UTC](https://discuss.elastic.co/t/synonym-configuration/5202/2 "2011-08-19T21:48:47Z")

</div>

After doing some searches in this group I see that most folks use  
gists for this sort of thing, so I've created a gist:

> <https://gist.github.com/jessejlt/1158093>
>
> There are more than three files. show original

On Aug 19, 12:03 pm, jessejlt [jesse...@gmail.com](mailto:jesse...@gmail.com) wrote:

> Greetings!
> 
> I'm new to Elasticsearch and could use some quick validation of my  
> configuration.
> 
> I installed ES via brew on Lion, so ES is installed at:  
> /usr/local/Cellar/elasticsearch/0.17.1
> 
> My config file lives at:  
> /usr/local/Cellar/elasticsearch/0.17.1/config/elasticsearch.yml
> 
> And I'm launching ES manually via:  
> elasticsearch -f -D es.config=/usr/local/Cellar/elasticsearch/0.17.1/  
> config/elasticsearch.yml
> 
> Now in my config file (elasticsearch.yml), I have the following index  
> definition:
> 
> index :  
> analysis :  
> analyzer :  
> standard :  
> type : standard
> 
> ```
> tokenizer :
> myTokenizer1 :
> type : standard
> 
> filter :
> myTokenFilter1 :
> type : synonym
> synonyms_path : synonym.txt
> 
> ```
> 
> And peer to elasticsearch.yml I have created a file named synonym.txt.  
> A sample of the data in synonym.txt is:
> 
> field type, scan type, field dominance
> 
> upper field first, uff
> 
> After reading the documentation at:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/s)...  
> It seems to suggest that that:  
> field type == scan type == field dominance  
> and  
> upper field first == off
> 
> as in, they're all considered the same thing.
> 
> So to test this, I added a new document:
> 
> { "scan type" : "upper field first" }
> 
> and then searched for it using:
> 
> curl -XGEThttp://localhost:9200/test/records/\_search?q=uff
> 
> But I received no hits, but I would have expected that uff would have  
> translated to "upper field first", which should have received a hit.
> 
> So I must be doing something wrong, and this is where I need your  
> help.
> 
> Much thanks!  
> -jesse

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 20, 2011, 10:17am UTC](https://discuss.elastic.co/t/synonym-configuration/5202/3 "2011-08-20T10:17:34Z")

</div>

Hi Jesse

You had a few issues:

1. You weren't specifying the analyzer correctly - it should  
be a custom analyzer, which includes in its definition your  
synonyms token filter

2. You weren't applying that analyzer to any field

3. You were searching on the \_all field which has its own  
analyzer (standard, unless you change that) so even  
if your field is analyzed with synonyms, the \_all field  
wouldn't be.

I've gisted a demo so that you can see how to do this correctly:

> <https://gist.github.com/clintongormley/4193a7d63af534d3b0ef>

clint

---

<div class="post-metadata">

**Author:** ![jessejlt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessejlt/32/2862_2.png) [@jessejlt](https://discuss.elastic.co/u/jessejlt)\
**Post date:** [August 22, 2011, 7:19pm UTC](https://discuss.elastic.co/t/synonym-configuration/5202/4 "2011-08-22T19:19:03Z")

</div>

Hey thanks, Clinton!

Does this mean that the \_all field cannot have the synonym analyzer  
attached to it?

On Aug 20, 3:17 am, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> Hi Jesse
> 
> You had a few issues:
> 
> 1. You weren't specifying the analyzer correctly - it should  
> be a custom analyzer, which includes in its definition your  
> synonyms token filter
> 
> 2. You weren't applying that analyzer to any field
> 
> 3. You were searching on the \_all field which has its own  
> analyzer (standard, unless you change that) so even  
> if your field is analyzed with synonyms, the \_all field  
> wouldn't be.
> 
> I've gisted a demo so that you can see how to do this correctly:
> 
> [gist:4193a7d63af534d3b0ef · GitHub](https://gist.github.com/4193a7d63af534d3b0ef)
> 
> clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 22, 2011, 7:27pm UTC](https://discuss.elastic.co/t/synonym-configuration/5202/5 "2011-08-22T19:27:45Z")

</div>

Hi Jesse

> Does this mean that the \_all field cannot have the synonym analyzer  
> attached to it?

The \_all field uses the standard analyzer by default, but there is no  
reason that you can't change it to use whatever analyzer you like.

However, it will be applied to all terms included in the \_all field,  
which probably isn't what you want.

clint

---

<div class="post-metadata">

**Author:** ![jessejlt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jessejlt/32/2862_2.png) [@jessejlt](https://discuss.elastic.co/u/jessejlt)\
**Post date:** [August 22, 2011, 10:01pm UTC](https://discuss.elastic.co/t/synonym-configuration/5202/6 "2011-08-22T22:01:54Z")

</div>

Thanks again!

So synonym filters are capable of identifying synonyms for a field's  
value, do you know if it's possible to declare synonyms at the field  
level? I can do this server-side before touching ES, but before doing  
so I figure it's worth seeing if this functionality is already in ES.

So an example of a record:

{  
"field-type" : "Upper Field First"  
}

Where "field-type" is a synonym for "field-order" and "scan-type".

On Aug 22, 12:27 pm, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> Hi Jesse
> 
> > Does this mean that the \_all field cannot have the synonym analyzer  
> > attached to it?
> 
> The \_all field uses the standard analyzer by default, but there is no  
> reason that you can't change it to use whatever analyzer you like.
> 
> However, it will be applied to all terms included in the \_all field,  
> which probably isn't what you want.
> 
> clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 23, 2011, 8:28am UTC](https://discuss.elastic.co/t/synonym-configuration/5202/7 "2011-08-23T08:28:09Z")

</div>

Hiya

> So synonym filters are capable of identifying synonyms for a field's  
> value, do you know if it's possible to declare synonyms at the field  
> level? I can do this server-side before touching ES, but before doing  
> so I figure it's worth seeing if this functionality is already in ES.
> 
> So an example of a record:
> 
> {  
> "field-type" : "Upper Field First"  
> }
> 
> Where "field-type" is a synonym for "field-order" and "scan-type".

I don't quite follow what it is you are trying to achieve here.

What ES does have is "multi-fields"

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

ie you provide the field 'field-type' and in ES, that field actually  
consists of several "sub-fields", eg 'field-type.analyzed',  
'field-type.not\_analyzed', etc

If your search on 'field-type', you would actually be searching on  
'field-type.field-type'.

Also, you can set an index\_name on any field (including those  
sub-fields) which would allow you to refer to eg 'field-type.foo' as  
field 'foo'

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

clint

---

<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:** [July 6, 2017, 3:56am UTC](https://discuss.elastic.co/t/synonym-configuration/5202/8 "2017-07-06T03:56:17Z")

</div>


