In our symfony2 project we want to implement elasticsearch with ongr-io bundle, but our whole system is built on doctrine. Is it possible to somehow use ongr-io elasticsearch bundle without totally redoing whole database with documents instead of entities?
Entity that I want to index (fields for search would be: name, ChildCategory and ParentCategory):
/**
* Course
*
* @ORM\Table(name="course")
* @ORM\Entity(repositoryClass="CoreBundle\Repository\CourseRepository")
* @ORM\HasLifecycleCallbacks
*/
class Course
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, unique=false)
*/
private $name;
/**
* @var ParentCategory
*
* @ORM\ManyToOne(targetEntity="ParentCategory")
* @ORM\JoinColumn(name="parentCategory_id", referencedColumnName="id")
*/
private $parentCategory;
/**
* @var ChildCategory
*
* @ORM\ManyToOne(targetEntity="ChildCategory", inversedBy="courses")
* @ORM\JoinColumn(name="childCategory_id", referencedColumnName="id")
*/
private $childCategory;
/**
* @var City
*
* @ORM\ManyToOne(targetEntity="City")
* @ORM\JoinColumn(name="city_id", referencedColumnName="id")
*/
private $city;
/**
* @var Users
*
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\Users", inversedBy="course")
* @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
*/
private $owner;
/**
* @var text
*
* @ORM\Column(name="description", type="text")
*/
private $description;
/**
* @var Picture
*
* @ORM\OneToMany(targetEntity="CoreBundle\Entity\Picture", mappedBy="course", cascade={"persist", "remove"})
*/
private $pictures;
/**
* @var Ratings
*
* @ORM\OneToMany(targetEntity="CoreBundle\Entity\Ratings", mappedBy="courseid")
*/
private $ratings;
public $avgRating;
}
it's very interesting.
The first thing is Entity location. The document for ElasticsearchBundle has to be in
Documentdirectory. It's not a big deal. All you need to do is to create an empty class and extend entity with@Documentannotation. Next are the fields. Withnamefield there is no problem at all, just add@propertyannotation and you are good. More interesting is with relations. My suggestion would be to create separate property and in the getter return value from the relation for that field. I hope you got the idea.Update:
Here's an example of documents:
AppBundle/Entity/Post
AppBundle/Document/Post