Hi
I need to support searches like green apple near yellow peach, but
can't find existing query syntax from ElaticSearch to support this directly.
So I tried to combine multiple phrase match with a boolean query to
achieve this. It doesn't work perfectly, but search results are close
enough. However, I can't find a good way to highlight the match terms
correctly as my client only wants to highlight the phrase green apple and
yellow peach where they near each other. With the query I come up, all
the individual word could be highlighted as well if I have a sentence like
green and red apple with yellow banana and pink peach, assuming somewhere
in the text would have two phrases green apple and yellow peach that
satisfy the query.
I use standard tokenizer with snowball filter for the text field, and
term_vector
with_postions_offsets is used for highlighting.
Here is my query:
query:
{bool:{must:
[{match_phrase:{headline:{text:green apple}}},
{match_phrase:{headline:{text:yellow peach}}},
{match_phrase:{headline:{text:green apple yellow
peach,slop:10}}}
]
}}
highlight:
{fields:{text:{}},
fragment_size:200,
number_of_fragments:50,
highlight_query:{match_phrase:{headline:{text:green apple
yellow peach,slop:10}}},
require_field_match:true
}
I tried span near query, but I can't find span term that support phrases,
and I believe span query only works on not-analyzed fields.
Can anyone have suggestions to handle the highlighting for such proximity
phrase searches? Thanks.
--
You received this message because you are subscribed to the Google Groups
elasticsearch group.
To unsubscribe from this group and stop receiving emails from it, send an email
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/18cdb5cb-3aed-4d87-95ec-2d146306117b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.