Laravel Scout with Elastic search not working

5k views Asked by At

I tried

  • Using Elastic search with Laravel scout with packages

    "laravel/scout": "^1.0",
    "tamayo/laravel-scout-elastic": "^1.0"
    
  • Ran Elasticsearch server in localhost:9200 and created index and gave necessary config's,

  • added searchable trait's to the model,

  • and imported data to index like

    php artisan scout:import "App\story"
    Imported [App\story] models up to ID: 4
    All [App\story] records have been imported.
    

But when I do a search it returns an empty array

 story::search("the")->get()
 => Illuminate\Database\Eloquent\Collection {#754
      all: [],
 }

when I do curl also it shows like,

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

      {
        "took": 1,
        "timed_out": false,
        "_shards": {
          "total": 5,
          "successful": 5,
          "failed": 0
        },
        "hits": {
          "total": 0,
          "max_score": null,
          "hits": [
            
          ]
        }
      }

When I adding the record without index in ES the model throws an error like index not found. But after adding data and all, it seems empty. Did I miss anything?

The whole same works fine with algolia.

3

There are 3 answers

0
Mihai On

In case you are using elastic search, check the error log - I had:

sudo su 

tail -f /var/log/elasticsearch/elasticsearch.log


high disk watermark [90%] exceeded on [minbqqKpRV-umA0DPxkuww][mihai-MS-7A72][/var/lib/elasticsearch/nodes/0] free: 28.9gb[6.3%], shards will be relocated away from this node; currently relocating away shards totalling [0] bytes; the node is expected to continue to exceed the high disk watermark when these relocations are complete

IF that`s the case,disable the disk check,at least for testing

curl -XPUT -H "Content-Type: application/json" \
   http://localhost:9200/_all/_settings \
     -d '{"index.blocks.read_only_allow_delete": false}'

Or make those changes permanent in elasticsearch.yml and restart the service.

0
gabi doroftei On

Set QUEUE=sync or you could turn off queue on config/scout.php.

Had the same issue: https://github.com/ErickTamayo/laravel-scout-elastic/issues/43

0
tacheshun On

I had the same issue. Delete your index in Elasticsearch and run:

php artisan scout:import App\\story

Let scout create it.