Comments (4)
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.
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.
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.
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)
- Range query fails when using date strings HOT 3
- Can't index as float type for decimal db field HOT 1
- PHPStan failing in PHP8.3 CI HOT 3
- Mocking multiple ES responses HOT 2
- Permission Error while cleaning Aliases
- Model not being imported HOT 8
- Set limit/offset in search (not in paginate) HOT 7
- Unable to filter Date using Range HOT 1
- Unable to nested sorting HOT 3
- Bump elasticsearch version HOT 1
- Raw query HOT 1
- Support for Ingest Pipelines HOT 5
- Not erroring when indexing field of wrong type HOT 1
- Batch indexing model with condition HOT 1
- PHP 8.3 support in composer.json HOT 2
- `whereIn` not accepting integers HOT 7
- Laravel 11: Bump required illuminate/support to ^11 HOT 2
- how to add shards HOT 5
- Index aliases HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from explorer.