How to add LIKE query in Elasticsearch?

By Hardik Savani | January 26, 2016 | | 35916 Viewer | Category : Elasticsearch


I want to use LIKE query as work on sql, i mean If using a SQL or Mysql 'Like' query to query data it will return data even if its only partially matched. if i search just 't' then it will return all the records match 't'. so you can add LIKE statement by using 'query_string'.

you can easily implement LIKE statement by using 'query_string', in following example you can see how to impletemt:

$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

}

}

}

}

');

Try this.....



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.