doushan5222 2018-01-02 12:07
浏览 104
已采纳

ONGR ElasticsearchBundle将虚拟字段映射到ElasticSearch

I want to do a full name lookup in ElasticSearch when I have a first name and last name in MySQL.

I have looked at cross_fields and copy-to, but neither support the flexibility of being able to search part or all of the name in a MatchPhrasePrefixQuery as far as I can tell.

So what I want to do instead is add a field to ElasticSearch that is $firstName . ' ' . $lastName

I have mapped my user entity fields to ElasticSearch using the @ES decorator.

 /**
 * @var string
 *
 * @ORM\Column(name="firstname", type="string", length=255, nullable=true)
 * @ES\Property(type="keyword")
 * @Serializer\Groups({"default"})
 * @Serializer\SerializedName("firstName")
 */
private $firstname;

But how do I add a virtual fullName column to ElasticSearch so that I can search that field instead of the 2 separate fields?

Is there a way to add it using the decorators so that it is automatically handled with the other fields and data migrations etc., without having to make a separate import script for it and doing it manually?

  • 写回答

1条回答 默认 最新

  • douzai9405 2018-01-02 12:55
    关注

    Just a quick shot (not tested):

     /**
     * @var string
     *
     * @ES\Property(type="keyword")
     * @Serializer\Groups({"default"})
     * @Serializer\SerializedName("fullName")
     */
    private $fullname;
    
    /**
     * Get fullname
     *
     * @return string
     */
    public function getFullname()
    {
        return $this->firstname . ' ' . $this->lastname;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料