Highlighting is not working on my search results


(anusha) #1

Hi,

Am using the following query for to highlight my search data..

GET /ymme/ymme_type/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"_all":
{
"query": "2012 aston",
"operator": "and"
}
}
}
]
}
},
"highlight": {
"fields": {
"Year":{}
}
}
}

The o/p am getting for this in sense plugin as:

"_score": 8.155715,
"_source": {
"MakeCode": "101",
"Year": "2012",
"Model": "DBS",
"EngineCode": "6",
"YearCode": "2012",
"ShortYear": "12",
"Engine": "12-5935 6.0L",
"ModelCode": "6",
"Make": "ASTON MARTIN"
},
"highlight": {
"Year": [
"2012"
]
}
}
....................
..............
..........
And the relevant Java API am using:

BoolQueryBuilder builder= boolQuery();
		builder.must(QueryBuilders.matchQuery("_all", term).operator(MatchQueryBuilder.Operator.AND).fuzziness(4).prefixLength(4));
		
		SearchRequestBuilder srb = client.prepareSearch().setTimeout(timeValue).setQuery(builder).addHighlightedField("Year");

		setParameters(index, type, size, srb);

		SearchResponse response = srb.execute().actionGet();

		hits=response.getHits();

But in UI my response data is not highlighted, may I know the reason.. Do I need to write the code in any other way to highlight my data which is displaying in UI????????


(anusha) #2

And when am using the following query.......

GET /ymme/ymme_type/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"_all":
{
"query": "2012 aston martin",
"operator": "and"
}
}
}
]
}
},
"highlight": {
"fields": {
"Year":{},
"Make":{}

      }
  }
  }

Am getting response with only one highlight field "Year",

{
"_index": "ymme",
"_type": "ymme_type",
"_id": "AU4Fz0hhSl0tkDoQ8lSM",
"_score": 9.607379,
"_source": {
"MakeCode": "101",
"Year": "2012",
"Model": "RAPIDE",
"EngineCode": "6",
"YearCode": "2012",
"ShortYear": "12",
"Engine": "12-5935 6.0L",
"ModelCode": "14",
"Make": "ASTON MARTIN"
},
"highlight": {
"Year": [
"2012"
]
}
},
{
"_index": "ymme",
"_type": "ymme_type",
"id": "AU4Fz2M-Sl0tkDoQ8oq",
"_score": 9.607379,
"_source": {
"MakeCode": "101",
"Year": "2012",
"Model": "VIRAGE",
"EngineCode": "6",
"YearCode": "2012",
"ShortYear": "12",
"Engine": "12-5935 6.0L",
"ModelCode": "12",
"Make": "ASTON MARTIN"
},
"highlight": {
"Year": [
"2012"
]
}
}

May I know how can I get all the highlight fields???


(system) #3