title: How to match exact value in elasticsearch?
body: <p>I have indexed the meta-data of three files and they are of "text/plain" mime-Types.</p>
  
  <p>But when I am trying to match other <code>mime-types</code> with "text/plain", following are getting matched!</p>
  
  <p>Here is the list of <code>mime-types</code> that are matching with "text/plain", with <code>hits</code> &amp; <code>score</code>:</p>
  
  <pre><code>***********************************
  1. Mime-Type text/vnd.motorola.reflex
  2. Total Hits 3
  3. Max Score 0.07154637
  ***********************************
  1. Mime-Type text/vnd.ms-mediapackage
  2. Total Hits 3
  3. Max Score 0.034633614
  ***********************************
  1. Mime-Type text/vnd.net2phone.commcenter.command
  2. Total Hits 3
  3. Max Score 0.07154637
  ***********************************
  1. Mime-Type text/plain
  2. Total Hits 3
  3. Max Score 0.629606
  ***********************************
  </code></pre>
  
  <p><strong>I want that mime-type should exact match</strong> and should consider only last one. If you notice it's giving Max-score greater then all above. </p>
  
  <p>Search Code:</p>
  
  <p>query = "text/plain";
  filter = "mimeType"</p>
  
  <pre><code>public long getHitsCount(String query, String filter, Project project) {
          try {
              /*TermQueryBuilder QueryBuilder =  new TermQueryBuilder(filter, smartEscapeQuery(query));*/
             /* QueryStringQueryBuilder QueryBuilder = new QueryStringQueryBuilder(smartEscapeQuery(query)).field(filter);*/
              MatchQueryBuilder QueryBuilder = QueryBuilders.matchQuery(filter, smartEscapeQuery(query));
              QueryBuilder qb = QueryBuilders
                      .boolQuery()
                      .must(QueryBuilder);
  
              SearchRequestBuilder requestBuilder;
                  requestBuilder = client.prepareSearch()
                          .setIndices(getDomainIndexId(project))
                          .setTypes(getProjectTypeId(project))
                          .setSearchType(SEARCH_TYPE)
                          .setQuery(qb);
  
  
              SearchResponse response = requestBuilder.execute().actionGet(ES_TIMEOUT_MS);
              SearchHits hits = response.getHits();
              if (hits.getTotalHits() &gt; 0) {
                  return hits.getTotalHits();
              }else{
                  return 0l;
              }
          } catch (IndexMissingException ex) {
  
          }
         return 0;
      } 
  
  /**
       * Escape the string from bad chars for the search
       *
       * @param str the String that should be escaped
       * @return an escaped String
       */
      @SuppressWarnings({"ConstantConditions"})
      private static String smartEscapeQuery(String str) {
          if (StringUtils.isBlank(str)) {
              return "";
          }
  
          StringBuilder sb = new StringBuilder();
          for (int i = 0; i &lt; str.length(); i++) {
              char c = str.charAt(i);
              if (c == '\\' || c == '+' || c == '-' || c == '!' || c ==
                      '(' || c == ')' || c == ':'
                      || c == '^' || c == '[' || c == ']' || c == '\"'
                      || c == '{' || c == '}' || c == '~' || c == '/'
                      || c == '?' || c == '|' || c == '&amp;' || c == ';'
                      || (!Character.isSpaceChar(c) &amp;&amp;
                      Character.isWhitespace(c))) {
                  sb.append('\\');
              }
              sb.append(c);
          }
          return sb.toString();
      }
  </code></pre>
  
  <p>Match Query: </p>
  
  <pre><code>    {
        "bool" : {
          "must" : {
            "match" : {
              "mimeType" : {
                "query" : "text\\/plain",
                "type" : "boolean"
              }
            }
          }
        }
      }
  Result: 3 Hits
  </code></pre>
  
  <p>Term Query:</p>
  
  <pre><code>{
    "bool" : {
      "must" : {
        "term" : {
          "mimeType" : "text\\/plain"
        }
      }
    }
  }
  
  Result: 0 Hits
  </code></pre>
  
  <p>I have tried with both <code>TermQuery</code> &amp; <code>MatchQuery</code> but it did not work. I am using <code>AutoDetectParser</code> while indexing.   </p>
  
  <p><strong>How can I match the exact value in elasticsearch so that in above example it should only match with the "text/plain" NOT with matching ones?</strong> </p>