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:


http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_wildcard_and_regexp_queries.html

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


http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/ngrams-compound-words.html

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

  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 [email protected].
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.

Reply via email to