-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Highlighting array field - Also return non-matching entries #7416
Comments
I don't believe it has an option to do that right now. I don't think it'd be too hard to build though. |
What would be better: To respect the setting of no_match_size for every single array entry or introduce a new setting parameter? |
Hi, did this ever get fixed? I'm relying on this functionality returning non-matched entries for my application. |
Hi Team, |
+1 here |
+1 |
1 similar comment
+1 |
Would also like this. Or some other way to find out what fields in the original document actually got highlighted when having nested documents with arrays. |
+1 |
any fixes available for this ??? My work would hugely depend on this. |
+1 |
Waiting for any fixes... |
+1 |
1 similar comment
+1 |
cc @elastic/es-search-aggs |
+1 |
1 similar comment
+1 |
+1 I also faced with the need to get non-matching entries because arrays are the simplest way to implement relations. I know sub items order so I don't need to use nested objects. For example, I can just store usernames like an arrays:
instead of using objects with ID:
|
We index multi-valued fields as if it was a single value, each entry is appended and separated with a custom separator. This means that the offsets that we index are relative to the concatenated text. |
Any update on the newest version? |
Any update on the newest version? |
This would be really useful. Would make things a lot easier for a project Im working on. Any update as to whether we are likely to see it implemented any time soon? |
Waiting for any fixes |
+1 |
Any news on this one? It's quite old and I suppose a lot of people would be happy to see it implemented. |
+1 I really don't see how I can use Highlight feature, until this is resolved. I thought I can manually merge source and highlight, but if you have simple array of strings - it's not possible to merge.
As a work around I could matched it by index, if highlights returns "null" for non-matched records like Is there another workaround at this point? |
+1 |
If you have a nested object, there is a way to find out what element was highlighted if you use inner_hits in nested query. For example if you have document like this:
You can make a query like this:
Now when you run a search you will find "inner_hits" field in the document, somewhere after "_source". There will be something like this, you can find index of highlighted element in _nested.offset field.
It is not perfect, but I hope it will help someone. |
+1 |
My workaroundUse a regex to remove the pre/post tags and compare against the data in ExampleSource: { export function removeHighlightTags(
text: string,
preTag = '<em>',
postTag = '</em>',
) {
return text
.replace(new RegExp(preTag, 'g'), '')
.replace(new RegExp(postTag, 'g'), '')
.trim()
}
// fetch data
const {hits} = await es_client.search(...)
// let's handle a single hit
const hit = hits.hits[0]
const highlights = hit.highlight.['path.to.arrayField.arrayItem']
const result = hit.arrayField.map((item) => {
return highlights.find((h) => removeHighlightTags(h) === item.trim()) || item
})
console.log(result) // --> [<em>foo</em>, <em>foo</em>bar, bar] |
I've created a similar issue where highlighted array items could be indicated by path as an alternative to the original proposal of including non-highlighted items within |
I have an array field with the entries
[foo, foobar, bar]
and search forfoo
. The highlighting then returns for that fieldI would like it to return
I did try to set
no_match_size
as described on http:https://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html but that didn't work. Is there any way to make elasticsearch behave the way I want?The text was updated successfully, but these errors were encountered: