Reputation: 398
The problem is to do a phrase search for two adjacent words in any order with words analysis.
E.g. in Sphinx extended syntax terms the query string can be written as WordToBeAnalyzed1 NEAR/1 WordToBeAnalyzed2
. Then both words are being analyzed and the search engine finds either "Word1 Word2" or "Word2 Word1", where both words can be in any form (e.g. "fox jumps", "jumping fox", "foxes jumped", and so on).
Reading the ES docs I could not express the same search in the ES query DSL.
When querying with match_phrase
and slop
I can query a phrase "WordToBeAnalyzed1 WordToBeAnalyzed2"
with a "slop": 2
param to match same words in reverse order. But it will also match such undesirable variants as "Word1 SlopWord1 Word2" and "Word1 SlopWord1 SlopWord2 Word2".
I also tried to use span_near
query with the in_order
param, but
span queries are term-level queries, so they have no analysis phase
I would be glad if anyone can point me to a way to solve this problem.
Upvotes: 3
Views: 1942
Reputation: 11
This will work.
{
"query":{
"bool":{
"must":[
{
"query_string":{
"query":"*hello* *there*",
"fields":[
"subject"
],
"default_operator":"and",
}
}]
}
}
}
Upvotes: 1