Elasticquent Parent/Child Mapping

时间:2019-04-08 13:00:28

标签: elasticsearch laravel-5.2 elasticsearch-6

I want to define the parent/child mapping on my model through Elasticquent. When I index the data it is ignoring my mapping properties that I set on the model. It is also possible that the linking of my parent/child relationship is not being set but I would like to set it with Elasticquent.

I have already tried indexing the relational data on the object itself as well as defining the mapping properties on the model itself using elasticquent. Both methods seem to ignore the relationship completely.

I have already tried the following:

  1. Setting the relationship when indexing the data

    $model = 'App\Lead';
    $entities = $model::with('company')->get();
    foreach ($entities as $entity) {
        $entity->addToIndex();
    }
    
  2. Setting the parent/child mapping on the model itself:

    protected $mappingProperties = [
        'leads' => [
            '_parent' => [
                'type' => 'company'
            ]
        ]
    ]
    

I tried doing the search like this:

'query' => [
    'has_parent' => [
        'type' => 'company',
        'query' => [
            'term' => [
                'id' => $company_id
            ]
        ]
    ],
],
'query' => [
    'wildcard' => [
        'name'     => $keywords.'*',
    ],
]

I am expecting to see the relationship defined in the mapping properties but there is nothing like a "type" or "parent" that is being show and when using the "has_parent" query it is clearly not filtering the results correctly and showing leads for all companies and not only the one that I am busy on.

0 个答案:

没有答案