Ashwani
Ashwani

Reputation: 732

how to do full text search in elasticsearch

I have very big data in on table (more then 4lc rows). Right now i am using mysql full text search but its very slow.

I google and found many blog which suggest to use elastic search for searching. We are testing if elastic search will help in fast search.

but we are getting opposite result(mysql better search), but i doubt if i have used elastic search in correct way. Elastic search query i used is:-

{
 "query" : {
     "bool" : {
        "must" : {
           "query_string" : {
               "query" : "goog*",
               "default_field" : "search"
           }
        }
     }
 },
 "size" : 1000
}

For same search in mysql we used

SELECT SQL_NO_CACHE * FROM table1 WHERE (MATCH (search) AGAINST (' +goog*' IN BOOLEAN MODE))

I get time diff:- elastic time = 0.34929585456848

mysql time = 0.02162504196167

Any suggestion where i am wrong I will very much appreciate

Upvotes: 5

Views: 19443

Answers (1)

Anirudh Modi
Anirudh Modi

Reputation: 1829

The first reason for query being a little slow is because you are using wildcard while searching...

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html

https://www.elastic.co/guide/en/elasticsearch/guide/current/search-in-depth.html

I will suggest that you look into elastic search mapping, analyzers to get the benefit of elastic search you will need to index your data correctly, and apply the right set of queries...

Filename search with ElasticSearch

this is a little advanced example to just show how to achieve search in between words of a file..

How your data is indexed can also effect the search query timing, and the query itself which you will be using..

You can register here and look into a short video on the different type of queries provided by elastic guys only..

https://www.elastic.co/webinars/elasticsearch-query-dsl

You can't decide which one is better without proper analysis..that too in elastic-search where indexing of the data effects a lot..

Upvotes: 7

Related Questions