pdphilip / laravel-elasticsearch

Laravel Elasticsearch: An Elasticsearch implementation of Laravel's Eloquent ORM
https://elasticsearch.pdphilip.com/
MIT License
88 stars 16 forks source link

Nested / Dot notation whereExact Fails #42

Open use-the-fork opened 3 days ago

use-the-fork commented 3 days ago

Describe the bug

When using whereExact with either a queryNested or by using dot notation a ParameterException occurs. This seems to be a direct result of the parseRequiredKeywordMapping helper in the Bridge.

To Reproduce

Create a nested field mapping as part of the schema make sure it has a keyword mapping and then query in either of these fashions:

       ConfiguredItem::queryNested('request', function ($query) use ($item) {
            $query->whereExact('item_number', $item['item_number']);
        })->toSql();
       ConfiguredItem::whereExact('request.business_unit', $item['business_unit']))->toSql();

Expected behavior

This should work as long as long as the field is mapped to a keyword field.


Screenshots:

image

image

pdphilip commented 3 days ago

If you try:

$query->whereExact('item_number.keyword', $item['item_number']);

and

ConfiguredItem::whereExact('request.business_unit.keyword', $item['business_unit']))->get();

Then still the same issue?

Mapping order matters, so if you map the $index->keyword first and then $index->text; then keyword is used by default, and the field still remains text analysed for full-text searching. Just how ES works, they could really do that one better...

Let me know

use-the-fork commented 3 days ago

yes same issue. But let me try moving the mapping around I didn't think about that.

use-the-fork commented 3 days ago

No Same result. Here is my updated mapping: image

Here it is when I ask for mapping directly: image

and doing this:

ConfiguredItem::whereExact('request.business_unit', $item['business_unit'])->toSql();

and this:

onfiguredItem::queryNested('request', function ($query) use ($item) {
            $query->whereExact('business_unit', $item['business_unit']); //or comments.country
        })->toSql()

fails. image

pdphilip commented 3 days ago

Definitely a bug. I'll look into it. Thanks

use-the-fork commented 3 days ago

@pdphilip I fixed it. Raising a PR later today. It's because of the "." notation mostly