laravel elasticsearch babenkoivan/弹性适配器模型关系

yfjy0ee7  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(452)

我正在寻找使用ElasticSearch与模型关系的项目。
现在ElasticSearch已经开始工作了,我跟随这个文档,他解释了如何从这个包开始:
elasticsearch/ElasticSearch
babenkoivan/弹性迁移
babenkoivan/弹性适配器
babenkoivan/弹性童子军司机
问题是我需要能够按关系搜索。
这是我的复合弹性迁移:

  1. Index::create('composant', function(Mapping $mapping, Settings $settings){
  2. $mapping->text('reference');
  3. $mapping->keyword('designation');
  4. $mapping->join('categorie');
  5. $settings->analysis([
  6. 'analyzer' => [
  7. 'reference' => [
  8. 'type' => 'custom',
  9. 'tokenizer' => 'whitespace'
  10. ],
  11. 'designation' => [
  12. 'type' => 'custom',
  13. 'tokenizer' => 'whitespace'
  14. ]
  15. ]
  16. ]);
  17. });

这里是我的分类弹性迁移:

  1. Index::create('categorie', function(Mapping $mapping, Settings $settings){
  2. $mapping->keyword('nom');
  3. $settings->analysis([
  4. 'analyzer' => [
  5. 'nom' => [
  6. 'type' => 'custom',
  7. 'tokenizer' => 'whitespace'
  8. ]
  9. ]
  10. ]);
  11. });

我的复合模型:

  1. public function categorie()
  2. {
  3. return $this->belongsTo('App\Model\Categorie');
  4. }
  5. public function toSearchableArray()
  6. {
  7. return [
  8. 'reference' => $this->reference,
  9. 'designation' => $this->designation,
  10. 'categorie' => $this->categorie(),
  11. ];
  12. }

以及我的分类模型:

  1. public function toSearchableArray()
  2. {
  3. return [
  4. 'nom' => $this->nom,
  5. ];
  6. }

因此,如果查看composant关系,可以看到joinMap返回categorie关系。我现在不知道我是否做得对,但我知道的是,elasticsearch没有任何关系,在我要找的对象。
而且我没有找到任何关于如何使用包的连接Map方法的文档。

ny6fqffe

ny6fqffe1#

如果您想得到categorie的“nom”,请用composant模型代替它

  1. 'categorie' => $this->categorie->nom ?? null,

$this->categorie()返回关系,而不是对象。

相关问题