Reputation: 106
I would like to do an Elasticsearch query wherein i want to do an OR filter
imagine i have this kind of documents
[ {name : "John Doe"}, {name :"Jane Doe"}, {name:"Steve Doe"} ]
A query that does the same thing with this SQL Query
SELECT * from table WHERE name LIKE 'Ja%' OR name LIKE 'Jo%'
Right now i'm using elasticsearch's match_phrase_prefix for the LIKE but i'm quite stuck with the OR.
Thanks
Upvotes: 1
Views: 842
Reputation: 6357
You can use bool should
query for implementing the OR
operation. You can actually make use of prefix
query instead of match_phrase_prefix
for what you've described. Anyways, if you still find use case for a match_phrase_prefix
query just replace the prefix
query in the request below with match_phrase_prefix
query.
{
"query": {
"bool": {
"should": [
{
"prefix": {
"name": {
"value": "ja"
}
}
},
{
"prefix": {
"name": {
"value": "jo"
}
}
}
]
}
}
}
Upvotes: 2