I have SQL table XYZ with below data:
P------ S----- R--
SAMSUNG GALAXY 1
SAMSUNG GALAXY 2
SAMSUNG GALAXY 10
SAMSUNG GALAXY 9
APPLE IOS 12
APPLE IOS 9
I have below SQL query:
select * from XYZ where P='SAMSUNG' AND S='GALAXY' AND R IN (1,2)
It returns all the records that match column P with value "SAMSUNG" AND column S with "GALAXY" AND column R with values 1 or 2.
OUTPUT:
SAMSUNG GALAXY 1
SAMSUNG GALAXY 2
Now I am trying to prepare an Elastic Search query for the above behavior but the result is not as expected:
{'query':
{'bool':
{'must': [{'match': {'P' : 'SAMSUNG'}}],
'must': [{'match': {'S' : 'GALAXY'}}],
'must': [{'match': {'R' : '1'}}, {'match': {'R' : '2'}}]
}
}
}
The above query returns empty output. But If I specify only 'P' it works:
{'query':
{'bool':
{'must': [{'match': {'P' : 'APPLE'}}]}
}
}
This returns below output
APPLE IOS 12
APPLE IOS 9
Not sure what is wrong with my first query. Could any one help how to use "must", "should" with elastic search queries?