In my laravel 5.7 app I use Elasticsearch and I have bulk function to fill my votes with related vote_items.
The problem is that I that I can not add array of related vote_items as I get error :
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"object mapping for [vote_items] tried to parse field [null] as object, but found a concrete value"}],"type":"mapper_parsing_exception","reason":"object mapping for [vote_items] tried to parse field [null] as object, but found a concrete value"},"status":400}
at method(error line is uncomment and marked):
public static function bulkVotesToElastic()
{
$elastic = app(\App\Elastic\Elastic::class);
$elasticsearch_root_index = config('app.elasticsearch_root_index');
$elasticsearch_type = with(new Vote)->getElasticsearchType();
Vote::chunk(100, function ($Votes) use ($elastic, $elasticsearch_root_index, $elasticsearch_type) {
foreach ($Votes as $nextVote) {
if ($nextVote->status!= 'A') continue; // only active votes must be saved in elasticsearch
$voteCategory= $nextVote->voteCategory;
if (empty($voteCategory)) continue; // only votes with valid category must be saved in elasticsearch
if ( !$voteCategory->active ) continue; // only votes with active category must be saved in elasticsearch
$voteItems = VoteItem
::getByVote($nextVote->id)
->orderBy('ordering', 'asc')
->get();
$relatedVoteItemsList= [];
foreach ($voteItems as $nextVoteItem) {
$relatedVoteItemsList[]= $nextVoteItem->name; // THIS LINE RAISE ERROR!
// $relatedVoteItemsList[]= [ $nextVoteItem->name ]; // THIS LINE RAISE ERROR TOO!
// $relatedVoteItemsList[]= [ 'vote_item_name' => $nextVoteItem->name ]; // THIS LINE DOES NOT RAISE ERROR!
}
$elastic->index([
'index' => $elasticsearch_root_index,
'type' => $elasticsearch_type,
'id' => $nextVote->id,
'body' => [
'id' => $nextVote->id,
'slug' => $nextVote->slug,
'name' => $nextVote->name,
'description' => $nextVote->description,
'created_at' => $nextVote->created_at,
'vote_items' => $relatedVoteItemsList,
'category_id' => $voteCategory->id,
'category' => [
'name' => $voteCategory->name,
'slug' => $voteCategory->slug,
'created_at' => $voteCategory->created_at,
],
]
]);
}
});
}
If I uncomment line :
// $relatedVoteItemsList[]= [ 'vote_item_name' => $nextVoteItem->name ]; // THIS LINE DOES NOT RAISE ERROR!
and comment 2 lines above then bulk works ok, but my search condition does not work for vote_items
$elasticQuery = [
"bool" => [
'must' => [
[
"multi_match" => [
"query" => $text,
"type" => "cross_fields",
"fields" => [
"name^4",
"description",
"vote_items^2"
]
],
],
],
]
];
and I do not know which syntax is valid?
Thanks!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire