I recently try migrating from MySQL Full Text Search to ElasticSearch, and I'm a little bit confused with translating some queries.
I have this query.
"SELECT * FROM Books WHERE MATCH (description) AGAINST ('+Harry +Potter' IN BOOLEAN MODE)"
It means both "Harry" and "Potter" must shown in the description column, regardless the order or the position. (For the sake of example, please assume "Harry" and "Potter" can be independent from each other.)
I tried this using ElasticSearch
{
"query": {
"query_string": {
"query": "Harry Potter",
"fields": ["description"]
}
}
}
but it's still give some result that only contains "Harry" or "Potter".
I tried this one also,
{
"query": {
"bool": {
"must" : {
"term" : { "description" : "Harry Potter" }
}
}
}
}
this one returns all result contains "Harry Potter", not "Harry Bla Bla Bla Potter" and "Potter Bla Bla Bla Harry".
What is the simplest (or perhaps also fastest) ElasticSearch query that returns the same result with the MySQL query above.
UPDATE
I just found something like this
{
"query": {
"match" : {
"description" : {
"query" : "Harry Potter",
"operator" : "and"
}
}
}
}
the result seems about right. But is there other way that is more common?