Search code examples
python-3.xelasticsearch-2.0elasticsearch-dsl

Elasticsearch DSL, store fields and dictionary


I have some fields with known mapping and some unknown, I want to store them. Mapping:

class MyDoctype(DocType):
  ...
  known_field = String(index='not_analyzed')
  ...

  unknown_dict = Nested() # How can I store this dict ???

This should be possible as ElasticSearch 2.x can handle this mixed mapping. Is ES dsl based on strict mappings behind the scene ? I also looked at the persistence docs but it seems to rely on strong mappings everywhere.


Solution

  • You can use Object. tested on Elasticsearch 6.x, Elasticsearch-dsl 6.x

    from elasticsearch_dsl import DocType, Object
    
    class MyDoctype(DocType):
      ...
      known_field = String(index='not_analyzed')
      ...
    
      unknown_dict = Object()