Not able to search a phrase in elasticsearch 5.4

I am searching for a phrase in a email body. Need to get the exact data filtered like, if I search for 'Avenue New', it should return only results which has the phrase 'Avenue New' not 'Avenue Street', 'Park Avenue'etc

My mapping is like:

 {
 "exchangemailssql": {
"aliases": {},
"mappings": {
 "email": {
    "dynamic_templates": [
       {
          "_default": {
             "match": "*",
             "match_mapping_type": "string",
             "mapping": {
                "doc_values": true,
                "type": "keyword"
             }
          }
       }
    ],
    "properties": {
       "attachments": {
          "type": "text",
          "fields": {
             "keyword": {
                "type": "keyword",
                "ignore_above": 256
             }
          }
       },
       "body": {
          "type": "text",
          "analyzer": "keylower",
          "fielddata": true
       },

       "count": {
          "type": "short"
       },
       "emailId": {
          "type": "long"
       }              
    }
 }
},
 "settings": {
   "index": {
    "refresh_interval": "3s",
    "number_of_shards": "1",
    "provided_name": "exchangemailssql",
    "creation_date": "1500527793230",
    "analysis": {
       "filter": {
          "nGram": {
             "min_gram": "4",
             "side": "front",
             "type": "edge_ngram",
             "max_gram": "100"
          }
       },
       "analyzer": {
          "keylower": {
             "filter": [
                "lowercase"
             ],
             "type": "custom",
             "tokenizer": "keyword"
          },
          "email": {
             "filter": [
                "lowercase",
                "unique",
                "nGram"
             ],
             "type": "custom",
             "tokenizer": "uax_url_email"
          },
          "full": {
             "filter": [
                "lowercase",
                "snowball",
                "nGram"
             ],
             "type": "custom",
             "tokenizer": "standard"
          }
       }
    },
    "number_of_replicas": "0",
    "uuid": "2XTpHmwaQF65PNkCQCmcVQ",
    "version": {
       "created": "5040099"
     }
    }
  }
 }
}

I have given the search query like:

{
 "query": {
"match_phrase": {
 "body": "Avenue New"
}
 },
"highlight": {
"fields" : {
    "body" : {}
}
}
}

Is the problem that you aren't finding any documents with the query? Returning incorrect results? Can you describe the problem a bit more?

As an aside, you can probably change your body field from a text to keyword, given the current setup. E.g. your analyzer is a keyword tokenizer + lowercase filter. Instead, you can just use the keyword field type and enable a lowercase tokenizer. See: https://www.elastic.co/guide/en/elasticsearch/reference/current/normalizer.html

This allows you to use doc values for the field instead of fielddata.

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