# Adding Source Filtering for Includes segment

**URL:** <https://discuss.elastic.co/t/adding-source-filtering-for-includes-segment/144211>\
**Category:** Elasticsearch\
**Created:** [August 13, 2018, 4:20pm UTC](https://discuss.elastic.co/t/adding-source-filtering-for-includes-segment/144211 "2018-08-13T16:20:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tatha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tatha/32/22976_2.png) [@tatha](https://discuss.elastic.co/u/tatha)\
**Post date:** [August 13, 2018, 4:20pm UTC](https://discuss.elastic.co/t/adding-source-filtering-for-includes-segment/144211/1 "2018-08-13T16:20:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jaddison](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@jaddison](https://discuss.elastic.co/u/jaddison)\
**Post date:** [September 9, 2018, 9:16pm UTC](https://discuss.elastic.co/t/adding-source-filtering-for-includes-segment/144211/2 "2018-09-09T21:16:28Z")

</div>

I think you need to add your index/doc mapping.

Also, if you pretty-print/indent your docs and query, it makes it easier for people to parse and provide answers.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 7, 2018, 9:20pm UTC](https://discuss.elastic.co/t/adding-source-filtering-for-includes-segment/144211/3 "2018-10-07T21:20:27Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
