Hello,
I'm working on a search engine with Elasticsearch, I have keywords and excluded keywords.
I would like to use quotes, AND and OR in my two inputs for advanced search.
Here's what I'm trying:
Keywords:
"foo bar" AND lorem OR ipsum
{
"body": {
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"multi_match": {
"query": "foo bar",
"type": "phrase",
"fields": [
"content",
"title"
]
}
},
{
"multi_match": {
"query": "lorem",
"fields": [
"content",
"title"
]
}
}
]
}
},
{
"bool": {
"must": [
{
"multi_match": {
"query": "ipsum",
"fields": [
"content",
"title"
]
}
}
]
}
}
]
}
}
}
}
Results:
"lorem foo bar" => true
"foo bar" => false
"ipsum foo bar" => true
It works but is it the right way?
For the excluded keywords, I don't know how to add into this with the same system.
Example of what I'm expecting :
Excluded keywords:
"test AND test2 OR test3"
"lorem foo bar" => true
"lorem foo bar test" => true
"lorem foo bar test3" => false
"test lorem foo bar test2" => false