I have stored some HTML pages in ElasticSearch, now I want to match an input string with all the strings present in those HTML and get the exact location of the match. So far I have written this query:
"query": {
"query_string": {
"query": queryText,
"default_field": "html"
}
}
This returns the whole document where the match is found. Is there a way to get the exact location of the match?
CodePudding user response:
You can leverage the Highlight feature, like this:
GET myindex/_search
{
"query": {
"query_string": {
"query": queryText,
"default_field": "html"
}
},
"highlight": {
"fields": {
"html": {}
}
}
}