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天自由行" ] } }