使用relationsip的Symfony elastica映射在填充索引

时间:2017-07-31 01:56:51

标签: php symfony elasticsearch foselasticabundle

我想索引来自我已经拥有索引的主要实体的关联实体的一些数据。我的映射规则如下,我也给了下面的2个实体。我的问题是我在尝试填充索引时得到OutOfMemoryExceptionbin/console fos:elastica:populate --index=sales_rule

索引配置

sales_rule:
            client: default
            use_alias: true
            types:
                sales_rule:
                    mappings:
                        id: {type: integer}
                        name:
                        description:
                        salesCoupons:
                            type: nested
                            properties:
                                code:
                    persistence:
                        driver: orm
                        model: MyProject\MyBundle\Entity\SalesRule
                        provider:
                            batch_size: 100
                        listener:

实体

/**
 * @ORM\Table(name="sales_rule")
 * @ORM\Entity(repositoryClass="MyProject\MyBundle\Repository\SalesRuleRepository")
 */
class SalesRule
{
    /**
     * @var int
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(type="text")
     */
    private $description;

    /**
     * @var int
     *
     * @ORM\Column(type="integer", nullable=true)
     */
    private $usageLimit;

    /**
     * @var SalesCoupon[]|ArrayCollection
     *
     * @ORM\OneToMany(targetEntity="SalesCoupon", mappedBy="salesRule")
     */
    private $salesCoupons;

    public function __construct()
    {
        $this->salesCoupons = new ArrayCollection();
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return int
     */
    public function getUsageLimit()
    {
        return $this->usageLimit;
    }

    /**
     * @return int
     */
    public function getUsagePerCustomer()
    {
        return $this->usagePerCustomer;
    }

    /**
     * @param string $description
     * @return SalesRule
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * @param string $name
     * @return SalesRule
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @param int $usageLimit
     * @return SalesRule
     */
    public function setUsageLimit($usageLimit)
    {
        $this->usageLimit = $usageLimit;

        return $this;
    }

    /**
     * @return SalesCoupon[]|ArrayCollection
     */
    public function getSalesCoupons()
    {
        return $this->salesCoupons;
    }

    /**
     * @param ArrayCollection $salesCoupons
     */
    public function setSalesCoupons(ArrayCollection $salesCoupons)
    {
        $this->salesCoupons = $salesCoupons;
    }
}

    /**
 * @ORM\Table(name="sales_coupon")
 * @ORM\Entity(repositoryClass="MyProject\MyBundle\Repository\SalesCouponRepository")
 */
class SalesCoupon
{

    /**
     * @var int
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     */
    private $id;

    /**
     * @var SalesRule
     *
     * @Serializer\Exclude
     *
     * @ORM\ManyToOne(targetEntity="SalesRule", inversedBy="salesCoupons")
     * @ORM\JoinColumn(nullable=false)
     */
    private $salesRule;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $fromDate;

    /**
     * @var \DateTime
     *
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $toDate;

    /**
     * @var string
     *
     * @ORM\Column(nullable=true)
     */
    private $code;

    /**
     * @var int
     *
     * @Assert\Range(min=0)
     *
     * @ORM\Column(type="integer", nullable=true)
     */
    private $usageLimit;


    public function __construct()
    {
        $this->salesCouponCustomers = new ArrayCollection();
    }

    /**
     * @return string
     */
    public function getCode()
    {
        return $this->code;
    }

    /**
     * @return \DateTime
     */
    public function getFromDate()
    {
        return $this->fromDate;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return \Unity\CmsBundle\Entity\SalesRule
     */
    public function getSalesRule()
    {
        return $this->salesRule;
    }

    /**
     * @return \DateTime
     */
    public function getToDate()
    {
        return $this->toDate;
    }

    /**
     * @param string $code
     * @return SalesCoupon
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

    /**
     * @param \DateTime $fromDate
     * @return SalesCoupon
     */
    public function setFromDate($fromDate)
    {
        $this->fromDate = $fromDate;

        return $this;
    }

    /**
     * @param \Unity\CmsBundle\Entity\SalesRule $salesRule
     * @return SalesCoupon
     */
    public function setSalesRule(SalesRule $salesRule)
    {
        $this->salesRule = $salesRule;

        return $this;
    }

    /**
     * @param \DateTime $toDate
     * @return SalesCoupon
     */
    public function setToDate($toDate)
    {
        $this->toDate = $toDate;

        return $this;
    }
}

1 个答案:

答案 0 :(得分:0)

您可以尝试设置限制内存无限制。 php -d memory_limit=-1 bin/console fos:elastica:populate --index=sales_rule