Ejemplo n.º 1
0
def index_objects(ids,
                  model,
                  search,
                  index=None,
                  transforms=None,
                  objects=None):
    if index is None:
        index = model._get_index()
    if objects is None:
        objects = model.objects

    indices = Reindexing.objects.get_indices(index)

    if transforms is None:
        transforms = []

    qs = objects.no_cache().filter(id__in=ids)
    for t in transforms:
        qs = qs.transform(t)

    bulk = []
    for ob in qs:
        data = search.extract(ob)
        for index in indices:
            bulk.append({
                "_source": data,
                "_id": ob.id,
                "_type": ob.get_mapping_type(),
                "_index": index
            })

    es = amo.search.get_es()
    return helpers.bulk(es, bulk)
Ejemplo n.º 2
0
def index_objects(ids, model, search, index=None, transforms=None):
    if index is None:
        index = model._get_index()

    indices = get_indices(index)

    if transforms is None:
        transforms = []

    qs = model.uncached.filter(id__in=ids)
    for t in transforms:
        qs = qs.transform(t)

    for ob in qs:
        data = search.extract(ob)

        for index in indices:
            model.index(data, bulk=True, id=ob.id, index=index)

    amo.search.get_es().flush_bulk(forced=True)
Ejemplo n.º 3
0
def index_objects(ids, model, search, index=None, transforms=None):
    if index is None:
        index = model._get_index()

    indices = Reindexing.objects.get_indices(index)

    if transforms is None:
        transforms = []

    qs = model.objects.no_cache().filter(id__in=ids)
    for t in transforms:
        qs = qs.transform(t)

    for ob in qs:
        data = search.extract(ob)

        for index in indices:
            model.index(data, bulk=True, id=ob.id, index=index)

    amo.search.get_es().flush_bulk(forced=True)
Ejemplo n.º 4
0
def index_objects(ids, model, search, index=None, transforms=None):
    if index is None:
        index = model._get_index()

    indices = Reindexing.objects.get_indices(index)

    if transforms is None:
        transforms = []

    qs = model.objects.no_cache().filter(id__in=ids)
    for t in transforms:
        qs = qs.transform(t)

    bulk = []
    for ob in qs:
        data = search.extract(ob)
        for index in indices:
            bulk.append({"_source": data, "_id": ob.id, "_type": ob.get_mapping_type(), "_index": index})

    es = amo.search.get_es()
    return helpers.bulk(es, bulk)