ES 经过在查询的时候能够在查询以后的字段数据加上html 标签字段,使文档在在web 界面上显示的时候是由颜色或者字体格式的 GET /product/_search { "size": 200, "query": { "match_phrase": { "name": "上海" } }, "highlight": { "fields": { "name": { } } } }
被highlight修饰的字段,在搜索以后是这样的, 这个部分包含了 name 属性匹配的文本片断,并以 HTML 标签 封装html
"_source": { "attribute": 13, "averageScore": 0, "bussinessProductId": "2-1641", "dayNum": 1, "departureCitys": [ "北京" ], "name": "上海1天自由行", "passbyCities": [ "上海" ], "picture": "img/M00/00/05/CiAAxlnA6BKAPzgOAAPzETc6-UU510.jpg", "productId": 1641, "productSource": 2, "productThemes": [], "themes": [], "weight": 1021 }, "highlight": { "name": [ "<em>上</em><em>海</em>1天自由行" ] } }