Exemple #1
0
    def init_elasticsearch(index: bool, data: bool, product: bool,
                           category: bool, product_version: str):
        import orjson

        from robotoff import settings
        from robotoff.utils.es import get_es_client
        from robotoff.elasticsearch.product.dump import product_export
        from robotoff.elasticsearch.category.dump import category_export

        if index:
            with settings.ELASTICSEARCH_PRODUCT_INDEX_CONFIG_PATH.open(
                    "rb") as f:
                product_index_config = orjson.loads(f.read())

            with settings.ELASTICSEARCH_CATEGORY_INDEX_CONFIG_PATH.open(
                    "rb") as f:
                category_index_config = orjson.loads(f.read())

            client = get_es_client()

            if product:
                client.indices.create(product_version, product_index_config)

            if category:
                client.indices.create("category", category_index_config)

        if data:
            if product:
                product_export(version=product_version)

            if category:
                category_export()
Exemple #2
0
    def init_elasticsearch(index: bool, data: bool, product: bool,
                           category: bool):
        import json
        from robotoff import settings
        from robotoff.utils.es import get_es_client
        from robotoff.elasticsearch.product.dump import product_export
        from robotoff.elasticsearch.category.dump import category_export

        if index:
            with settings.ELASTICSEARCH_PRODUCT_INDEX_CONFIG_PATH.open(
                    'r') as f:
                product_index_config = json.load(f)

            with settings.ELASTICSEARCH_CATEGORY_INDEX_CONFIG_PATH.open(
                    'r') as f:
                category_index_config = json.load(f)

            client = get_es_client()

            if product:
                client.indices.create('product', product_index_config)

            if category:
                client.indices.create('category', category_index_config)

        if data:
            if product:
                product_export()

            if category:
                category_export()