0

I've this in my index: "ground beef".

This is my config:

settings:
    index:
        analysis:
            analyzer:
                index_analyzer:
                    tokenizer: whitespace
                    filter: [lowercase, asciifolding, word_delimiter, snowball]

This is how I search:

    $query      = new \Elastica\Query;
    $boolQuery  = new \Elastica\Query\Bool;
    $matchQuery = new \Elastica\Query\Match;
    $filter     = new \Elastica\Filter\Term(array('visible' => 'true'));
    $termQuery  = new \Elastica\Query\Term;

    $termQuery->setTerm('locale_id', $localeId);
    $matchQuery->setFieldQuery('name', $name);
    $matchQuery->setFieldParam('name', 'type', 'phrase_prefix');

    $boolQuery->addMust($termQuery);
    $boolQuery->addMust($matchQuery);

    $query->setQuery($boolQuery);

    $this->finder->findPaginated($query, array('from' => $from, 'size' => $size));

Everything works like charm.

If I search for "ground beef", I'll get my entities. If I search for "beef ground", nothing will be returned.

Has anyone an idea?

1 Answers1

0

You are using a phrase_prefix search:

$matchQuery->setFieldParam('name', 'type', 'phrase_prefix');

This is going to perform a match_phrase_prefix which is looking for phrases:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html towards bottom of page.

I think you want a boolean search (either AND or OR, defaults to OR) to look for either term. That or use a phrase search but set slop to at least 2 (but make certain you are using a version of ES that does not have this slop bug: https://github.com/elasticsearch/elasticsearch/issues/5437)

John Petrone
  • 26,943
  • 6
  • 63
  • 68