Hello,
How can I query documents where all fields should at least contain one term and all terms should be present ?
Suppose I have this index
PUT /test_query
{
"mappings": {
"properties": {
"firstname": {
"type": "text"
},
"lastname": {
"type": "text"
}
}
}
}
And these documents :
POST /test_query/_doc
{
"firstname": "Will Smith",
"lastname": "Will Smith"
}
POST /test_query/_doc
{
"firstname": "Will",
"lastname": "Smith"
}
I want to query documents where all fields (firstname, lastname) should at least contain one of these terms :
Will, Smith
I ran this query :
GET /test_query/_search
{
"query": {
"multi_match" : {
"query": "WILL SMITH",
"fields": [ "firstname", "lastname" ]
}
}
}
And it returns all the documents which is normal but if I run this query :
GET /test_query/_search
{
"query": {
"multi_match" : {
"query": "WILL SMITH TEST",
"fields": [ "firstname", "lastname" ]
}
}
}
It should give me an empty result instead of all documents because there is no TEST in all fields (firstname, lastname)