# Regexp support in source filtering

**URL:** <https://discuss.elastic.co/t/regexp-support-in-source-filtering/117808>\
**Category:** Elasticsearch\
**Created:** [January 31, 2018, 1:12pm UTC](https://discuss.elastic.co/t/regexp-support-in-source-filtering/117808 "2018-01-31T13:12:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fchicharro](https://avatars.discourse-cdn.com/v4/letter/f/f07891/32.png) [@fchicharro](https://discuss.elastic.co/u/fchicharro)\
**Post date:** [January 31, 2018, 1:12pm UTC](https://discuss.elastic.co/t/regexp-support-in-source-filtering/117808/1 "2018-01-31T13:12:15Z")

</div>

Hi All,  
I have a question about the capabilities of source filtering.  
I have documents which represents products. Each document contains a set product properties and a set of product prices, one price for each country. Something like:

```
"product": {
	"name": "ProductA",
	"description": "Product A is really cool",
	"collection": "cool products",
	....
	"prices": {
		"US":{
			"price": 3000,
			"formattedPrice": "3,000 $"
		},
		"DE":{
			"price": 2900,
			"formattedPrice": "2.900 €"
		},
		"FR":{
			"price": 2850,
			"formattedPrice": "2.850 €"
		},		
		"CH":{
			"price": 3050,
			"formattedPrice": "CHF 3,050"
		},
		...
	}
}

```

I would like to use source filtering to return all the document fields, except for prices. For Prices I would like to return only the price of a specific country I know at query time.  
For instance: if I'm searching in the context of Switzerland I would need something like:

```
"_source": {
	"includes": "<all fields>"
	"excludes": "<all prices that are not for Switzerland>"
}

```

I tried with "excludes": "prices.~CH", which doesn't work.  
The only solution I could find was to add in the excludes clause all the prices that I don't want. e.g.

```
"_source": {
	"includes": "*"
	"excludes": ["prices.US", "prices.DE", "prices.FR", ..."]
}

```

The problem is that the list of countries for which I have a price is long, and can be different from product to product.

Is there a better way to address this requirement?

Thanks in advance,  
Francisco

---

<div class="post-metadata">

**Author:** ![svola](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@svola](https://discuss.elastic.co/u/svola)\
**Post date:** [February 13, 2018, 12:54pm UTC](https://discuss.elastic.co/t/regexp-support-in-source-filtering/117808/2 "2018-02-13T12:54:53Z")

</div>

Hi Francisco,

the only operator source filtering supports is the wildcard-operator to match full field names.  
So "prices._" or "_.DE" etc. would match all subfields inside the prices object or all objects that contain a "DE" field inside a document.

More advanced operators are unfortunatley not supported as far as I know.

[https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-request-source-filtering.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-request-source-filtering.html)

Kind regards,  
Saskia

---

<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:** [March 13, 2018, 12:55pm UTC](https://discuss.elastic.co/t/regexp-support-in-source-filtering/117808/3 "2018-03-13T12:55:00Z")

</div>

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