# Little problem with queries

**URL:** <https://discuss.elastic.co/t/little-problem-with-queries/21573>\
**Category:** Elasticsearch\
**Created:** [January 11, 2015, 3:42pm UTC](https://discuss.elastic.co/t/little-problem-with-queries/21573 "2015-01-11T15:42:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan\_Kruse\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stefan_kruse_2/32/12005_2.png) [@Stefan\_Kruse\_2](https://discuss.elastic.co/u/Stefan_Kruse_2)\
**Post date:** [January 11, 2015, 3:42pm UTC](https://discuss.elastic.co/t/little-problem-with-queries/21573/1 "2015-01-11T15:42:56Z")

</div>

Hi, i need a fuzzy or "like" search for the elasticsearch php client.

I have a field called name, and there are values like testone, testtwo,  
testthree.  
Now i need a search for a searchstring like test. There should come all  
values.

How do i make this?

I try:

$params = array();  
$params['index'] = 'myIndex';  
$params['type'] = 'myType';  
$params['body']['query']['match or fuzzy']['name'] = 'test';

$ret = $client-\>search($params);

Does anybody has an idea or hint for me?

Thanks  
Stefan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/291ac520-d9ef-49a9-98eb-2ed82378afca%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/291ac520-d9ef-49a9-98eb-2ed82378afca%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Hannes\_Korte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hannes_korte/32/909_2.png) [@Hannes\_Korte](https://discuss.elastic.co/u/Hannes_Korte)\
**Post date:** [January 11, 2015, 6:41pm UTC](https://discuss.elastic.co/t/little-problem-with-queries/21573/2 "2015-01-11T18:41:11Z")

</div>

Hi Stefan,

maybe this helps:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

You can query for term prefixes and complex patterns:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

But use it with care as it is rather slow. To speed it up you might want  
to use n-grams at index time:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Best regards,  
Hannes

On 11.01.2015 16:42, Stefan Kruse wrote:

> Hi, i need a fuzzy or "like" search for the elasticsearch php client.
> 
> I have a field called name, and there are values like testone, testtwo,  
> testthree.  
> Now i need a search for a searchstring like test. There should come all  
> values.
> 
> How do i make this?
> 
> I try:
> 
> $params = array();  
> $params['index'] = 'myIndex';  
> $params['type'] = 'myType';  
> $params['body']['query']['match or fuzzy']['name'] = 'test';
> 
> $ret = $client-\>search($params);
> 
> Does anybody has an idea or hint for me?
> 
> Thanks  
> Stefan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/54B2C3C7.3090603%40hkorte.com](https://groups.google.com/d/msgid/elasticsearch/54B2C3C7.3090603%40hkorte.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Stefan\_Kruse\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stefan_kruse_2/32/12005_2.png) [@Stefan\_Kruse\_2](https://discuss.elastic.co/u/Stefan_Kruse_2)\
**Post date:** [January 12, 2015, 12:13pm UTC](https://discuss.elastic.co/t/little-problem-with-queries/21573/3 "2015-01-12T12:13:45Z")

</div>

Hi Hannes,  
thanks for replay. But i dont get it to work.  
I made some chages. In my database i have the value"Scherzartikel für  
Feste" and when i search for "Feste" it would be found. But if i try "Feste  
Scherz" then i would not be found. How to solve this? Is there a way?

Thanks Stefan

Am Sonntag, 11. Januar 2015 16:42:57 UTC+1 schrieb Stefan Kruse:

> Hi, i need a fuzzy or "like" search for the elasticsearch php client.
> 
> I have a field called name, and there are values like testone, testtwo,  
> testthree.  
> Now i need a search for a searchstring like test. There should come all  
> values.
> 
> How do i make this?
> 
> I try:
> 
> $params = array();  
> $params['index'] = 'myIndex';  
> $params['type'] = 'myType';  
> $params['body']['query']['match or fuzzy']['name'] = 'test';
> 
> $ret = $client-\>search($params);
> 
> Does anybody has an idea or hint for me?
> 
> Thanks  
> Stefan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/80ade4ea-2bfd-4c3d-97fe-f711fb7ba200%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/80ade4ea-2bfd-4c3d-97fe-f711fb7ba200%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Hannes\_Korte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hannes_korte/32/909_2.png) [@Hannes\_Korte](https://discuss.elastic.co/u/Hannes_Korte)\
**Post date:** [January 14, 2015, 4:59pm UTC](https://discuss.elastic.co/t/little-problem-with-queries/21573/4 "2015-01-14T16:59:36Z")

</div>

Hi Stefan,

without any details about your mapping and the way you build the query  
it is really hard to say what exactly is wrong in your setup.

If you use the default analyzer and simply index a few documents:

PUT testindex/test/1  
{ "name": "Scherzartikel für Feste" }  
PUT testindex/test/2  
{ "name": "Furzkissen" }  
PUT testindex/test/3  
{ "name": "Scherzbrille" }  
PUT testindex/test/4  
{ "name": "Feste Schuhe" }

Then you can query the documents in various ways, for example:

1. using the query\_string query:

2. using a prefix query:

3. or using a more complex query:

It should be straightforward to write this as PHP code. If you want to  
find any word parts instead of only prefixes you could use a wildcard  
query instead:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

But keep in mind that it is much faster if you prepare the data at index  
time using ngram filters:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

By the way, in case you don't know how to test the examples above, I  
recommend using Marvel on your development machine:

[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/overview/marvel/)

Best regards,  
Hannes

On 12.01.2015 13:13, Stefan Kruse wrote:

> Hi Hannes,  
> thanks for replay. But i dont get it to work.  
> I made some chages. In my database i have the value"Scherzartikel für  
> Feste" and when i search for "Feste" it would be found. But if i try "Feste  
> Scherz" then i would not be found. How to solve this? Is there a way?
> 
> Thanks Stefan
> 
> Am Sonntag, 11. Januar 2015 16:42:57 UTC+1 schrieb Stefan Kruse:
> 
> > Hi, i need a fuzzy or "like" search for the elasticsearch php client.
> > 
> > I have a field called name, and there are values like testone, testtwo,  
> > testthree.  
> > Now i need a search for a searchstring like test. There should come all  
> > values.
> > 
> > How do i make this?
> > 
> > I try:
> > 
> > $params = array();  
> > $params['index'] = 'myIndex';  
> > $params['type'] = 'myType';  
> > $params['body']['query']['match or fuzzy']['name'] = 'test';
> > 
> > $ret = $client-\>search($params);
> > 
> > Does anybody has an idea or hint for me?
> > 
> > Thanks  
> > Stefan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/54B6A078.2050808%40hkorte.com](https://groups.google.com/d/msgid/elasticsearch/54B6A078.2050808%40hkorte.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:38am UTC](https://discuss.elastic.co/t/little-problem-with-queries/21573/5 "2017-07-06T00:38:56Z")

</div>


