# How to disable \_source from dsl when creating mappings

**URL:** <https://discuss.elastic.co/t/how-to-disable-source-from-dsl-when-creating-mappings/122495>\
**Category:** Elasticsearch\
**Created:** [March 5, 2018, 11:44am UTC](https://discuss.elastic.co/t/how-to-disable-source-from-dsl-when-creating-mappings/122495 "2018-03-05T11:44:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlosvega](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlosvega/32/28433_2.png) [@carlosvega](https://discuss.elastic.co/u/carlosvega)\
**Post date:** [March 5, 2018, 11:44am UTC](https://discuss.elastic.co/t/how-to-disable-source-from-dsl-when-creating-mappings/122495/1 "2018-03-05T11:44:00Z")

</div>

I can't find how should I proceed to disable \_source field when using the Python elasticsearch-dsl API.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![carlosvega](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlosvega/32/28433_2.png) [@carlosvega](https://discuss.elastic.co/u/carlosvega)\
**Post date:** [March 5, 2018, 2:43pm UTC](https://discuss.elastic.co/t/how-to-disable-source-from-dsl-when-creating-mappings/122495/2 "2018-03-05T14:43:32Z")

</div>

I answer my self:

You can dynamically create a DocType class to support the elasticsearch-dsl methods, like this.  
With `dicc` being a dictionary with the types, like:

```
    es = Elasticsearch()
    dicc = {'date': Date(), 'age': Integer(), 'location': GeoPoint(), 'ip': Ip(), 'name': Keyword(), 'comments': Text()}

	if args.no_source: #to disable _source field
		dicc[doc_type] = {'_source' : {'enabled' : False}}

	if args.no_all: #to disable _all field
		dicc[doc_type] = {'_all' : {'enabled' : False}}		
		
	DocClass = type(doc_type, (DocType,), dicc)
	DocClass.init(index='indexname', using=es)

```

And it works ! 😊

---

<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:** [April 2, 2018, 2:43pm UTC](https://discuss.elastic.co/t/how-to-disable-source-from-dsl-when-creating-mappings/122495/3 "2018-04-02T14:43:33Z")

</div>

Closed on April 2, 2018, 2:43pm UTC

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