Use Analyzer on search text

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)

    {
      "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.

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

Thank you

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

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