예제 #1
0
def gendata():
    for product in all_products():
        yield dict(_index=INDEX_NAME,
                   _type=DOC_TYPE,
                   _id=product.id,
                   _source={
                       "name": product.name,
                       "image": product.image,
                   })
예제 #2
0
def products_to_index():
    for product in all_products():
        yield {
            "_index": INDEX_NAME,
            "_type": DOC_TYPE,
            "_id": product.id,
            "_source": {
                "name": product.name,
                "image": product.image,
                "description": product.description
            },
        }
예제 #3
0
def single_product(product_id):
    """
    Display information about a specific product
    """

    product = str(all_products()[product_id - 1])

    return render_template(
        'product.html',
        product_json=product,
        search_term='',
    )
def products_to_index():
    for product in all_products():
        yield {
            '_op_type': 'create',
            "_index": INDEX_NAME,
            # doc_type=DOC_TYPE,
            "_id": product.id,
            "_source": {
                "url": product.url,
                "title": product.title,
            }
        }
예제 #5
0
def products_to_index():
    for product in all_products():
        yield {
            '_op_type': 'index',
            '_index': INDEX_NAME,
            '_type': DOC_TYPE,
            '_id': product.id,
            '_source': {
                'name': product.name,
                'image': product.image,
                'price': product.price,
            },
        }
def main():
    # Connect to localhost:9200 by default.
    es = Elasticsearch()

    es.indices.delete(index=INDEX_NAME, ignore=404)
    es.indices.create(
        index=INDEX_NAME,
        body={
            'mappings': {},
            'settings': {},
        },
    )

    index_product(es, all_products()[0])
예제 #7
0
def main():
    # Connect to localhost:9200 by default.
    es = Elasticsearch()

    es.indices.delete(index=INDEX_NAME, ignore=404)
    es.indices.create(
        index=INDEX_NAME,
        body={
            'mappings': {},
            'settings': {},
        },
    )

    index_product(es, all_products()[0])
예제 #8
0
def main():
    # Connect to localhost:9200 by default.
    es = Elasticsearch()

    es.indices.delete(index=INDEX_NAME, ignore=404)
    es.indices.create(
        index=INDEX_NAME,
        body={
            'mappings': {
                DOC_TYPE: {
                    'properties': {
                        'name': {
                            'type': 'text',
                            'fields': {
                                'english_analyzed': {
                                    'type': 'text',
                                    'analyzer': 'custom_english_analyzer',
                                },
                            },
                        },
                        'description': {
                            'type': 'text',
                            'fields': {
                                'english_analyzed': {
                                    'type': 'text',
                                    'analyzer': 'custom_english_analyzer',
                                },
                            },
                        },
                    },
                },
            },
            'settings': {
                'analysis': {
                    'analyzer': {
                        'custom_english_analyzer': {
                            'type': 'english',
                            'stopwords': ['made', '_english_'],
                        },
                    },
                },
            },
        },
    )

    helpers.bulk(es, products_to_index(all_products()))
예제 #9
0
def products_index(es):
    actions = []
    pdts = all_products()
    for product in pdts:
        action = {
            "_index": INDEX_NAME,
            "_type": DOC_TYPE,
            "_id": product.id,
            "_source": {
                "name": product.name,
                "image": product.image,
                "description": product.description
            }
        }
        actions.append(action)

    helpers.bulk(es, actions)