Example #1
0
def insert_coworking(instance):
    client = ChHelpers.get_es()

    try:
        client.delete(
            index=settings.ELASTICSEARCH['index'],
            doc_type=settings.ELASTICSEARCH['doc_type'],
            id=instance.pk
        )
    except:
        pass

    client.index(
        index=settings.ELASTICSEARCH['index'],
        doc_type=settings.ELASTICSEARCH['doc_type'],
        id=instance.pk,
        body={
            'name': instance.name,
            'location': {
                'lat': instance.lat,
                'lon': instance.lng
            },
            'amenities': [a.name for a in instance.amenities.all()],
            'photos': [a.photo.url for a in instance.photos.all()],
            'tables': [{
                'name': t.name,
                'price': t.price,
                'pk': t.pk,
            } for t in instance.tables.all()]
        }
    )
Example #2
0
    def handle_noargs(self, **options):
        es = ChHelpers.get_es()
        indices = es.indices

        index = settings.ELASTICSEARCH['index']
        doc_type = settings.ELASTICSEARCH['doc_type']

        if indices.exists(index):
            indices.delete(index)

        indices.create(index, {
            'mappings': {
                doc_type: {
                    'properties': {
                        'location': {
                            'type': 'geo_point',
                            'store': True
                        }
                    }
                }
            }
        })