pdphilip / laravel-elasticsearch

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

[Fixed] whereIn appears to be partial matching strings #17

Closed davimug closed 7 months ago

davimug commented 7 months ago

Package version

ex: v2.10.3 (NB!)

Describe the bug

A clear and concise description of what the bug is.

Say we have the following document:

{
     name: 'John Smith',
     jobs: ['AI Inc', 'Loops Services'] <!- keyword field
}

and we do a query

Person::whereIn('jobs', ['AI', 'Loops'])->get();

We would expect no results, however, the query IS matching with the example provided.

To Reproduce

Steps to reproduce the behavior:

Expected behavior

A clear and concise description of what you expected to happen.


Screenshots: If applicable, add screenshots to help explain your problem.

Component Versions (Paste in the require section from your composer.json file):

  "require": {

  },

Additional context: Add any other context about the problem here.

pdphilip commented 7 months ago

Hey @davimug , seems to be getting hits on the text tokens.

Try:

Person::whereIn('jobs.keyword', ['AI', 'Loops'])->get();
davimug commented 7 months ago

Hi @pdphilip , thanks for the response! I tried that and it doesn't seem to match with any documents at all, even the correct ones.

pdphilip commented 7 months ago

Strange, first try update to the latest version v2.10.7 and see if it helps

Then, can you show me your mappings?

Schema::getMappings('people');

I'm in the process of rebuilding the bridge that will use DSL queries directly, the whereIn() method will leverage Elasticsearch's terms query that will look for an exact match. This will be a major release v3.x - weeks away.

In the meantime, an equivalent query would be:

Person::where('jobs', 'AI')->orWhere('jobs', 'Loops')->get();

Let me know where you land

pdphilip commented 7 months ago

Hi @davimug - this bug has been fixed in the new v3 version.

Can see in docs

To update for Laravel 10 composer require pdphilip/elasticsearch:~3.10

davimug commented 6 months ago

Hi sorry for the late reply @pdphilip, amazing work! Will take a look