Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get only main body from indexed object from elasticsearch #117

Closed
IgorDePaula opened this issue Oct 25, 2016 · 10 comments
Closed

Get only main body from indexed object from elasticsearch #117

IgorDePaula opened this issue Oct 25, 2016 · 10 comments

Comments

@IgorDePaula
Copy link

I got indexed the model with yours relationships, the elasticsearch show me all data (relationship included) but on search by model, I got only data from main body, I dont got the data from relationship indexed too.

@brino
Copy link
Contributor

brino commented Oct 27, 2016

I think you just need to eager load the relations before indexing the data.

Or, what I like to do, is add the protected member $with to the model like this ...

protected $with = ['user','category','tags'];

This will automatically eager load user, category, and tags every time the model is accessed ... including when scout indexes documents.

@IgorDePaula
Copy link
Author

I have the model with relations indexed on elastic search, but, to return a search, I dont got the relations, in elasticsearch all data are there, all data of relations too. Only on search the data arent returned.

@brino
Copy link
Contributor

brino commented Oct 27, 2016

hmm that does seem a little odd ...

@IgorDePaula
Copy link
Author

My code

// in controller
public function search($search){
        return Produto::search($search)->get();
    }

My model

<?php

namespace Tandle\Pedagogico\Model;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Tandle\Support\Rules\Ativo;

class Produto extends Model
{
    use Ativo, Searchable;

    protected $primaryKey = 'idCurso';
    protected $table = 'Curso';

    public function tipoproduto()
    {
        return $this->belongsTo(TipoProduto::class);
    }

    public function instituicao()
    {
        return $this->belongsTo(Instituicao::class);
    }

    public function modulos()
    {
        return $this->hasMany(Modulo::class,'Curso');
    }

    public function disciplinas()
    {
        return $this->belongsToMany(Disciplina::class, 'CursoDisciplina',  'Curso','Disciplina');
    }
    public function alunos()
    {
        return $this->belongsToMany(User::class, 'CursoAluno',  'Curso','Aluno');
    }

    public function unidades()
    {
        return $this->belongsToMany(Unidade::class, 'UnidadesCursos', 'Curso','Unidade');
    }
    public function turmas()
    {
        return $this->hasMany(Turma::class, 'Curso');
    }

    public function searchableAs()
    {
        return 'produtos_index';
    }

    /**
     * @return array
     */
    public function toSearchableArray()
    {

      $array = $this->toArray();




      $array['modulos'] =self::with(['modulos'])->get();
      $array['unidades'] =self::with(['unidades'=>function($q){
          $q->select('Curso');
      }])->get();
      $array['disciplinas'] =self::with(['disciplinas'=>function($q){
          $q->orderBy('criterio_aprovacao','ASC');
      }])->get();

      return $array;
    }

}

and result
in ES
es
Note the relations
And result of search
errosearch
No relations from ES

@IgorDePaula
Copy link
Author

someone any idea?

1 similar comment
@IgorDePaula
Copy link
Author

someone any idea?

@driesvints
Copy link
Member

Going to close this as Elasticsearch support has been removed since. There are some third party packages on packages with an Elasticsearch engine for scout.

@IgorDePaula
Copy link
Author

Interesting, if you have a problem, you drop a tool (part of) that you created for erase the problem?

@driesvints
Copy link
Member

@IgorDePaula this was 2 years ago. You're always welcome to create a full and working ElasticSearch implementation for Scout yourself if you want :)

@IgorDePaula
Copy link
Author

IgorDePaula commented Oct 6, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants