2

I'm attempting to create an autocomplete search using Elastica and Elastic Search (more specifically, FOSElasticaBundle for Symfony2).

I've created a simple index, populated it with objects.

A basic search works, ie:

$finder = $this->container->get('fos_elastica.finder.search.person');
$results = $finder->find('Mike');

I'm having some trouble getting my prefix query to work though and I can't find any examples online. Here's what I'm trying:

$finder = $this->container->get('fos_elastica.finder.search.person');
$prefixQuery = new \Elastica\Query\Prefix();
$prefixQuery->setPrefix('nameFirst','Mik');
$results = $finder->find($prefixQuery);

It doesn't kick any errors, but just doesn't return any results.

The field should be set properly...my configuration looks like this:

...
            types:
                person:
                    mappings:
                        nameFirst: { boost: 10 }
                        nameLast: { boost: 10 }
                        nameMiddle: { boost: 3 }
...

Can anyone tell what I'm doing wrong?

Also: Bonus Question: Is the best way to search the prefix on both the nameFirst AND nameLast fields going to be using a NestedQuery, or using addParam() to add both the nameFirst and nameLast?

Thanks a bunch-

Pez
  • 1,251
  • 16
  • 32

0 Answers0