Elasticsearch - location of fragments in a document -
i executing phrase query 1 below. returns me highlighted fragments ordered relevance. naturally, want user click on fragment , i'd scroll document corresponding location. however, don't see way in elasticsearch find out fragments in original document. ideas?
get documents/doc/_search { "query": { "match_phrase": { "text": { "query": "hello world", "slop": 10 } } }, "highlight" : { "order" : "score", "fields" : { "text" : {"fragment_size" : 100, "number_of_fragments" : 10} } } }
in meantime couldn't find proper solution , ended following hack (works us): before indexing annotate each word in text "[index]", "some text index" becomes "some[00] text[01] to[02] index[03]". use char filter shown below. when highlights returned parse out word positions highlight text.
"settings": { "analysis": { "char_filter": { "remove_annotation": { "type": "pattern_replace", "pattern": "\\[[0-9]+\\]", "replacement": "" } }, "analyzer": { "annotated_english_language_analyzer": { "type": "custom", "char_filter": [ "remove_annotation" ], ...
note, annotation indexes should padded log10(text_length)+1
digits, width of found highlights (after annotations removal) not depend on (beginning vs. end of text) found.
Comments
Post a Comment