Reputation: 11160
Is it possible in elasticsearch to get all documents that contain phrase1 OR phrase2 in a single query? I know to match a phrase, one can use the following query:
"query" : {
"match_phrase" : {
"title" : "rock climbing"
}
}
But how about a case when there are multiple phrases and the goal is to retrieve documents containing either of these phrases.
Upvotes: 2
Views: 145
Reputation: 8165
You can wrap the two match_phrase
queries in the should
clause of a bool query :
{
"query" : {
"bool": {
"should": [
{
"match_phrase" : {
"title" : "phrase1"
}
},
{
"match_phrase": {
"title": "phrase2"
}
}
],
"minimum_number_should_match": 1
}
}
}
Upvotes: 3
Reputation: 432
You can perform Query String search
{
"query_string" : {
"default_field" : "content",
"query" : "this AND that OR thus"
}
}
You can specify the AND / OR clause in query or use default_operator
and just write keywords to query
parameter. If you want exact phare, just wrap the words to quotes.
Upvotes: 1