Explorer icon indicating copy to clipboard operation
Explorer copied to clipboard

`whereIn` not accepting integers

Open Aniket-IN opened this issue 1 year ago β€’ 7 comments

Hi πŸ‘‹,

First of all thank you for this amazing package. I Just started learning the basics of Elastic Search.

I was trying to do filtering like this:

User::search("")->whereIn('id', [1, 2, 3])->get();

It throws error: Expected a string. Got: integer

If I do,

User::search("")->where('id', 1)->get();

It works completely fine.

I mean I could definitely manually transform them to string, Just the different allowed types for where and whereIn seemed odd.

Is this intentional?

Thanks again 😊

Aniket-IN avatar Jan 14 '24 21:01 Aniket-IN

Can you locate where the error is from? As far as I know where and whereIn are part of Laravel and not Explorer. So I'm curious for the stacktrace :)

Jeroen-G avatar Jan 15 '24 08:01 Jeroen-G

Previously I was using Meilisearch driver, it was working fine with integers whereIn('id', [1, 2, 3])

The error is coming from here: image

Aniket-IN avatar Jan 15 '24 09:01 Aniket-IN

Ah ok. From the docs:

value (Required, string) Term you wish to find in the provided . To return a document, the term must exactly match the field value, including whitespace and capitalization.

So they need to be strings for this Elasticsearch syntax.

Jeroen-G avatar Jan 15 '24 09:01 Jeroen-G

Hmm, but then why does where works with integer and not whereIn πŸ€”

Aniket-IN avatar Jan 15 '24 09:01 Aniket-IN

Because where uses the Term syntax and whereIn uses Terms, and someone forgot to add the assertion to Term. πŸ•΅οΈ

Jeroen-G avatar Jan 15 '24 09:01 Jeroen-G

Honestly, the where is working fine. I can pass integers and it filters as expected.

So I think safe to remove the assertion from whereIn? Or atleast allow strings and numbers as well.

Aniket-IN avatar Jan 15 '24 10:01 Aniket-IN

Feel free to test, verify and if so create a PR!

Jeroen-G avatar Jan 15 '24 13:01 Jeroen-G