Giter VIP home page Giter VIP logo

Comments (4)

drmmr763 avatar drmmr763 commented on July 28, 2024

Small followup, I did confirm I could control the mapping from the root model:

/**
     * Get the indexable data array for the model.
     *
     * @return array<string, mixed>
     */
    public function toSearchableArray(): array
    {
        $array = $this->toArray();

        $array['candidate_skills'] = $this->candidateSkills->map(function ($item) {
            return $item->toSearchableArray();
        });

        return $array;
    }

Its not quite as elegant as I'd like but I recognize that might be a scout limitation. Still if there is a way to do it more per-model rather than the root model I'd love to know it.

from explorer.

Jeroen-G avatar Jeroen-G commented on July 28, 2024

Thank you for the elaborate description, really! πŸ‘

I dove into the source and this is the culprit:
https://github.com/Jeroen-G/Explorer/blob/master/src%2FApplication%2FOperations%2FBulk%2FBulkUpdateOperation.php#L62

It does nothing to see what happens in the root, it expects a plain array in return. Apparently you are the first to encounter this or be bothered by it😁

Unless you know of a smart solution I think you will have to do everything as you showed in the root toSearchableArray.

from explorer.

drmmr763 avatar drmmr763 commented on July 28, 2024

Thanks @Jeroen-G for confirming I wasn't missing anything!

I guess that explains why it doesn't work. For now I've gone ahead and set up my root document to call the toSearchableArray on child relations as needed.

I did want to follow up on one thing though: the nested object field mappings are also not being used to create the index in Elastic.

For example, in the code I give above with something like a Candidate, CandidateHasSkill, and Skill object, In the Candidate model, I can use mappableAs to define the field types I want in Elastic. I then also define candidate_has_skill as a nested field.

How do tell Elastic what the field types for candidate_has_skill are to be? it is doing automatically right now and getting it a bit wrong. For example its using integer or long for IDs when per Elastic's docs it really should be keyword.

https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html

Is there a way to define a nested object's field mappings?

from explorer.

Jeroen-G avatar Jeroen-G commented on July 28, 2024

There is a bit on nested mappings here: https://jeroen-g.github.io/Explorer/mapping.html which might help you!

I think this could work:

return [
    'id' => 'keyword',
    'candidate_skills' => [
        'name' => 'keyword'
    ]
];

from explorer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.