I store in Elasticsearc objects like that:
{
"userName": "Cool User",
"orders":[
{
"orderType": "type1",
"amount": 500
},
{
"orderType": "type2",
"amount": 1000
}
]
}
And all is ok while I`m searching by 'orders.orderType' or 'orders.amount' fields. But what query I have to use for getting objects, which has 'orders.amount >= 500' and 'orders.orderType=type2'?
I`ve tried to query like that:
{
"query": {
"bool": {
"must": [
{
"range": {
"orders.amount": {
"from": "499"
}
}
},
{
"query_string": {
"query": "type2",
"fields": [
"orders.orderType"
]
}
}
]
}
}
}
..but this request returns records that has 'orders.orderType=type2' OR 'orders.amount >= 500'.
Please help me to construct query, that will look for objects that has object inside orders array and it object has to have amount >= 500 AND 'orderType=type2'.