# Where should I add Analyzer?

**URL:** <https://discuss.elastic.co/t/where-should-i-add-analyzer/48291>\
**Category:** Elasticsearch\
**Created:** [April 25, 2016, 9:31am UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291 "2016-04-25T09:31:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![loez1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loez1/32/9274_2.png) [@loez1](https://discuss.elastic.co/u/loez1)\
**Post date:** [April 25, 2016, 9:31am UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291/1 "2016-04-25T09:31:04Z")

</div>

Hi,

I'm a beginner and I want to use some analyzer in my code to add synonym and to eliminate stopwords but I don't know where I must add it exactly ! (after first query ? or after second query ? ...)

my code look like that :

```
processArrFn['basket'] = (nomCallback) =>

    client.search
      index: 'gosport'
      type: 'objbasket'
      size: @_SEARCH_SIZE
      body: 
        query:
          function_score:
            query:
              query_string:
                fields: ["NAME^5", "TYPE^1", "DEFINITION^3"]
                query: queryTxt
            boost_mode: "multiply"
    .then (res) => nomCallback(null, res)

```

Thank you !

---

<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 25, 2016, 10:18am UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291/2 "2016-04-25T10:18:38Z")

</div>

Hi,

Analyzers are typically already used for the first time when you are indexing your document, e.g. for stopword removal. So adding them only in your query doesn't work. You need to specify them in your field mappings that you can customize. The whole process and how mappings and analyzers are related is described in its own chapter in the [ES Definitive Guide](https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-analysis.html).

---

<div class="post-metadata">

**Author:** ![NgocPham](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ngocpham/32/6242_2.png) [@NgocPham](https://discuss.elastic.co/u/NgocPham)\
**Post date:** [April 25, 2016, 11:03am UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291/3 "2016-04-25T11:03:03Z")

</div>

in what i know ( i know ) have 2 way analyzer.  
type 1 : analyzer when you index data to elasticsearch  
type 2 : analyzer when you search (analyzer keyword)

Can you explain what you want search in 2 type ?. i cant understand what your code action 🙂 Sr  
~~

i think you want search index called NAME  
INDEX called TYPE  
AND search word is : DEFINITION  
It true ?

---

<div class="post-metadata">

**Author:** ![loez1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loez1/32/9274_2.png) [@loez1](https://discuss.elastic.co/u/loez1)\
**Post date:** [April 25, 2016, 11:51am UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291/4 "2016-04-25T11:51:18Z")

</div>

Thank you for your answer ! I wanna know plz what do you mean by "the first time when you are indexing your document" ! can you show me plz an exemple of indexing document ?

---

<div class="post-metadata">

**Author:** ![loez1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loez1/32/9274_2.png) [@loez1](https://discuss.elastic.co/u/loez1)\
**Post date:** [April 25, 2016, 11:55am UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291/5 "2016-04-25T11:55:55Z")

</div>

I'm grateful for your answer ^ Tahnk you !

```
fields: ["NAME^5", "TYPE^1", "DEFINITION^3"]

```

By this line I attribute a weight to each field

And my index's name is gosport (as you can see in this line )

```
index: 'gosport'
```

---

<div class="post-metadata">

**Author:** ![NgocPham](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ngocpham/32/6242_2.png) [@NgocPham](https://discuss.elastic.co/u/NgocPham)\
**Post date:** [April 26, 2016, 3:29am UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291/6 "2016-04-26T03:29:17Z")

</div>

Oh 🙂 Ok now i know your idea.  
You want search : "queryTxt" , add synonym , use stopword in "queryTxt" ?

In my opinion, you can create one analyzer and stopword after create index "gosport". Before you index anydata to "gosport"

analyzer can auto add some synonym when you search  
use synonym  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/using-synonyms.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/using-synonyms.html)

create stop word  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/using-stopwords.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/using-stopwords.html)

---

<div class="post-metadata">

**Author:** ![loez1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loez1/32/9274_2.png) [@loez1](https://discuss.elastic.co/u/loez1)\
**Post date:** [April 26, 2016, 2:52pm UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291/7 "2016-04-26T14:52:12Z")

</div>

Yes exactly that's what I'm trying to do but it dosen't work ! I think I have some problems with syntaxe !!!! I'm gonna try again

---

<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 5, 2017, 10:56pm UTC](https://discuss.elastic.co/t/where-should-i-add-analyzer/48291/8 "2017-07-05T22:56:15Z")

</div>


