Product ES index #2
This commit is contained in:
parent
a3b944ed1e
commit
692f4ba3ab
|
|
@ -1,9 +1,11 @@
|
|||
from search_indexes.documents.establishment import EstablishmentDocument
|
||||
from search_indexes.documents.news import NewsDocument
|
||||
from search_indexes.documents.product import ProductDocument
|
||||
|
||||
|
||||
# todo: make signal to update documents on related fields
|
||||
__all__ = [
|
||||
'EstablishmentDocument',
|
||||
'NewsDocument',
|
||||
'ProductDocument',
|
||||
]
|
||||
|
|
@ -5,53 +5,21 @@ from search_indexes.utils import OBJECT_FIELD_PROPERTIES
|
|||
from product import models
|
||||
|
||||
ProductIndex = Index(settings.ELASTICSEARCH_INDEX_NAMES.get(__name__, 'product'))
|
||||
ProductIndex.settings(number_of_shards=1, number_of_replicas=1)
|
||||
ProductIndex.settings(number_of_shards=1, number_of_replicas=1, mapping={'total_fields':{'limit': 3000}})
|
||||
|
||||
|
||||
@ProductIndex.doc_type
|
||||
class ProductDocument(Document):
|
||||
"""Product document."""
|
||||
|
||||
@staticmethod
|
||||
def _get_standard_properties():
|
||||
return {
|
||||
'name': fields.KeywordField(),
|
||||
'standard_type': fields.IntegerField(),
|
||||
'coordinates': fields.GeoPointField(),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _get_country_properties():
|
||||
return {
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _get_tags_properties():
|
||||
return {
|
||||
'label': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'value': fields.KeywordField(),
|
||||
'category': fields.ObjectField(properties={
|
||||
'label': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'public': fields.BooleanField(),
|
||||
'index_name': fields.KeywordField(),
|
||||
'value_type': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties=ProductDocument._get_country_properties()),
|
||||
}),
|
||||
}
|
||||
|
||||
description = fields.ObjectField(attr='description_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES)
|
||||
product_type = fields.ObjectField(properies={
|
||||
product_type = fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'index_name': fields.KeywordField(),
|
||||
'use_subtypes': fields.BooleanField(),
|
||||
})
|
||||
|
||||
subtypes = fields.ObjectField(
|
||||
properties={
|
||||
'name': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
|
|
@ -59,41 +27,77 @@ class ProductDocument(Document):
|
|||
},
|
||||
multi=True
|
||||
)
|
||||
|
||||
# TODO establishment
|
||||
|
||||
wine_region = fields.ObjectField(properties={
|
||||
'name': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties=_get_country_properties()),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
'coordinates': fields.GeoPointField(),
|
||||
'description': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
})
|
||||
|
||||
wine_sub_region = fields.ObjectField(properties={'name': fields.KeywordField()})
|
||||
|
||||
classifications = fields.ObjectField( # TODO
|
||||
properties={
|
||||
'classification_type': fields.ObjectField(properties={}),
|
||||
'standard': fields.ObjectField(properties=_get_standard_properties()),
|
||||
'standard': fields.ObjectField(properties={
|
||||
'name': fields.KeywordField(),
|
||||
'standard_type': fields.IntegerField(),
|
||||
'coordinates': fields.GeoPointField(),
|
||||
}),
|
||||
'tags': fields.ObjectField(
|
||||
properties=_get_tags_properties(),
|
||||
properties={
|
||||
'label': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'value': fields.KeywordField(),
|
||||
'category': fields.ObjectField(properties={
|
||||
'label': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'public': fields.BooleanField(),
|
||||
'index_name': fields.KeywordField(),
|
||||
'value_type': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
multi=True
|
||||
),
|
||||
},
|
||||
multi=True
|
||||
)
|
||||
|
||||
standards = fields.ObjectField(
|
||||
properties=_get_standard_properties(),
|
||||
properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
},
|
||||
multi=True
|
||||
)
|
||||
|
||||
wine_village = fields.ObjectField(properties={
|
||||
'name': fields.KeywordField(),
|
||||
})
|
||||
|
||||
tags = fields.ObjectField(
|
||||
properties=_get_tags_properties(),
|
||||
properties={
|
||||
'label': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'value': fields.KeywordField(),
|
||||
'category': fields.ObjectField(properties={
|
||||
'label': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'public': fields.BooleanField(),
|
||||
'index_name': fields.KeywordField(),
|
||||
'value_type': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}),
|
||||
}),
|
||||
},
|
||||
multi=True
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ router = routers.SimpleRouter()
|
|||
router.register(r'establishments', views.EstablishmentDocumentViewSet, basename='establishment')
|
||||
router.register(r'mobile/establishments', views.EstablishmentDocumentViewSet, basename='establishment-mobile')
|
||||
router.register(r'news', views.NewsDocumentViewSet, basename='news')
|
||||
router.register(r'product', views.ProductDocumentViewSet, basename='news')
|
||||
router.register(r'product', views.ProductDocumentViewSet, basename='product')
|
||||
|
||||
urlpatterns = router.urls
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user