I have a customer info with orders in Elastic Search in the following format
{
"_index": “customer_domain_r4",
"_type": “CustomerData”,
"_id": "6fff6ce8-e792-4047-b636-a1dda0aa2b72",
"_version": 173,
"_score": 3.551258,
"_source": {
“first”: "John",
“last”: "Doe",
“dateOfBirth”: null,
"primaryPhone": "6154525131",
“customerOrders”: [
{
“orders”: [
{
“orderNumber": 1,
“orderName": “Grocery”,
"recordVersion": 1,
"createdDateTimeGmt": "May 09, 2018 03:19:11 PM",
"deletedDateTimeGmt": "May 12, 2018 08:28:42 PM",
"createdSessionTokenId": "PUWzJmipCIyvciMDEr3IfhXuV3Gx",
"updatedSessionTokenId": "1234567890",
"lastUpdatedDateTimeGmt": "May 12, 2018 08:28:48 PM",
“orderType”: “Online”
"id": "8e2973e3-b43b-4430-b6d7-7c24846e9bba"
},
{
“orderNumber": 2,
“orderName": “Medications”,
"recordVersion": 1,
"createdDateTimeGmt": "May 09, 2018 03:19:11 PM",
"deletedDateTimeGmt": null,
"createdSessionTokenId": "PUWzJmipCIyvciMDEr3IfhXuV3Gx",
"updatedSessionTokenId": "1234567890",
"lastUpdatedDateTimeGmt": "May 12, 2018 08:28:48 PM",
“orderType”: “Offline”
"id": "8e2973e3-b43b-4430-b6d7-7c2665e9bba"
}
]
}
Now my requirement is to fetch only orders of a certain type for a given customer id. The query i ran
{"index":"customer_domain_r4","type":"CustomerData"} {"query":{"bool":{"must":[{"match":{"id":"6fff6ce8-e792-4047-b636-a1dda0aa2b72"}},{"nested":{"path":"customerOrders","query":{"bool":{"must":[{"match":{"customerOrders. orderType":"Online"}}]}}}}]}},"_source":{"includes":["customerOrders"],"excludes":[]}}
The above query returns all the orders of the customer because the criteria looks for any customer which has an order of type online. I am looking for the query to return only orders of customer 6fff6ce8-e792-4047-b636-a1dda0aa2b72 of type online.
Is there a way I can directly add criteria for the includes section.
If not I have to filter this in the java middle tier section