# Use Analyzer on search text

**URL:** <https://discuss.elastic.co/t/use-analyzer-on-search-text/233480>\
**Category:** Elasticsearch\
**Created:** [May 20, 2020, 7:47am UTC](https://discuss.elastic.co/t/use-analyzer-on-search-text/233480 "2020-05-20T07:47:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ridma\_Gamage](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ridma_gamage/32/67684_2.png) [@Ridma\_Gamage](https://discuss.elastic.co/u/Ridma_Gamage)\
**Post date:** [May 20, 2020, 7:47am UTC](https://discuss.elastic.co/t/use-analyzer-on-search-text/233480/1 "2020-05-20T07:47:56Z")

</div>

I'm relatively new for elastic search. I have used edge\_ngram analyzer at the index time and It created ngrams like this. (elastic -\> elas,elast,elasti, elastic)

```auto
    {
      "analysis":{
        "analyzer":{
          "publicIdAutoComplete":{
            "tokenizer":"publicIdAutoComplete"
          },
          "orderIdAutoComplete":{
            "tokenizer":"orderIdAutoComplete"
          }
        },
     "tokenizer":{
          "publicIdAutoComplete":{
            "type":"edge_ngram",
            "min_gram":4,
            "max_gram":15,
            "token_chars":[
              "letter",
              "digit"
            ]
          },
          "orderIdAutoComplete":{
            "type":"edge_ngram",
            "min_gram":4,
            "max_gram":40,
            "token_chars":[]
          }
    }
    }
    }

```

Index has created ngrams accordingly. now I want to implement a search functionality top of this index. search should work like this. if I search `elast` it should return only `elast`. not the both `elas` & `elast`. According to my understand I have to use analyzer at the search also. if I'm correct how do I use analyzer at the search query? Do I need to use same analyzer which I used for indexing or do I need to create new analyzer? Here's my query.

```auto
      queryBuilder.filter(
              QueryBuilders.multiMatchQuery(queryMap.get("orderId"), "id", "publicId")
                  .type(Type.MOST_FIELDS));

```

Thank you

---

<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:** [May 20, 2020, 8:10am UTC](https://discuss.elastic.co/t/use-analyzer-on-search-text/233480/2 "2020-05-20T08:10:49Z")

</div>

You need to define a `search_analyzer`. I'd recommend using the `simple` analyzer.

An example here:

```
      "autocomplete": {
        "type": "text",
        "analyzer": "autocomplete",
        "search_analyzer": "simple"
      },

```

HTH

---

<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:** [June 17, 2020, 8:10am UTC](https://discuss.elastic.co/t/use-analyzer-on-search-text/233480/3 "2020-06-17T08:10:49Z")

</div>

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