# How to perform a Prefix query with Elastica

**URL:** <https://discuss.elastic.co/t/how-to-perform-a-prefix-query-with-elastica/19937>\
**Category:** Elasticsearch\
**Created:** [September 24, 2014, 10:23am UTC](https://discuss.elastic.co/t/how-to-perform-a-prefix-query-with-elastica/19937 "2014-09-24T10:23:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Garcia](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@Javier\_Garcia](https://discuss.elastic.co/u/Javier_Garcia)\
**Post date:** [September 24, 2014, 10:23am UTC](https://discuss.elastic.co/t/how-to-perform-a-prefix-query-with-elastica/19937/1 "2014-09-24T10:23:00Z")

</div>

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.

--  
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/d04ca78b-a739-40a3-8758-033ad47450c4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d04ca78b-a739-40a3-8758-033ad47450c4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Javier\_Garcia](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@Javier\_Garcia](https://discuss.elastic.co/u/Javier_Garcia)\
**Post date:** [September 25, 2014, 8:50am UTC](https://discuss.elastic.co/t/how-to-perform-a-prefix-query-with-elastica/19937/2 "2014-09-25T08:50:00Z")

</div>

Any help?

El miércoles, 24 de septiembre de 2014 12:23:00 UTC+2, Javier Garcia  
escribió:

> 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.

--  
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/bff3bdd1-7f3c-4b75-bc54-92483d42e650%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bff3bdd1-7f3c-4b75-bc54-92483d42e650%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jorge\_Luis\_Betancour](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@Jorge\_Luis\_Betancour](https://discuss.elastic.co/u/Jorge_Luis_Betancour)\
**Post date:** [September 28, 2014, 5:11am UTC](https://discuss.elastic.co/t/how-to-perform-a-prefix-query-with-elastica/19937/3 "2014-09-28T05:11:14Z")

</div>

Can tu print the query that your code translates to? Basically your prefix query could be accomplished using wildcards?

On Sep 25, 2014, at 4:50 AM, Javier Garcia [tirengarfio@gmail.com](mailto:tirengarfio@gmail.com) wrote:

> Any help?
> 
> El miércoles, 24 de septiembre de 2014 12:23:00 UTC+2, Javier Garcia escribió:
> 
> 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.
> 
> --  
> 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/bff3bdd1-7f3c-4b75-bc54-92483d42e650%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bff3bdd1-7f3c-4b75-bc54-92483d42e650%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

Concurso "Mi selfie por los 5". Detalles en [http://justiciaparaloscinco.wordpress.com](http://justiciaparaloscinco.wordpress.com)

--  
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/E0F3A97D-4DF3-4668-A9BC-BCD5A02442E5%40uci.cu](https://groups.google.com/d/msgid/elasticsearch/E0F3A97D-4DF3-4668-A9BC-BCD5A02442E5%40uci.cu).  
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:59am UTC](https://discuss.elastic.co/t/how-to-perform-a-prefix-query-with-elastica/19937/4 "2017-07-06T00:59:35Z")

</div>


