Incorrect query analyzing that don't correspond to the search_analyzer setting

I'm trying to transform search query against a field replacing parentheses by underscores making them regular letters available for search. The same process is made both for index and for the query. I expect that my query (MIT) will be translated to _mit_ and only those rows will be fetched that contains this word in their index. But despite the configuration, I can't get the intended result.

Index:

{
   "settings":{
      "index":{
         "analysis":{
            "filter":{
               "autocomplete_filter":{
                  "type":"ngram",
                  "min_gram":1,
                  "max_gram":14
               }
            },
            "char_filter":{
               "parentheses_filter":{
                  "type":"mapping",
                  "mappings":[
                     "( => _",
                     ") => _"
                  ]
               }
            },
            "analyzer":{
               "autocomplete":{
                  "type":"custom",
                  "tokenizer":"standard",
                  "char_filter":[
                     "parentheses_filter"
                  ],
                  "filter":[
                     "lowercase",
                     "asciifolding",
                     "autocomplete_filter"
                  ]
               },
               "autocomplete_query":{
                  "type":"custom",
                  "tokenizer":"standard",
                  "char_filter":[
                     "parentheses_filter"
                  ],
                  "filter":[
                     "lowercase",
                     "asciifolding"
                  ]
               }
            }
         }
      }
   },
   "mappings":{
      "default":{
         "properties":{
            "name":{
               "type":"text",
               "analyzer":"autocomplete",
               "search_analyzer":"standard",
               "copy_to":"search_by_name"
            },
            "search_by_name":{
               "type":"text",
               "analyzer":"autocomplete",
               "search_analyzer":"autocomplete_query"
            }
         }
      }
   }
}

Documents:

{"name":"German Network for Mitochondrial Disorders (mitoNET)"}
{"name":"Madanapalle Institute of Technology and Science (MITS)"}
{"name":"Massachusetts Institute of Technology (MIT)"}
{"name":"Lomonosov Moscow University of Fine Chemical Technology (MITHT)"}
{"name":"Italy Ministry of Infrastructures and Transport (MIT)"}
{"name":"MITOVASC"}
{"name":"Muzaffarpur Institute of Technology (MIT Muzaffarpur)"}
{"name":"Michigan Institute of Translational Nanotechnology (MITRAN)"}
{"name":"Department of Monitoring and Instrumentation Technology (MIT), NILU"}
{"name":"Madras Institute of Technology (MIT), AU"}
{"name":"Mahakal Institute of Technology, Ujjain (MIT)"}
{"name":"MIT Energy Initiative (MITEI)"}
{"name":"Department of Molecular Immunology and Toxicology (MITO), NIO"}
{"name":"Department of Molecular Imaging and Theranostics (MIT), QST"}
{"name":"Department of Microbiology, Immunology, and Tropical Medicine (MITM), GW"}
{"name":"Charité Department of Radiology (including Pediatric Radiology)"}
{"name":"Mitsubishi Kagaku Institute of Life Sciences (MITILS)"}
{"name":"Mainz Institute for Theoretical Physics (MITP)"}

Query http://localhost:9200/institution_test/_search?q=search_by_name:_mit_ returns documents as expected:

{
   "hits":{
      "total":{
         "value":6
      },
      "hits":[
         {
            "_source":{
               "name":"Massachusetts Institute of Technology (MIT)",
            }
         },
         {
            "_source":{
               "name":"Mahakal Institute of Technology, Ujjain (MIT)",
            }
         },
         {
            "_source":{
               "name":"Madras Institute of Technology (MIT), AU",
            }
         },
         {
            "_source":{
               "name":"Italy Ministry of Infrastructures and Transport (MIT)",
            }
         },
         {
            "_source":{
               "name":"Department of Monitoring and Instrumentation Technology (MIT), NILU",
            }
         },
         {
            "_source":{
               "name":"Department of Molecular Imaging and Theranostics (MIT), QST",
            }
         }
      ]
   }
}

But this query http://localhost:9200/institution_test/_search?q=search_by_name:(mit) returns all rows despite it should return the same results as the previous one because I configured to map parentheses to underscores. And this transformation must work:

POST http://localhost:9202/institution_test/_analyze HTTP/1.1

{
    "analyzer": "autocomplete_query",
    "text": "(MIT)"
}


{
   "tokens":[
      {
         "token":"_mit_",
         "start_offset":0,
         "end_offset":5,
         "type":"<ALPHANUM>",
         "position":0
      }
   ]
}

But it looks like when I make an actual search query the search_analyzer is ignored and the autocomplete_query analyzer is not executed.

WhatI'm doing wrong?

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