1-01-12. Highlighting Our Searches
Many applications like to highlight snippets of text from each search result so the user can see whythe document matched the query. Retrieving highlighted fragments is easy in Elasticsearch.
많은 응용프로그램은 왜 document가 query에 일치하는지를, 사용자가 알 수 있도록, 각 검색 결과에 하이라이트(highlight) 표시를 해주기를 원한다. 하이라이트 표시는 Elasticsearch에서 아주 쉽다.
Let’s rerun our previous query, but add a new highlight
parameter:
조금 전의 query에 highlight
매개변수를 추가해 다시 실행해 보자.
GET /megacorp/employee/_search { "query" : { "match_phrase" : { "about" : "rock climbing" } }, "highlight": { "fields" : { "about" : {} } } }
When we run this query, the same hit is returned as before, but now we get a new section in the response called highlight
. This contains a snippet of text from the about
field with the matching words wrapped in <em></em>
HTML tags:
이 query를 실행하면, 조금 전과 동일한 hit를 볼 수 있다. 그런데 응답에서 highlight
라 불리는 새로운 부분을 볼 수 있다. 이 부분은 about
field에서 일치한 단어를 <em></em>
이라는 HTML tag로 감싸고 있는 부분을 포함하고 있다.
{ ... "hits": { "total": 1, "max_score": 0.23013961, "hits": [ { ... "_score": 0.23013961, "_source": { "first_name": "John", "last_name": "Smith", "age": 25, "about": "I love to go rock climbing", "interests": [ "sports", "music" ] }, "highlight": { "about": [ "I love to go <em>rock</em> <em>climbing</em>"] } } ] } }
You can read more about the highlighting of search snippets in the highlighting reference documentation.
highlighting reference documentation에서, 검색 정보의 하이라이트에 대해 더 많이 읽을 수 있다.