Howto highlight results in a generic fashion

Hi All,

I have a requirement to highlight any searched field and update it in the returned source, this will be shown in a fielded HTML UI with the highlights shown per-field.

I see a number of posts such as: Is there any option for highlight to highlight the results in "_source"?

that tell me that there is no magic flag to just tell elastic to update the returned _source, instead I have to provide a highlight directive per https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-highlighting.html and then update the _source myself.
It seems like if I set "number_of_fragments": 0 and the fields in question are not too big, I will probably get away with this.

I also have a lot of nested information (not my choice!). The question here is how to identify the nested row in question. This information does not seem to be in the response. For example:

{
    "query": {
        "bool": {
            "should": [
                {
                    "nested": {
                        "path": "ProductDetails",
                        "ignore_unmapped": true,
                        "query": {
                            "simple_query_string": {
                                "query": "abc",
                                "fields": [
                                    "ProductDetails.DetailDescription",
                                    "ProductDetails.DetailDescription.autocomplete"
                                ]
                            }
                        }
                    }
                }
            ]
        }
    },
    "highlight": {
        "number_of_fragments": 0,
        "fields": {
            "ProductDetails.DetailDescription": {},
            "ProductDetails.DetailDescription.autocomplete": {}
        }
    }

returns:

               "highlight": {
                    "ProductDetails.DetailDescription.autocomplete": [
                        "INV/<em>ABC</em>"
                    ],
                    "ProductDetails.DetailDescription": [
                        "INV/<em>ABC</em>"
                    ]
                }

In the above I do not know which detail was matched (there may be multiple), and due to the use of autocomplete (and I do not control the text "abc - this is user-entered) I get two matches. I would assume the non-autocomplete one is better, a partial autocomplete match will not return a highlight for the full word match.

Should I be also using inner_hits{} directives to determine the matching detail row?

all thoughts appreciated, including "are you mad" but preferably "we did this already, here's how ...",
Dave :wink:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.