Home Elasticsearch How to add LIKE query in Elasticsearch?

How to add LIKE query in Elasticsearch?

by Shahriar Sagor

Now in this blog i will show you how to add LIKE query in Elasticsearch. If we want to use LIKE query as work on sql, i mean that If we are using a SQL or Mysql ‘Like’ query to get data it will be return data even if its only partially matched. When we are search just ‘t’ then it will return the all records match with ‘t’. So here we can add LIKE statement by using ‘query_string’.

Now we can easily implement LIKE statement by using ‘query_string’, in following example so we can see how to implement:

$search = 't';
$sql = json_decode(' {
            "type": "main",
            "query_cache": true,
            "body": {
                "size": 500,
                "query": {
                    "query_string": {
                        "default_field": "name",
                        "query": "' . $search . ' OR *' . $search . '*",
                        "use_dis_max": true,
                        "fuzzy_max_expansions": 50,
                        "fuzziness": 1
                    }
                }
            }
        }
        ');

Read Also : How to get element with CSS class name and id using jquery ?

Thanks for read this, I hope it will you. You can also follow us on Facebook.

close

You may also like