Q:

multiple match must fields not working in elastic search

below query is fetching result if i give existing record that is fine , but if i change name field from 'John' to 'John1' then still record is fetching.
{
 "query" : {
            "bool" : {
              "must" : [
                 { "match" : {"employeeId" : "1234"}}, 
                 { "match" : {"name" : "John"}} 
              ]
           }
   }
}

I tried another alternative query  as well but still giving result.which query is correct in terms of performance?but both are giving results if i change name record from 'John' to 'John1'
{

 "filter": {
  "bool" : {
    "must" : {
      "term" : {
        "employeeId" : "1234"
      }
     }
    }
    },
    "query": {
      "match" : {
        "name" : {
          "query" : "John",
          "type" : "phrase"
        }
      } 
   }
}

A:

This because you are doing match, if you want do exact search you need to use filter
Notice we assuce the mapping of name column is analyzed
{
    "query" :{
        "filtered" : {
            "filter" : {
                "bool" : {
                  "must" : [
                     { "term" : {"employeeId" : "1234"}}, 
                     { "term" : {"name" : "john"}} 
                  ]
               }
          }
       }
    }
}

