How to add LIKE query in Elasticsearch?

By Hardik Savani November 5, 2023 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.....

Tags :

We are Recommending you

Shares