How to know which field (fields) is matched and do the custom highlighting?


(Chunlei Wu) #1

Hi,

 My JSON document to be indexed has dozens of fields:

{
"field1": "foo",
"field2": ["bar1", "bar2", "bar3"],
"field3": ["foo", "foo2"],
"field4": "adskj akfjoa asdfja foo adbja ...",
... ...
}

I can index them in ES without a problem. My query is mostly looking
for matches on any fields (e.g., just a string query of "foo").

My question is to know which fields are matched (like "field1",
"field3" and "field4" for a query of "foo")? I can pass all my fields
for highlighting, and that will return matched fields with highlighted
snippets and the rest of fields with "[]". Because I have large amount
of fields, that will make the returned query result quite big. So I am
wondering if there is other better way to do that or any way to simply
remove the unmatched fields from "highlight".

My eventual purpose is to get a custom highlighting like this (for a
query "foo"):

{
...
"highlight": {"field1": ["foo"],
"field3": ["foo, foo2"],
"field4": ["adskj akfjoa asdfja foo
adbja"],
},
...
}

Basically, for a field with an array of values (i.e., "field3"), I
need to highlight matches under the context of other values.

Thanks a lot.

Chunlei


(system) #2