Finding which elements of an array are the ones that matched in search results


(Russell Mull) #1

I have a document which looks something like this:

{
content: [
"The first entry is ok",
"But the second entry is great!"
]
}

I can find this document when I search for 'great' under content, but I'd
like to find out that the second element of 'content' is the one that
matched. I can do this by hand, but that's clearly less than ideal.

The only way I've found so far is to abuse the highlighter like this:

"highlight" : {
"pre_tags" : [""],
"post_tags" : [""],
"fields" : {
"content" : {}
}
}

This causes only the entries that matched to show up in highlight.content
in the results. But this seems less than ideal. Is there a better way to do
it?

Thanks,
Russell


(Clinton Gormley) #2

I can find this document when I search for 'great' under content, but
I'd like to find out that the second element of 'content' is the one
that matched. I can do this by hand, but that's clearly less than
ideal.

The only way I've found so far is to abuse the highlighter like this:

This causes only the entries that matched to show up in
highlight.content in the results. But this seems less than ideal. Is
there a better way to do it?

Currently there isn't a better way to do this. There are various issues
open about this and similar features with nested docs. Definitely
should be on the roadmap

clint


(system) #3