How to disable _source from dsl when creating mappings


(Carlosvega) #1

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

Thanks :slight_smile:


(Carlosvega) #2

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 ! :blush:


(system) #3

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