Highlighted Text is not working

Hi All,
i am applying highlightedText on elasticsearch indexe through the java code, the highlighted text feature is working not working below is the mapping-

"dcl_raac_pcdb": {
"mappings": {
"dcl_raac_pcdbv1": {
"properties": {
"Application": {
"type": "string",
"index": "not_analyzed"
},
"Attributes": {
"type": "nested",
"properties": {
"key": {
"type": "string",
"index": "not_analyzed"
},
"value": {
"type": "string"
}
}
},
"BrandDesc": {
"type": "string",
"index": "not_analyzed",
"fields": {
"raw": {
"type": "string"
}
}
},
"BrandId": {
"type": "string",
"index": "not_analyzed"
},
"Cat": {
"type": "string",
"index": "not_analyzed",
"fields": {
"raw": {
"type": "string"
}
}
},
"CatDesc": {
"type": "string",
"index": "not_analyzed",
"fields": {
"raw": {
"type": "string"
}
}
},
"CatId": {
"type": "string",
"index": "not_analyzed"
},
"CountryOfOrigin": {
"type": "string",
"index": "not_analyzed"
},
"Desc": {
"type": "string",
"index": "not_analyzed",
"fields": {
"raw": {
"type": "string"
}
}
},
"LineCode": {
"type": "string",
"index": "not_analyzed"
},
"MarketingDesc": {
"type": "string",
"index": "not_analyzed",
"fields": {
"raw": {
"type": "string"
}
}
},

           "SubCatId": {
              "type": "string",
              "index": "not_analyzed",
              "fields": {
                 "raw": {
                    "type": "string"
                 }
              }
           },
           "SubCatImageUrl": {
              "type": "string"
           },
           "Term": {
              "type": "string",
              "index": "not_analyzed",
              "fields": {
                 "raw": {
                    "type": "string"
                 }
              }
           },

           "highlight": {
              "properties": {
                 "fields": {
                    "properties": {
                       "BrandId": {
                          "type": "object"
                       }
                    }
                 }
              }
           },
           "query": {
              "properties": {
                 "bool": {
                    "properties": {
                       "must": {
                          "properties": {
                             "query_string": {
                                "properties": {
                                   "query": {
                                      "type": "string"
                                   }
                                }
                             }
                          }

}

Java code

BoolQueryBuilder builder = boolQuery();
builder.must(QueryBuilders.queryStringQuery(term));
SearchRequestBuilder srb =ClientInstance.getInstance().getClient().prepareSearch().setIndices("dcl_raac_pcdb").setTypes("dcl_raac_pcdbv1").setQuery(builder).addHighlightedField("BrandId");
SearchResponse response = srb.execute().actionGet();
long total = response.getHits().getTotalHits();

{ Removed some properties (Fields) from the mapping due to space limitation)
I am using highlighted text field as "BrandId" or "LineCode" (tried with different fields), but am not getting Highlighted content in the response, its not working here (using elasticsearch 1.5.2)
Can anyone please guide me,
Thanks in advance.

Hi @apratapi,

first of all, your mapping looks odd. You have "raw" subfields but you index the top level field as "not_analyzed". This is backwards.

Below is a complete example that works in Sense (and with a correct mapping):

DELETE /logs

PUT /logs
{
   "mappings": {
      "incoming": {
         "properties": {
            "timestamp": {
               "type": "date",
               "format": "epoch_millis"
            },
            "message": {
               "type": "string",
               "fields": {
                   "raw": {
                       "type": "string",
                       "index": "not_analyzed"
                   }
               }
            }
         }
      }
   }
}

POST /logs/incoming
{
    "timestamp": 1469625086000,
    "message": "Let's see whether we can get this highlighted."
}

GET /logs/incoming/_search
{
   "query": {
       "match": {
          "message": "highlighted"
       }
      
   },
   "highlight": {
      "fields": {
         "message": {}
      }
   }
}

The response of the query is:

{
   "took": 8,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.25811607,
      "hits": [
         {
            "_index": "logs",
            "_type": "incoming",
            "_id": "AVYsfkWqSgxvwr39TmHP",
            "_score": 0.25811607,
            "_source": {
               "timestamp": 1469625086000,
               "message": "Let's see whether we can get this highlighted."
            },
            "highlight": {
               "message": [
                  "Let's see whether we can get this <em>highlighted</em>."
               ]
            }
         }
      ]
   }
}

I hope this gets you started.

Daniel