Exemple #1
0
 class TestDocument(Document):
     name = Field(String, required=True)
     status = Field(Integer)
 class ProductDocument(Document):
     is_visible = Field(Boolean)
Exemple #3
0
        class GeoPointDoc(Document):
            __doc_type__ = 'geo_data'

            pin = Field(GeoPoint)
Exemple #4
0
        class CompletionDoc(Document):
            __doc_type__ = 'suggest'

            suggest = Field(Completion, payloads=True)
Exemple #5
0
        class ProductGroupDocument(Document):
            __doc_type__ = 'product_group'

            id = Field(Integer)
            name = Field(String, norms={'enabled': False})
Exemple #6
0
    def test_to_mapping(self):
        class ProductGroupDocument(Document):
            __doc_type__ = 'product_group'

            id = Field(Integer)
            name = Field(String, norms={'enabled': False})

        self.assertEqual(
            ProductGroupDocument.to_mapping(),
            {
                "product_group": {
                    "properties": {
                        "id": {
                            "type": "integer"
                        },
                        "name": {
                            "type": "string",
                            "norms": {
                                "enabled": False
                            }
                        }
                    }
                }
            }
        )

        class ProductGroupSubDocument(Document):
            id = Field(Integer)
            name = Field(String, norms={'enabled': False})

            __dynamic_fields__ = [
                Field('group_id_level_*', Integer)
            ]

            __mapping_options__ = {
                'dynamic': True,
            }

        class ProductDocument(Document):
            __doc_type__ = 'product'

            __mapping_options__ = {
                'dynamic': False,
                'date_detection': False,
            }

            _routing = Field(required=True, path='company_id')
            _all = Field(enabled=False)

            name = Field(
                String,
                fields={
                    'autocomplete': Field(
                        String,
                        analyzer='ngrams',
                        search_analyzer='text_delimit',
                        norms={'enabled': False}
                    )
                }
            )
            company_id = Field(Integer)
            group = Field(Object(ProductGroupSubDocument))
            popularity = Field(Float, doc_values=True)

            __dynamic_fields__ = [
                Field('attr_*', Integer)
            ]

        ProductDocument.tags = Field(List(String))

        self.assertEqual(
            ProductDocument.to_mapping(),
            {
                "product": {
                    "dynamic": False,
                    "date_detection": False,
                    "dynamic_templates": [
                        {
                            "group.group_id_level_*": {
                                "path_match": "group.group_id_level_*",
                                "mapping": {
                                    "type": "integer"
                                }
                            }
                        },
                        {
                            "attr_*": {
                                "path_match": "attr_*",
                                "mapping": {
                                    "type": "integer"
                                }
                            }
                        }
                    ],
                    "_routing": {
                        "required": True,
                        "path": "company_id"
                    },
                    "_all": {
                        "enabled": False
                    },
                    "properties": {
                        "name": {
                            "type": "string",
                            "fields": {
                                "autocomplete": {
                                    "type": "string",
                                    "analyzer": "ngrams",
                                    "search_analyzer": "text_delimit",
                                    "norms": {"enabled": False}
                                }
                            }
                        },
                        "company_id": {
                            "type": "integer"
                        },
                        "group": {
                            "dynamic": True,
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "integer"
                                },
                                "name": {
                                    "type": "string",
                                    "norms": {
                                        "enabled": False
                                    }
                                }
                            }
                        },
                        "popularity": {
                            "type": "float",
                            "doc_values": True
                        },
                        "tags": {
                            "type": "string"
                        }
                    }
                }
            }
        )
Exemple #7
0
 class InheritedDocument(TestDocument):
     description = Field(String)
Exemple #8
0
class TestDocument(Document):
    _all = Field(enable=False)

    name = Field('test_name', String(), fields={'raw': Field(String)})
    status = Field(Integer)
    group = Field(Object(GroupDocument))
    price = Field(Float)
    tags = Field(List(Object(TagDocument)))
    date_created = Field(Date)
    unused = Field(String)

    __dynamic_fields__ = [
        Field('i_attr_*', Integer),
        Field('b_attr_*', Boolean),
    ]
Exemple #9
0
class TagDocument(Document):
    id = Field(Integer)
    name = Field(String)
    group = Field(Object(GroupDocument))