Little problem with queries

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/291ac520-d9ef-49a9-98eb-2ed82378afca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi Stefan,

maybe this helps:

You can query for term prefixes and complex patterns:

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

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/54B2C3C7.3090603%40hkorte.com.
For more options, visit https://groups.google.com/d/optout.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/80ade4ea-2bfd-4c3d-97fe-f711fb7ba200%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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:

    POST testindex/_search
    {
    "query": {
    "query_string": {
    "default_field": "name",
    "query": "feste scherz*"
    }
    }
    }

    This returns:
    "Scherzartikel für Feste"
    "Feste Schuhe"
    "Scherzbrille"

  2. using a prefix query:

    POST testindex/_search
    {
    "query": {
    "prefix": {
    "name": {
    "value": "scherz"
    }
    }
    }
    }

    This returns:
    "Scherzartikel für Feste"
    "Scherzbrille"

  3. or using a more complex query:

    POST testindex/_search
    {
    "query": {
    "bool": {
    "must": [
    {
    "prefix": {
    "name": {
    "value": "scherz"
    }
    }
    },
    {
    "prefix": {
    "name": {
    "value": "fest"
    }
    }
    }
    ]
    }
    }
    }

    This returns:
    "Scherzartikel für Feste"

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:

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

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

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/54B6A078.2050808%40hkorte.com.
For more options, visit https://groups.google.com/d/optout.