I started recently to experiment with elasticsearch and I can not do an AND.
I have two objects like the following:
"objeto1": [{"id": 1,"tipo": [{"id": 1,"valor": 5},{"id": 2,"valor": 4},{"id": 3,"valor": 2}]}]
"objeto2": [{"id": 2,"tipo": [{"id": 1,"valor": 2},{"id": 2,"valor": 1},{"id": 3,"valor": 6}]}]
I want to filter the objects that within the "type" array have an object with "id" 3 and "value" 2. I have tried to use the MUST expression of elasticsearch to do the AND.
{
"query": {
"bool":{
"must":[
{
"term": {"tipo.id":3}
},
{
"term": {"tipo.valor":2}
}
]
}
}
}
But it returns both objects, since within object1 and object 2 there are fields with "id" 3 and "value" 2. My intention would be to return only the object1, since it is the only one that has "type" an object with "id" 3 and "value" 2.
{
"id": 3,
"valor": 2
}
How could an AND be made to filter through two fields?