Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

farshadf's avatar

scout + elastic search query always return null

i have indexed my data and can see them by the link below :

http://localhost:9200/accommodation_write/_search?pretty=true&q=*:*

when i hit the above link i can see all my data active and indexed on my elastic search but when i try to search them like below :

  public function search(Request $request){
        $orders = Accommodation::search('*')
            ->where('id', 1)
            ->get();
        return $orders;
    }

i always get empty object no matter what query i change for the conditions . any help or advice you can give me ??

0 likes
3 replies
jlrdw's avatar

Elasticsearch is a restful search. If your top example works, but bottom does not, you probably need to build a rest search from the request.

Like in a regular search you post a search form, but after initial search it's a get request with pagination. Something like:

    public function processAdmin()
    {
        if (!ChkAuth::chkRole('admin')) {  // ignore line custom auth
            return redirect('indexbl');
        }
        if (Request::has('submit')) {
            $dogsearch = !empty(Request::input('psch')) ? Request::input('psch') : '';
            return redirect('dog/indexadmin/' . $dogsearch);
        }
    }

Now I hit my route dog/indexadmin and can have the parameter $dogsearch.

Anyway this part:

'dog/indexadmin/' . $dogsearch

Is built since it's going to be a paginated get request after the initial post search.

And sorry

It's very hard to explain all this in just a forum post. But search for other Elasticsearch example as well, maybe S.O.

Bottom line, build the rest search line needed from initial request data.

I'm sure there's other ways as well.

Edit: seems like the examples from Scout should be working for example: https://laravel.com/docs/5.8/scout#where-clauses

Make sure you are using and set up Scout exactly like the documentation says.

farshadf's avatar

Thanks @jlrdw but i am using it in Api and i configed scout exacly as documentation said

hondnl's avatar

What does your Accomodation model looks like?

Please or to participate in this conversation.