highlighting - Can ElasticSearch stitch together a field to show matches from different parts of a field? -
when performing query on long field, ie. description
, field may day 200 or more characters in length.
to show relevancy in search result, can es stitch different parts of field show this?
for example:
there red car 4 doors driving down brick road ... , red balloon floating.
if query searches 'red', there way of displaying following:
there [em]red[/em] car 4 doors . . . , [em]red[/em] balloon floating.
i realize can use highlight
ing wrap matching keyword fragments in emphasis tags.
i know if es can stitch relevant field fragments around matched keyword fragments.
yes, you're on right path, that's highlighting for. let's try on example.
first, let's create index highlights
mapping type having single string field called content
. example, use fast vector highlighter, job want show.
curl -xput localhost:9200/highlights -d '{ "mappings": { "highlight": { "properties": { "content": { "type": "string", "term_vector": "with_positions_offsets" } } } } }'
then index new document content suggested:
curl -xput localhost:9200/highlights/highlight/1 -d '{ "content": "there red car 4 doors driving down brick road bla bla bla bla bla bla bla bla bla bla bla bla , red balloon floating." }'
now can query , highlight term red
this:
curl -xpost localhost:9200/highlights/highlight/_search -d '{ "_source": false, "query": { "match": { "content": "red" } }, "highlight": { "fields": { "content": { "fragment_size": 30 } } } }'
this yields following results:
{ ... "hits" : { "total" : 1, "max_score" : 0.06780553, "hits" : [ { "_index" : "highlights", "_type" : "highlight", "_id" : "1", "_score" : 0.06780553, "highlight" : { "content" : [ "there <em>red</em> car 4 doors", "bla , <em>red</em> balloon floating" ] } } ] } }
also note tags can customized , changed likings, if needed.
Comments
Post a Comment