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, })
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 }, }
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, } }
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])
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()))
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)