8

I am building a REST api using Laravel for a mobile app. And now I need a search engine.

First off, I have never used any search engine. So I am looking for one thats simple to work with but still good at fulltext searching and filtering "where"

The table I want to perform searches on has 1 column (varchar45) that needs to be search by fulltext search, and then there is 5 columns (int) thats used to filter using a "where" statement.- Using the mysql approach. I also perform a inner join on that table in order to print out some other stuff when generating the result.

So I looked at sphinx and Elasticsearch, and decided to go with ES.

I have watched the ES intro form Laracon: https://www.youtube.com/watch?v=waTWeJeFp4A

and I also took a look at this package: https://github.com/freekmurze/searchindex

That left me with a few questions:

1) Do I drop my mysql DB and just store ALL my data in ES?

2) If 1-yes, can I still use my mysql DB and just use ES to store indexes? - Since I only have to perform a search on one table (search a total of 5 rows).

3 If 2-yes, Do I still keep my current indexes in my mysql table? Eg, fulltext index on title column, FK on another column and index on 3 others.

4 Since this is the first time I ever use a search engine, is there any other tutorial/book/snippet out there on how to use ES with Laravel?

Thanks in advance

user2722667
  • 8,195
  • 14
  • 52
  • 100
  • Personally I still store all info on MySQL, I just store big tables at elasticsearch and use it for searching only in big datas, where full index is slow, or I need to get ordered results. Also keep in mind that there would be good to store your data in some kind of database. Storing all info on ES isn't good, because as far as I know there isn't fast way to export ES data and just import it on another server. And if you choose to still use MySQL with ES, keep just indexes you need (for example if you are not searching by fulltext, remove it). – sanis Feb 04 '15 at 10:59

1 Answers1

10

I was solving the same issues recently. My opinions:

1. no. definitely keep your DB for storing data. ES wasn't built to replace your database. it is (mostly) search engine.

4. you can find nice tutorial here: http://www.fullstackstanley.com/read/simple-search-with-laravel-and-elasticsearch (as a starting point).
I suggest you to read also http://www.elasticsearch.org/guide/en/elasticsearch/guide/ (to understand ES better)

Igor Rjabinin
  • 761
  • 6
  • 7
  • Thanks Igor. Then I just have a copy of that table in ES. I found that tutorial before and its great. I even linked it in the laracasts forum since I seen alot of people asking about ES. Right now I am facing a new problem in case you have the time to look into it. First off - I cant map MySql timestamps into ES, I tried long/timestamp/integers none works. You can see more at https://stackoverflow.com/questions/28433724/cant-map-mysql-timestamp-into-elasticsearch – user2722667 Feb 10 '15 at 15:08
  • Second, I have a problem with ES sort function. My query looks like $sort = ['sort' => ['id' => 'desc']]; $posts = Post::searchByQuery($query,null,null,null,null,$sort); – user2722667 Feb 10 '15 at 15:09